@@ -150,6 +150,11 @@ public List<string> GetAllKeys()
150
150
return client . GetAllKeys ( ) ;
151
151
}
152
152
153
+ public string UrnKey ( T entity )
154
+ {
155
+ return client . UrnKey ( entity ) ;
156
+ }
157
+
153
158
public IRedisSet TypeIdsSet
154
159
{
155
160
get
@@ -176,28 +181,53 @@ public T DeserializeValue(byte[] value)
176
181
return serializer . DeserializeFromString ( strValue ) ;
177
182
}
178
183
179
- public void SetEntry ( string key , T value )
184
+ public void SetValue ( string key , T entity )
180
185
{
181
186
if ( key == null )
182
187
throw new ArgumentNullException ( "key" ) ;
183
188
184
- client . Set ( key , SerializeValue ( value ) ) ;
185
- client . RegisterTypeId ( value ) ;
189
+ client . Set ( key , SerializeValue ( entity ) ) ;
190
+ client . RegisterTypeId ( entity ) ;
186
191
}
187
192
188
- public void SetEntry ( string key , T value , TimeSpan expireIn )
193
+ [ Obsolete ( "Use SetValue()" ) ]
194
+ public void SetEntry ( string key , T value )
195
+ {
196
+ SetValue ( key , value ) ;
197
+ }
198
+
199
+ public void SetValue ( string key , T entity , TimeSpan expireIn )
189
200
{
190
201
if ( key == null )
191
202
throw new ArgumentNullException ( "key" ) ;
192
203
193
- client . Set ( key , SerializeValue ( value ) , expireIn ) ;
194
- client . RegisterTypeId ( value ) ;
204
+ client . Set ( key , SerializeValue ( entity ) , expireIn ) ;
205
+ client . RegisterTypeId ( entity ) ;
206
+ }
207
+
208
+ [ Obsolete ( "Use SetValue()" ) ]
209
+ public void SetEntry ( string key , T value , TimeSpan expireIn )
210
+ {
211
+ SetValue ( key , value , expireIn ) ;
212
+ }
213
+
214
+ public bool SetValueIfNotExists ( string key , T entity )
215
+ {
216
+ var success = client . SetNX ( key , SerializeValue ( entity ) ) == RedisNativeClient . Success ;
217
+ if ( success ) client . RegisterTypeId ( entity ) ;
218
+ return success ;
195
219
}
196
220
221
+ [ Obsolete ( "Use SetValueIfNotExists()" ) ]
197
222
public bool SetEntryIfNotExists ( string key , T value )
198
223
{
199
- var success = client . SetNX ( key , SerializeValue ( value ) ) == RedisNativeClient . Success ;
200
- if ( success ) client . RegisterTypeId ( value ) ;
224
+ return SetValueIfNotExists ( key , value ) ;
225
+ }
226
+
227
+ public bool SetValueIfExists ( string key , T entity )
228
+ {
229
+ var success = client . Set ( key , SerializeValue ( entity ) , exists : true ) ;
230
+ if ( success ) client . RegisterTypeId ( entity ) ;
201
231
return success ;
202
232
}
203
233
@@ -399,8 +429,14 @@ public IList<T> GetAll()
399
429
public T Store ( T entity )
400
430
{
401
431
var urnKey = client . UrnKey ( entity ) ;
402
- this . SetEntry ( urnKey , entity ) ;
432
+ this . SetValue ( urnKey , entity ) ;
433
+ return entity ;
434
+ }
403
435
436
+ public T Store ( T entity , TimeSpan expireIn )
437
+ {
438
+ var urnKey = client . UrnKey ( entity ) ;
439
+ this . SetValue ( urnKey , entity , expireIn ) ;
404
440
return entity ;
405
441
}
406
442
0 commit comments