6
6
using System . Threading . Tasks ;
7
7
using Redis . OM . Contracts ;
8
8
using Redis . OM . Modeling ;
9
+ using StackExchange . Redis ;
9
10
10
11
namespace Redis . OM
11
12
{
@@ -84,7 +85,7 @@ public static async Task<string> SetAsync(this IRedisConnection connection, obje
84
85
/// <returns>How many new fields were created.</returns>
85
86
public static async Task < int > HSetAsync ( this IRedisConnection connection , string key , params KeyValuePair < string , object > [ ] fieldValues )
86
87
{
87
- var args = new List < object > { key } ;
88
+ var args = new List < object > { new RedisKey ( key ) } ;
88
89
foreach ( var kvp in fieldValues )
89
90
{
90
91
args . Add ( kvp . Key ) ;
@@ -104,7 +105,7 @@ public static async Task<int> HSetAsync(this IRedisConnection connection, string
104
105
/// <returns>How many new fields were created.</returns>
105
106
public static async Task < int > HSetAsync ( this IRedisConnection connection , string key , TimeSpan timeSpan , params KeyValuePair < string , object > [ ] fieldValues )
106
107
{
107
- var args = new List < object > { key } ;
108
+ var args = new List < object > { new RedisKey ( key ) } ;
108
109
foreach ( var kvp in fieldValues )
109
110
{
110
111
args . Add ( kvp . Key ) ;
@@ -124,7 +125,7 @@ public static async Task<int> HSetAsync(this IRedisConnection connection, string
124
125
/// <returns>whether the operation succeeded.</returns>
125
126
public static async Task < bool > JsonSetAsync ( this IRedisConnection connection , string key , string path , string json )
126
127
{
127
- var result = await connection . ExecuteAsync ( "JSON.SET" , key , path , json ) ;
128
+ var result = await connection . ExecuteAsync ( "JSON.SET" , new RedisKey ( key ) , path , json ) ;
128
129
return result == "OK" ;
129
130
}
130
131
@@ -139,7 +140,7 @@ public static async Task<bool> JsonSetAsync(this IRedisConnection connection, st
139
140
public static async Task < bool > JsonSetAsync ( this IRedisConnection connection , string key , string path , object obj )
140
141
{
141
142
var json = JsonSerializer . Serialize ( obj , RedisSerializationSettings . JsonSerializerOptions ) ;
142
- var result = await connection . ExecuteAsync ( "JSON.SET" , key , path , json ) ;
143
+ var result = await connection . ExecuteAsync ( "JSON.SET" , new RedisKey ( key ) , path , json ) ;
143
144
return result == "OK" ;
144
145
}
145
146
@@ -154,7 +155,7 @@ public static async Task<bool> JsonSetAsync(this IRedisConnection connection, st
154
155
/// <returns>whether the operation succeeded.</returns>
155
156
public static async Task < bool > JsonSetAsync ( this IRedisConnection connection , string key , string path , string json , TimeSpan timeSpan )
156
157
{
157
- var args = new [ ] { key , path , json } ;
158
+ var args = new object [ ] { new RedisKey ( key ) , path , json } ;
158
159
return ( await connection . SendCommandWithExpiryAsync ( "JSON.SET" , args , key , timeSpan ) ) . First ( ) == "OK" ;
159
160
}
160
161
@@ -227,7 +228,7 @@ public static async Task<bool> JsonSetAsync(this IRedisConnection connection, st
227
228
public static int HSet ( this IRedisConnection connection , string key , TimeSpan timeSpan , params KeyValuePair < string , object > [ ] fieldValues )
228
229
{
229
230
var args = new List < object > ( ) ;
230
- args . Add ( key ) ;
231
+ args . Add ( new RedisKey ( key ) ) ;
231
232
foreach ( var kvp in fieldValues )
232
233
{
233
234
args . Add ( kvp . Key ) ;
@@ -246,7 +247,7 @@ public static int HSet(this IRedisConnection connection, string key, TimeSpan ti
246
247
/// <returns>How many new fields were created.</returns>
247
248
public static int HSet ( this IRedisConnection connection , string key , params KeyValuePair < string , object > [ ] fieldValues )
248
249
{
249
- var args = new List < object > { key } ;
250
+ var args = new List < object > { new RedisKey ( key ) } ;
250
251
foreach ( var kvp in fieldValues )
251
252
{
252
253
args . Add ( kvp . Key ) ;
@@ -266,7 +267,7 @@ public static int HSet(this IRedisConnection connection, string key, params KeyV
266
267
/// <returns>whether the operation succeeded.</returns>
267
268
public static bool JsonSet ( this IRedisConnection connection , string key , string path , string json )
268
269
{
269
- var result = connection . Execute ( "JSON.SET" , key , path , json ) ;
270
+ var result = connection . Execute ( "JSON.SET" , new RedisKey ( key ) , path , json ) ;
270
271
return result == "OK" ;
271
272
}
272
273
@@ -281,7 +282,7 @@ public static bool JsonSet(this IRedisConnection connection, string key, string
281
282
public static bool JsonSet ( this IRedisConnection connection , string key , string path , object obj )
282
283
{
283
284
var json = JsonSerializer . Serialize ( obj , RedisSerializationSettings . JsonSerializerOptions ) ;
284
- var result = connection . Execute ( "JSON.SET" , key , path , json ) ;
285
+ var result = connection . Execute ( "JSON.SET" , new RedisKey ( key ) , path , json ) ;
285
286
return result == "OK" ;
286
287
}
287
288
@@ -296,7 +297,7 @@ public static bool JsonSet(this IRedisConnection connection, string key, string
296
297
/// <returns>whether the operation succeeded.</returns>
297
298
public static bool JsonSet ( this IRedisConnection connection , string key , string path , string json , TimeSpan timeSpan )
298
299
{
299
- var arr = new [ ] { key , path , json } ;
300
+ var arr = new object [ ] { new RedisKey ( key ) , path , json } ;
300
301
return connection . SendCommandWithExpiry ( "JSON.SET" , arr , key , timeSpan ) . First ( ) == "OK" ;
301
302
}
302
303
@@ -570,7 +571,7 @@ public static string Set(this IRedisConnection connection, object obj, TimeSpan
570
571
/// <returns>the object pulled out of redis.</returns>
571
572
public static T ? JsonGet < T > ( this IRedisConnection connection , string key , params string [ ] paths )
572
573
{
573
- var args = new List < string > { key } ;
574
+ var args = new List < object > { new RedisKey ( key ) } ;
574
575
args . AddRange ( paths ) ;
575
576
var res = ( string ) connection . Execute ( "JSON.GET" , args . ToArray ( ) ) ;
576
577
return ! string . IsNullOrEmpty ( res ) ? JsonSerializer . Deserialize < T > ( res , RedisSerializationSettings . JsonSerializerOptions ) : default ;
@@ -586,7 +587,7 @@ public static string Set(this IRedisConnection connection, object obj, TimeSpan
586
587
/// <returns>the object pulled out of redis.</returns>
587
588
public static async Task < T ? > JsonGetAsync < T > ( this IRedisConnection connection , string key , params string [ ] paths )
588
589
{
589
- var args = new List < string > { key } ;
590
+ var args = new List < object > { new RedisKey ( key ) } ;
590
591
args . AddRange ( paths ) ;
591
592
var res = ( string ) await connection . ExecuteAsync ( "JSON.GET" , args . ToArray ( ) ) ;
592
593
return ! string . IsNullOrEmpty ( res ) ? JsonSerializer . Deserialize < T > ( res , RedisSerializationSettings . JsonSerializerOptions ) : default ;
@@ -601,7 +602,7 @@ public static string Set(this IRedisConnection connection, object obj, TimeSpan
601
602
public static IDictionary < string , RedisReply > HGetAll ( this IRedisConnection connection , string keyName )
602
603
{
603
604
var ret = new Dictionary < string , RedisReply > ( ) ;
604
- var res = connection . Execute ( "HGETALL" , keyName ) . ToArray ( ) ;
605
+ var res = connection . Execute ( "HGETALL" , new RedisKey ( keyName ) ) . ToArray ( ) ;
605
606
for ( var i = 0 ; i < res . Length ; i += 2 )
606
607
{
607
608
ret . Add ( res [ i ] , res [ i + 1 ] ) ;
@@ -619,7 +620,7 @@ public static IDictionary<string, RedisReply> HGetAll(this IRedisConnection conn
619
620
public static async Task < IDictionary < string , RedisReply > > HGetAllAsync ( this IRedisConnection connection , string keyName )
620
621
{
621
622
var ret = new Dictionary < string , RedisReply > ( ) ;
622
- var res = ( await connection . ExecuteAsync ( "HGETALL" , keyName ) ) . ToArray ( ) ;
623
+ var res = ( await connection . ExecuteAsync ( "HGETALL" , new RedisKey ( keyName ) ) ) . ToArray ( ) ;
623
624
for ( var i = 0 ; i < res . Length ; i += 2 )
624
625
{
625
626
ret . Add ( res [ i ] , res [ i + 1 ] ) ;
@@ -664,7 +665,7 @@ public static async Task<IDictionary<string, RedisReply>> HGetAllAsync(this IRed
664
665
sha ,
665
666
keys . Count ( ) . ToString ( ) ,
666
667
} ;
667
- args . AddRange ( keys ) ;
668
+ args . AddRange ( keys . Select ( x => new RedisKey ( x ) ) . Cast < object > ( ) ) ;
668
669
args . AddRange ( argv ) ;
669
670
try
670
671
{
@@ -756,15 +757,15 @@ public static async Task<IDictionary<string, RedisReply>> HGetAllAsync(this IRed
756
757
/// <param name="connection">the connection.</param>
757
758
/// <param name="key">the key to unlink.</param>
758
759
/// <returns>the status.</returns>
759
- public static async Task < long > UnlinkAsync ( this IRedisConnection connection , string key ) => await connection . ExecuteAsync ( "UNLINK" , key ) ;
760
+ public static async Task < long > UnlinkAsync ( this IRedisConnection connection , string key ) => await connection . ExecuteAsync ( "UNLINK" , new RedisKey ( key ) ) ;
760
761
761
762
/// <summary>
762
763
/// Unlinks array of keys.
763
764
/// </summary>
764
765
/// <param name="connection">the connection.</param>
765
766
/// <param name="keys">the keys to unlink.</param>
766
767
/// <returns>the status.</returns>
767
- public static async Task < long > UnlinkAsync ( this IRedisConnection connection , string [ ] keys ) => await connection . ExecuteAsync ( "UNLINK" , keys ) ;
768
+ public static async Task < long > UnlinkAsync ( this IRedisConnection connection , string [ ] keys ) => await connection . ExecuteAsync ( "UNLINK" , keys . Select ( x => new RedisKey ( x ) ) . Cast < object > ( ) . ToArray ( ) ) ;
768
769
769
770
/// <summary>
770
771
/// Unlinks the key and then adds an updated value of it.
@@ -835,7 +836,7 @@ private static RedisReply[] SendCommandWithExpiry(
835
836
TimeSpan ts )
836
837
{
837
838
var commandTuple = Tuple . Create ( command , args ) ;
838
- var expireTuple = Tuple . Create ( "PEXPIRE" , new object [ ] { keyToExpire , ( ( long ) ts . TotalMilliseconds ) . ToString ( CultureInfo . InvariantCulture ) } ) ;
839
+ var expireTuple = Tuple . Create ( "PEXPIRE" , new object [ ] { new RedisKey ( keyToExpire ) , ( ( long ) ts . TotalMilliseconds ) . ToString ( CultureInfo . InvariantCulture ) } ) ;
839
840
return connection . ExecuteInTransaction ( new [ ] { commandTuple , expireTuple } ) ;
840
841
}
841
842
@@ -847,7 +848,7 @@ private static Task<RedisReply[]> SendCommandWithExpiryAsync(
847
848
TimeSpan ts )
848
849
{
849
850
var commandTuple = Tuple . Create ( command , args ) ;
850
- var expireTuple = Tuple . Create ( "PEXPIRE" , new object [ ] { keyToExpire , ( ( long ) ts . TotalMilliseconds ) . ToString ( CultureInfo . InvariantCulture ) } ) ;
851
+ var expireTuple = Tuple . Create ( "PEXPIRE" , new object [ ] { new RedisKey ( keyToExpire ) , ( ( long ) ts . TotalMilliseconds ) . ToString ( CultureInfo . InvariantCulture ) } ) ;
851
852
return connection . ExecuteInTransactionAsync ( new [ ] { commandTuple , expireTuple } ) ;
852
853
}
853
854
}
0 commit comments