1
- namespace EasyCaching . CSRedis
1
+ namespace EasyCaching . CSRedis
2
2
{
3
3
using EasyCaching . Core ;
4
- using EasyCaching . Core . Internal ;
5
- using System . Collections . Generic ;
6
- using System . Threading . Tasks ;
7
-
4
+ using EasyCaching . Core . Internal ;
5
+ using System . Collections . Generic ;
6
+ using System . Threading . Tasks ;
7
+
8
8
public partial class DefaultCSRedisCachingProvider : IRedisCachingProvider
9
9
{
10
10
public long ZAdd < T > ( string cacheKey , Dictionary < T , double > cacheValues )
@@ -25,57 +25,73 @@ public long ZAdd<T>(string cacheKey, Dictionary<T, double> cacheValues)
25
25
26
26
public long ZCard ( string cacheKey )
27
27
{
28
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
29
-
30
- var len = _cache . ZCard ( cacheKey ) ;
28
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
29
+
30
+ var len = _cache . ZCard ( cacheKey ) ;
31
31
return len ;
32
32
}
33
33
34
34
public long ZCount ( string cacheKey , double min , double max )
35
35
{
36
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
37
-
38
- var len = _cache . ZCount ( cacheKey , ( decimal ) min , ( decimal ) max ) ;
36
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
37
+
38
+ var len = _cache . ZCount ( cacheKey , ( decimal ) min , ( decimal ) max ) ;
39
39
return len ;
40
40
}
41
41
public double ZIncrBy ( string cacheKey , string field , double val = 1 )
42
42
{
43
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
44
- ArgumentCheck . NotNullOrWhiteSpace ( field , nameof ( field ) ) ;
45
-
43
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
44
+ ArgumentCheck . NotNullOrWhiteSpace ( field , nameof ( field ) ) ;
45
+
46
46
var value = _cache . ZIncrBy ( cacheKey , field , ( decimal ) val ) ;
47
47
return ( double ) value ;
48
48
}
49
49
public long ZLexCount ( string cacheKey , string min , string max )
50
50
{
51
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
52
-
53
- var len = _cache . ZLexCount ( cacheKey , min , max ) ;
51
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
52
+
53
+ var len = _cache . ZLexCount ( cacheKey , min , max ) ;
54
54
return len ;
55
55
}
56
56
57
57
public List < T > ZRange < T > ( string cacheKey , long start , long stop )
58
58
{
59
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
60
-
61
- var list = new List < T > ( ) ;
62
-
63
- var bytes = _cache . ZRange < byte [ ] > ( cacheKey , start , stop ) ;
64
-
59
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
60
+
61
+ var list = new List < T > ( ) ;
62
+
63
+ var bytes = _cache . ZRange < byte [ ] > ( cacheKey , start , stop ) ;
64
+
65
+ foreach ( var item in bytes )
66
+ {
67
+ list . Add ( _serializer . Deserialize < T > ( item ) ) ;
68
+ }
69
+
70
+ return list ;
71
+ }
72
+
73
+ public List < T > ZRangeByScore < T > ( string cacheKey , double min , double max , long ? count = null , long offset = 0 )
74
+ {
75
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
76
+
77
+ var list = new List < T > ( ) ;
78
+
79
+ var bytes = _cache . ZRangeByScore < byte [ ] > ( cacheKey , ( decimal ) min , ( decimal ) max , count , offset ) ;
80
+
65
81
foreach ( var item in bytes )
66
82
{
67
83
list . Add ( _serializer . Deserialize < T > ( item ) ) ;
68
- }
69
-
84
+ }
85
+
70
86
return list ;
71
87
}
72
88
73
89
public long ? ZRank < T > ( string cacheKey , T cacheValue )
74
90
{
75
91
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
76
92
77
- var bytes = _serializer . Serialize ( cacheValue ) ;
78
-
93
+ var bytes = _serializer . Serialize ( cacheValue ) ;
94
+
79
95
var index = _cache . ZRank ( cacheKey , bytes ) ;
80
96
81
97
return index ;
@@ -86,27 +102,27 @@ public long ZRem<T>(string cacheKey, IList<T> cacheValues)
86
102
{
87
103
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
88
104
89
- var bytes = new List < byte [ ] > ( ) ;
90
-
105
+ var bytes = new List < byte [ ] > ( ) ;
106
+
91
107
foreach ( var item in cacheValues )
92
108
{
93
109
bytes . Add ( _serializer . Serialize ( item ) ) ;
94
- }
95
-
110
+ }
111
+
96
112
var len = _cache . ZRem < byte [ ] > ( cacheKey , bytes . ToArray ( ) ) ;
97
113
98
114
return len ;
99
- }
100
-
101
- public double ? ZScore < T > ( string cacheKey , T cacheValue )
102
- {
103
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
104
-
105
- var bytes = _serializer . Serialize ( cacheValue ) ;
106
-
107
- var score = _cache . ZScore ( cacheKey , bytes ) ;
108
-
109
- return ( double ? ) score ;
115
+ }
116
+
117
+ public double ? ZScore < T > ( string cacheKey , T cacheValue )
118
+ {
119
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
120
+
121
+ var bytes = _serializer . Serialize ( cacheValue ) ;
122
+
123
+ var score = _cache . ZScore ( cacheKey , bytes ) ;
124
+
125
+ return ( double ? ) score ;
110
126
}
111
127
112
128
public async Task < long > ZAddAsync < T > ( string cacheKey , Dictionary < T , double > cacheValues )
@@ -128,59 +144,75 @@ public async Task<long> ZAddAsync<T>(string cacheKey, Dictionary<T, double> cach
128
144
129
145
public async Task < long > ZCardAsync ( string cacheKey )
130
146
{
131
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
132
-
133
- var len = await _cache . ZCardAsync ( cacheKey ) ;
147
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
148
+
149
+ var len = await _cache . ZCardAsync ( cacheKey ) ;
134
150
return len ;
135
- }
136
-
151
+ }
152
+
137
153
public async Task < long > ZCountAsync ( string cacheKey , double min , double max )
138
154
{
139
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
140
-
141
- var len = await _cache . ZCountAsync ( cacheKey , ( decimal ) min , ( decimal ) max ) ;
155
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
156
+
157
+ var len = await _cache . ZCountAsync ( cacheKey , ( decimal ) min , ( decimal ) max ) ;
142
158
return len ;
143
159
}
144
160
145
161
public async Task < double > ZIncrByAsync ( string cacheKey , string field , double val = 1 )
146
162
{
147
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
148
- ArgumentCheck . NotNullOrWhiteSpace ( field , nameof ( field ) ) ;
149
-
163
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
164
+ ArgumentCheck . NotNullOrWhiteSpace ( field , nameof ( field ) ) ;
165
+
150
166
var value = await _cache . ZIncrByAsync ( cacheKey , field , ( decimal ) val ) ;
151
167
return ( double ) value ;
152
- }
153
-
168
+ }
169
+
154
170
public async Task < long > ZLexCountAsync ( string cacheKey , string min , string max )
155
171
{
156
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
157
-
158
- var len = await _cache . ZLexCountAsync ( cacheKey , min , max ) ;
172
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
173
+
174
+ var len = await _cache . ZLexCountAsync ( cacheKey , min , max ) ;
159
175
return len ;
160
176
}
161
177
162
178
public async Task < List < T > > ZRangeAsync < T > ( string cacheKey , long start , long stop )
163
179
{
164
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
165
-
166
- var list = new List < T > ( ) ;
167
-
168
- var bytes = await _cache . ZRangeAsync < byte [ ] > ( cacheKey , start , stop ) ;
169
-
180
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
181
+
182
+ var list = new List < T > ( ) ;
183
+
184
+ var bytes = await _cache . ZRangeAsync < byte [ ] > ( cacheKey , start , stop ) ;
185
+
170
186
foreach ( var item in bytes )
171
187
{
172
188
list . Add ( _serializer . Deserialize < T > ( item ) ) ;
173
- }
174
-
189
+ }
190
+
191
+ return list ;
192
+ }
193
+
194
+ public async Task < List < T > > ZRangeByScoreAsync < T > ( string cacheKey , double min , double max , long ? count = null , long offset = 0 )
195
+ {
196
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
197
+
198
+ var list = new List < T > ( ) ;
199
+
200
+ var bytes = await _cache . ZRangeByScoreAsync < byte [ ] > ( cacheKey , ( decimal ) min , ( decimal ) max , count , offset ) ;
201
+
202
+ foreach ( var item in bytes )
203
+ {
204
+ list . Add ( _serializer . Deserialize < T > ( item ) ) ;
205
+ }
206
+
175
207
return list ;
176
208
}
177
209
178
210
public async Task < long ? > ZRankAsync < T > ( string cacheKey , T cacheValue )
179
211
{
180
212
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
181
213
182
- var bytes = _serializer . Serialize ( cacheValue ) ;
183
-
214
+ var bytes = _serializer . Serialize ( cacheValue ) ;
215
+
184
216
var index = await _cache . ZRankAsync ( cacheKey , bytes ) ;
185
217
186
218
return index ;
@@ -190,28 +222,28 @@ public async Task<long> ZRemAsync<T>(string cacheKey, IList<T> cacheValues)
190
222
{
191
223
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
192
224
193
- var bytes = new List < byte [ ] > ( ) ;
194
-
225
+ var bytes = new List < byte [ ] > ( ) ;
226
+
195
227
foreach ( var item in cacheValues )
196
228
{
197
229
bytes . Add ( _serializer . Serialize ( item ) ) ;
198
- }
199
-
230
+ }
231
+
200
232
var len = await _cache . ZRemAsync < byte [ ] > ( cacheKey , bytes . ToArray ( ) ) ;
201
233
202
234
return len ;
203
- }
204
-
205
- public async Task < double ? > ZScoreAsync < T > ( string cacheKey , T cacheValue )
206
- {
207
- ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
208
-
209
- var bytes = _serializer . Serialize ( cacheValue ) ;
210
-
211
- var score = await _cache . ZScoreAsync ( cacheKey , bytes ) ;
212
-
213
- return ( double ? ) score ;
214
- }
215
-
216
- }
217
- }
235
+ }
236
+
237
+ public async Task < double ? > ZScoreAsync < T > ( string cacheKey , T cacheValue )
238
+ {
239
+ ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
240
+
241
+ var bytes = _serializer . Serialize ( cacheValue ) ;
242
+
243
+ var score = await _cache . ZScoreAsync ( cacheKey , bytes ) ;
244
+
245
+ return ( double ? ) score ;
246
+ }
247
+
248
+ }
249
+ }
0 commit comments