14
14
using ServiceStack . Redis . Internal ;
15
15
using System ;
16
16
using System . Collections . Generic ;
17
+ using System . Runtime . CompilerServices ;
17
18
using System . Threading ;
18
19
using System . Threading . Tasks ;
19
20
@@ -55,182 +56,125 @@ ValueTask IAsyncDisposable.DisposeAsync()
55
56
56
57
async Task < T > ICacheClientAsync . GetAsync < T > ( string key , CancellationToken cancellationToken )
57
58
{
58
- var client = await GetReadOnlyCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
59
- await using ( client as IAsyncDisposable )
60
- {
61
- return await client . GetAsync < T > ( key ) . ConfigureAwait ( false ) ;
62
- }
59
+ await using var client = await GetReadOnlyCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
60
+ return await client . GetAsync < T > ( key ) . ConfigureAwait ( false ) ;
63
61
}
64
62
65
63
async Task < bool > ICacheClientAsync . SetAsync < T > ( string key , T value , CancellationToken cancellationToken )
66
64
{
67
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
68
- await using ( client as IAsyncDisposable )
69
- {
70
- return await client . SetAsync < T > ( key , value , cancellationToken ) . ConfigureAwait ( false ) ;
71
- }
65
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
66
+ return await client . SetAsync < T > ( key , value , cancellationToken ) . ConfigureAwait ( false ) ;
72
67
}
73
68
74
69
async Task < bool > ICacheClientAsync . SetAsync < T > ( string key , T value , DateTime expiresAt , CancellationToken cancellationToken )
75
70
{
76
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
77
- await using ( client as IAsyncDisposable )
78
- {
79
- return await client . SetAsync < T > ( key , value , expiresAt , cancellationToken ) . ConfigureAwait ( false ) ;
80
- }
71
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
72
+ return await client . SetAsync < T > ( key , value , expiresAt , cancellationToken ) . ConfigureAwait ( false ) ;
81
73
}
82
74
83
75
async Task < bool > ICacheClientAsync . SetAsync < T > ( string key , T value , TimeSpan expiresIn , CancellationToken cancellationToken )
84
76
{
85
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
86
- await using ( client as IAsyncDisposable )
87
- {
88
- return await client . SetAsync < T > ( key , value , expiresIn , cancellationToken ) . ConfigureAwait ( false ) ;
89
- }
77
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
78
+ return await client . SetAsync < T > ( key , value , expiresIn , cancellationToken ) . ConfigureAwait ( false ) ;
90
79
}
91
80
92
81
async Task ICacheClientAsync . FlushAllAsync ( CancellationToken cancellationToken )
93
82
{
94
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
95
- await using ( client as IAsyncDisposable )
96
- {
97
- await client . FlushAllAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
98
- }
83
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
84
+ await client . FlushAllAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
99
85
}
100
86
101
87
async Task < IDictionary < string , T > > ICacheClientAsync . GetAllAsync < T > ( IEnumerable < string > keys , CancellationToken cancellationToken )
102
88
{
103
- var client = await GetReadOnlyCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
104
- await using ( client as IAsyncDisposable )
105
- {
106
- return await client . GetAllAsync < T > ( keys , cancellationToken ) . ConfigureAwait ( false ) ;
107
- }
89
+ await using var client = await GetReadOnlyCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
90
+ return await client . GetAllAsync < T > ( keys , cancellationToken ) . ConfigureAwait ( false ) ;
108
91
}
109
92
110
93
async Task ICacheClientAsync . SetAllAsync < T > ( IDictionary < string , T > values , CancellationToken cancellationToken )
111
94
{
112
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
113
- await using ( client as IAsyncDisposable )
114
- {
115
- await client . SetAllAsync < T > ( values , cancellationToken ) . ConfigureAwait ( false ) ;
116
- }
95
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
96
+ await client . SetAllAsync < T > ( values , cancellationToken ) . ConfigureAwait ( false ) ;
117
97
}
118
98
119
99
async Task < bool > ICacheClientAsync . RemoveAsync ( string key , CancellationToken cancellationToken )
120
100
{
121
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
122
- await using ( client as IAsyncDisposable )
123
- {
124
- return await client . RemoveAsync ( key , cancellationToken ) . ConfigureAwait ( false ) ;
125
- }
101
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
102
+ return await client . RemoveAsync ( key , cancellationToken ) . ConfigureAwait ( false ) ;
126
103
}
127
104
128
105
async Task ICacheClientAsync . RemoveAllAsync ( IEnumerable < string > keys , CancellationToken cancellationToken )
129
106
{
130
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
131
- await using ( client as IAsyncDisposable )
132
- {
133
- await client . RemoveAllAsync ( keys , cancellationToken ) . ConfigureAwait ( false ) ;
134
- }
107
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
108
+ await client . RemoveAllAsync ( keys , cancellationToken ) . ConfigureAwait ( false ) ;
135
109
}
136
110
137
111
async Task < long > ICacheClientAsync . IncrementAsync ( string key , uint amount , CancellationToken cancellationToken )
138
112
{
139
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
140
- await using ( client as IAsyncDisposable )
141
- {
142
- return await client . IncrementAsync ( key , amount , cancellationToken ) . ConfigureAwait ( false ) ;
143
- }
113
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
114
+ return await client . IncrementAsync ( key , amount , cancellationToken ) . ConfigureAwait ( false ) ;
144
115
}
145
116
146
117
async Task < long > ICacheClientAsync . DecrementAsync ( string key , uint amount , CancellationToken cancellationToken )
147
118
{
148
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
149
- await using ( client as IAsyncDisposable )
150
- {
151
- return await client . DecrementAsync ( key , amount , cancellationToken ) . ConfigureAwait ( false ) ;
152
- }
119
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
120
+ return await client . DecrementAsync ( key , amount , cancellationToken ) . ConfigureAwait ( false ) ;
153
121
}
154
122
155
123
async Task < bool > ICacheClientAsync . AddAsync < T > ( string key , T value , CancellationToken cancellationToken )
156
124
{
157
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
158
- await using ( client as IAsyncDisposable )
159
- {
160
- return await client . AddAsync < T > ( key , value , cancellationToken ) . ConfigureAwait ( false ) ;
161
- }
125
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
126
+ return await client . AddAsync < T > ( key , value , cancellationToken ) . ConfigureAwait ( false ) ;
162
127
}
163
128
164
129
async Task < bool > ICacheClientAsync . ReplaceAsync < T > ( string key , T value , CancellationToken cancellationToken )
165
130
{
166
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
167
- await using ( client as IAsyncDisposable )
168
- {
169
- return await client . ReplaceAsync < T > ( key , value , cancellationToken ) . ConfigureAwait ( false ) ;
170
- }
131
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
132
+ return await client . ReplaceAsync < T > ( key , value , cancellationToken ) . ConfigureAwait ( false ) ;
171
133
}
172
134
173
135
async Task < bool > ICacheClientAsync . AddAsync < T > ( string key , T value , DateTime expiresAt , CancellationToken cancellationToken )
174
136
{
175
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
176
- await using ( client as IAsyncDisposable )
177
- {
178
- return await client . AddAsync < T > ( key , value , expiresAt , cancellationToken ) . ConfigureAwait ( false ) ;
179
- }
137
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
138
+ return await client . AddAsync < T > ( key , value , expiresAt , cancellationToken ) . ConfigureAwait ( false ) ;
180
139
}
181
140
182
141
async Task < bool > ICacheClientAsync . ReplaceAsync < T > ( string key , T value , DateTime expiresAt , CancellationToken cancellationToken )
183
142
{
184
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
185
- await using ( client as IAsyncDisposable )
186
- {
187
- return await client . ReplaceAsync < T > ( key , value , expiresAt , cancellationToken ) . ConfigureAwait ( false ) ;
188
- }
143
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
144
+ return await client . ReplaceAsync < T > ( key , value , expiresAt , cancellationToken ) . ConfigureAwait ( false ) ;
189
145
}
190
146
191
147
async Task < bool > ICacheClientAsync . AddAsync < T > ( string key , T value , TimeSpan expiresIn , CancellationToken cancellationToken )
192
148
{
193
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
194
- await using ( client as IAsyncDisposable )
195
- {
196
- return await client . AddAsync < T > ( key , value , expiresIn , cancellationToken ) . ConfigureAwait ( false ) ;
197
- }
149
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
150
+ return await client . AddAsync < T > ( key , value , expiresIn , cancellationToken ) . ConfigureAwait ( false ) ;
198
151
}
199
152
200
153
async Task < bool > ICacheClientAsync . ReplaceAsync < T > ( string key , T value , TimeSpan expiresIn , CancellationToken cancellationToken )
201
154
{
202
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
203
- await using ( client as IAsyncDisposable )
204
- {
205
- return await client . ReplaceAsync < T > ( key , value , expiresIn , cancellationToken ) . ConfigureAwait ( false ) ;
206
- }
155
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
156
+ return await client . ReplaceAsync < T > ( key , value , expiresIn , cancellationToken ) . ConfigureAwait ( false ) ;
207
157
}
208
158
209
159
async Task < TimeSpan ? > ICacheClientAsync . GetTimeToLiveAsync ( string key , CancellationToken cancellationToken )
210
160
{
211
- var client = await GetReadOnlyCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
212
- await using ( client as IAsyncDisposable )
213
- {
214
- return await client . GetTimeToLiveAsync ( key , cancellationToken ) . ConfigureAwait ( false ) ;
215
- }
161
+ await using var client = await GetReadOnlyCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
162
+ return await client . GetTimeToLiveAsync ( key , cancellationToken ) . ConfigureAwait ( false ) ;
216
163
}
217
164
218
- async Task < IEnumerable < string > > ICacheClientAsync . GetKeysByPatternAsync ( string pattern , CancellationToken cancellationToken )
165
+ async IAsyncEnumerable < string > ICacheClientAsync . GetKeysByPatternAsync ( string pattern , [ EnumeratorCancellation ] CancellationToken cancellationToken )
219
166
{
220
- var client = await GetReadOnlyCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
221
- await using ( client as IAsyncDisposable )
167
+ await using var client = await GetReadOnlyCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
168
+ await foreach ( var key in client . GetKeysByPatternAsync ( pattern , cancellationToken ) . ConfigureAwait ( false ) . WithCancellation ( cancellationToken ) )
222
169
{
223
- return await client . GetKeysByPatternAsync ( pattern , cancellationToken ) . ConfigureAwait ( false ) ;
170
+ yield return key ;
224
171
}
225
172
}
226
173
227
174
async Task ICacheClientAsync . RemoveExpiredEntriesAsync ( CancellationToken cancellationToken )
228
175
{
229
- var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
230
- await using ( client as IAsyncDisposable )
231
- {
232
- await client . RemoveExpiredEntriesAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
233
- }
176
+ await using var client = await GetCacheClientAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
177
+ await client . RemoveExpiredEntriesAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
234
178
}
235
179
}
236
180
}
0 commit comments