RedisListHelperAsync.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using OASystem.RedisRepository.CommonHelper;
  2. using StackExchange.Redis;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OASystem.RedisRepository.RedisAsyncHelper
  9. {
  10. /// <summary>
  11. /// Redis异步操作类 List部分类
  12. /// </summary>
  13. internal partial class RedisHelper //: IRedisHelper
  14. {
  15. // _client.ListRightPopLeftPushAsync();
  16. // _client.ListTrimAsync();
  17. #region List 写操作
  18. public async Task<long> ListInsertAfterAsync<T>(string key, string pivot, T value)
  19. {
  20. return await _client.ListInsertAfterAsync(key, pivot, SerializeHelper.Serialize(value));
  21. }
  22. public async Task<long> ListInsertBeforeAsync<T>(string key, string pivot, T value)
  23. {
  24. return await _client.ListInsertBeforeAsync(key, pivot, SerializeHelper.Serialize(value));
  25. }
  26. public async Task<T> ListLeftPopAsync<T>(string key)
  27. {
  28. return SerializeHelper.Deserialize<T>(await _client.ListLeftPopAsync(key));
  29. }
  30. public async Task<long> ListLeftPushAsync<T>(string key, T value)
  31. {
  32. return await _client.ListLeftPushAsync(key, SerializeHelper.Serialize(value));
  33. }
  34. public async Task<long> ListLeftMultiPushAsync<T>(string key, List<T> values)
  35. {
  36. return await _client.ListLeftPushAsync(key, SerializeHelper.Serialize(RedisInnerTypeHelper.GenericListToRedisValues(values)));
  37. }
  38. public async Task<long> ListRemoveAsync<T>(string key, T value, long count = 0L)
  39. {
  40. return await _client.ListRemoveAsync(key, SerializeHelper.Serialize(value), count);
  41. }
  42. public async Task<T> ListRightPopAsync<T>(string key)
  43. {
  44. return SerializeHelper.Deserialize<T>(await _client.ListRightPopAsync(key));
  45. }
  46. public async Task<long> ListRightPushAsync<T>(string key, T value)
  47. {
  48. return await _client.ListRightPushAsync(key, SerializeHelper.Serialize(value));
  49. }
  50. public async Task<long> ListRightMultiPushAsync<T>(string key, List<T> values)
  51. {
  52. return
  53. await
  54. _client.ListRightPushAsync(key,
  55. SerializeHelper.Serialize(RedisInnerTypeHelper.GenericListToRedisValues(values)));
  56. }
  57. public async Task ListSetByIndexAsync<T>(string key, int index, T value)
  58. {
  59. await _client.ListSetByIndexAsync(key, index, SerializeHelper.Serialize(value));
  60. }
  61. public async Task ListTrimAsync(string key, long start, long stop)
  62. {
  63. await _client.ListTrimAsync(key, start, stop);
  64. }
  65. #endregion
  66. #region List 读操作
  67. public async Task<T> ListGetByIndexAsync<T>(string key, long index)
  68. {
  69. return SerializeHelper.Deserialize<T>(await _client.ListGetByIndexAsync(key, index, CommandFlags.PreferSlave));
  70. }
  71. public async Task<long> ListLengthAsync<T>(string key)
  72. {
  73. return await _client.ListLengthAsync(key, CommandFlags.PreferSlave);
  74. }
  75. public async Task<List<T>> ListRangeAsync<T>(string key, long start = 0L, long stop = -1L)
  76. {
  77. return RedisInnerTypeHelper.RedisValuesToGenericList<T>(await _client.ListRangeAsync(key, start, stop, CommandFlags.PreferSlave));
  78. }
  79. #endregion
  80. }
  81. }