@@ -160,6 +160,25 @@ public IGetOperationResult<T> PerformGet<T>(string key)
160
160
}
161
161
}
162
162
163
+ private bool CreateGetCommand ( string key , out IGetOperationResult result , out IMemcachedNode node , out IGetOperation command )
164
+ {
165
+ result = new DefaultGetOperationResultFactory ( ) . Create ( ) ;
166
+ var hashedKey = this . keyTransformer . Transform ( key ) ;
167
+
168
+ node = this . pool . Locate ( hashedKey ) ;
169
+ if ( node == null )
170
+ {
171
+ var errorMessage = $ "Unable to locate node with \" { key } \" key";
172
+ _logger . LogError ( errorMessage ) ;
173
+ result . Fail ( errorMessage ) ;
174
+ command = null ;
175
+ return false ;
176
+ }
177
+
178
+ command = this . pool . OperationFactory . Get ( hashedKey ) ;
179
+ return true ;
180
+ }
181
+
163
182
private bool CreateGetCommand < T > ( string key , out IGetOperationResult < T > result , out IMemcachedNode node , out IGetOperation command )
164
183
{
165
184
result = new DefaultGetOperationResultFactory < T > ( ) . Create ( ) ;
@@ -179,11 +198,28 @@ private bool CreateGetCommand<T>(string key, out IGetOperationResult<T> result,
179
198
return true ;
180
199
}
181
200
201
+ private IGetOperationResult BuildGetCommandResult ( IGetOperationResult result , IGetOperation command , IOperationResult commandResult )
202
+ {
203
+ if ( commandResult . Success )
204
+ {
205
+ result . Value = transcoder . Deserialize ( command . Result ) ;
206
+ result . Cas = command . CasValue ;
207
+ result . Pass ( ) ;
208
+ }
209
+ else
210
+ {
211
+ commandResult . Combine ( result ) ;
212
+ }
213
+
214
+ return result ;
215
+ }
216
+
182
217
private IGetOperationResult < T > BuildGetCommandResult < T > ( IGetOperationResult < T > result , IGetOperation command , IOperationResult commandResult )
183
218
{
184
219
if ( commandResult . Success )
185
220
{
186
221
result . Value = transcoder . Deserialize < T > ( command . Result ) ;
222
+ result . Cas = command . CasValue ;
187
223
result . Pass ( ) ;
188
224
}
189
225
else
@@ -194,6 +230,27 @@ private IGetOperationResult<T> BuildGetCommandResult<T>(IGetOperationResult<T> r
194
230
return result ;
195
231
}
196
232
233
+ public async Task < IGetOperationResult > GetAsync ( string key )
234
+ {
235
+ if ( ! CreateGetCommand ( key , out var result , out var node , out var command ) )
236
+ {
237
+ _logger . LogInformation ( $ "Failed to CreateGetCommand for '{ key } ' key") ;
238
+ return result ;
239
+ }
240
+
241
+ try
242
+ {
243
+ var commandResult = await node . ExecuteAsync ( command ) ;
244
+ return BuildGetCommandResult ( result , command , commandResult ) ;
245
+ }
246
+ catch ( Exception ex )
247
+ {
248
+ _logger . LogError ( 0 , ex , $ "{ nameof ( GetAsync ) } (\" { key } \" )") ;
249
+ result . Fail ( ex . Message , ex ) ;
250
+ return result ;
251
+ }
252
+ }
253
+
197
254
public async Task < IGetOperationResult < T > > GetAsync < T > ( string key )
198
255
{
199
256
if ( ! CreateGetCommand < T > ( key , out var result , out var node , out var command ) )
0 commit comments