平安校园
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

RedisCacheService.cs 4.3 KiB

hace 4 meses
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. 
  2. //
  3. namespace SafeCampus.Cache;
  4. /// <summary>
  5. /// <inheritdoc cref="ISimpleCacheService"/>
  6. /// Redis缓存
  7. /// </summary>
  8. public partial class RedisCacheService : ISimpleCacheService
  9. {
  10. private readonly ISimpleRedis _simpleRedis;
  11. public RedisCacheService(ISimpleRedis simpleRedis)
  12. {
  13. _simpleRedis = simpleRedis;
  14. }
  15. #region 普通操作
  16. /// <inheritdoc/>
  17. public T Get<T>(string key)
  18. {
  19. return _simpleRedis.Get<T>(key);
  20. }
  21. /// <inheritdoc/>
  22. public int Remove(params string[] keys)
  23. {
  24. return _simpleRedis.GetFullRedis().Remove(keys);
  25. }
  26. /// <inheritdoc/>
  27. public bool Set<T>(string key, T value, int expire = -1)
  28. {
  29. return _simpleRedis.Set(key, value, expire);
  30. }
  31. /// <inheritdoc/>
  32. public bool Set<T>(string key, T value, TimeSpan expire)
  33. {
  34. return _simpleRedis.Set(key, value, expire);
  35. }
  36. /// <inheritdoc/>
  37. public bool SetExpire(string key, TimeSpan expire)
  38. {
  39. return _simpleRedis.GetFullRedis().SetExpire(key, expire);
  40. }
  41. /// <inheritdoc/>
  42. public TimeSpan GetExpire(string key)
  43. {
  44. return _simpleRedis.GetFullRedis().GetExpire(key);
  45. }
  46. /// <inheritdoc/>
  47. public bool ContainsKey(string key)
  48. {
  49. return _simpleRedis.ContainsKey(key);
  50. }
  51. /// <inheritdoc/>
  52. public void Clear()
  53. {
  54. _simpleRedis.Clear();
  55. }
  56. /// <inheritdoc/>
  57. public void DelByPattern(string pattern)
  58. {
  59. _simpleRedis.DelByPattern(pattern);
  60. }
  61. #endregion 普通操作
  62. #region 集合操作
  63. /// <inheritdoc/>
  64. public IDictionary<string, T> GetAll<T>(IEnumerable<string> keys)
  65. {
  66. return _simpleRedis.GetFullRedis().GetAll<T>(keys);
  67. }
  68. /// <inheritdoc/>
  69. public void SetAll<T>(IDictionary<string, T> values, int expire = -1)
  70. {
  71. _simpleRedis.GetFullRedis().SetAll(values, expire);
  72. }
  73. /// <inheritdoc/>
  74. public IDictionary<string, T> GetDictionary<T>(string key)
  75. {
  76. return _simpleRedis.GetFullRedis().GetDictionary<T>(key);
  77. }
  78. /// <inheritdoc/>
  79. public IProducerConsumer<T> GetQueue<T>(string key)
  80. {
  81. return _simpleRedis.GetFullRedis().GetQueue<T>(key);
  82. }
  83. /// <inheritdoc/>
  84. public IProducerConsumer<T> GetStack<T>(string key)
  85. {
  86. return _simpleRedis.GetFullRedis().GetStack<T>(key);
  87. }
  88. /// <inheritdoc/>
  89. public ICollection<T> GetSet<T>(string key)
  90. {
  91. return _simpleRedis.GetFullRedis().GetSet<T>(key);
  92. }
  93. #endregion 集合操作
  94. #region 高级操作
  95. /// <inheritdoc/>
  96. public bool Add<T>(string key, T value, int expire = -1)
  97. {
  98. return _simpleRedis.GetFullRedis().Add(key, value, expire);
  99. }
  100. /// <inheritdoc/>
  101. public IList<T> GetList<T>(string key)
  102. {
  103. return _simpleRedis.GetFullRedis().GetList<T>(key);
  104. }
  105. /// <inheritdoc/>
  106. public T Replace<T>(string key, T value)
  107. {
  108. return _simpleRedis.GetFullRedis().Replace(key, value);
  109. }
  110. /// <inheritdoc/>
  111. public bool TryGetValue<T>(string key, out T value)
  112. {
  113. return _simpleRedis.GetFullRedis().TryGetValue(key, out value);
  114. }
  115. /// <inheritdoc/>
  116. public long Decrement(string key, long value)
  117. {
  118. return _simpleRedis.GetFullRedis().Decrement(key, value);
  119. }
  120. /// <inheritdoc/>
  121. public double Decrement(string key, double value)
  122. {
  123. return _simpleRedis.GetFullRedis().Decrement(key, value);
  124. }
  125. /// <inheritdoc/>
  126. public long Increment(string key, long value)
  127. {
  128. return _simpleRedis.GetFullRedis().Increment(key, value);
  129. }
  130. /// <inheritdoc/>
  131. public double Increment(string key, double value)
  132. {
  133. return _simpleRedis.GetFullRedis().Increment(key, value);
  134. }
  135. #endregion 高级操作
  136. #region 事务
  137. /// <inheritdoc/>
  138. public int Commit()
  139. {
  140. return _simpleRedis.GetFullRedis().Commit();
  141. }
  142. /// <inheritdoc/>
  143. public IDisposable AcquireLock(string key, int msTimeout)
  144. {
  145. return _simpleRedis.GetFullRedis().AcquireLock(key, msTimeout);
  146. }
  147. /// <inheritdoc/>
  148. public IDisposable AcquireLock(string key, int msTimeout, int msExpire,
  149. bool throwOnFailure)
  150. {
  151. return _simpleRedis.GetFullRedis().AcquireLock(key, msTimeout, msExpire, throwOnFailure);
  152. }
  153. #endregion 事务
  154. }