平安校园
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

199 satır
4.3 KiB

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