66using System . Threading . Tasks ;
77using Redis . OM . Contracts ;
88using Redis . OM . Modeling ;
9+ using StackExchange . Redis ;
910
1011namespace Redis . OM
1112{
@@ -84,7 +85,7 @@ public static async Task<string> SetAsync(this IRedisConnection connection, obje
8485 /// <returns>How many new fields were created.</returns>
8586 public static async Task < int > HSetAsync ( this IRedisConnection connection , string key , params KeyValuePair < string , object > [ ] fieldValues )
8687 {
87- var args = new List < object > { key } ;
88+ var args = new List < object > { new RedisKey ( key ) } ;
8889 foreach ( var kvp in fieldValues )
8990 {
9091 args . Add ( kvp . Key ) ;
@@ -104,7 +105,7 @@ public static async Task<int> HSetAsync(this IRedisConnection connection, string
104105 /// <returns>How many new fields were created.</returns>
105106 public static async Task < int > HSetAsync ( this IRedisConnection connection , string key , TimeSpan timeSpan , params KeyValuePair < string , object > [ ] fieldValues )
106107 {
107- var args = new List < object > { key } ;
108+ var args = new List < object > { new RedisKey ( key ) } ;
108109 foreach ( var kvp in fieldValues )
109110 {
110111 args . Add ( kvp . Key ) ;
@@ -124,7 +125,7 @@ public static async Task<int> HSetAsync(this IRedisConnection connection, string
124125 /// <returns>whether the operation succeeded.</returns>
125126 public static async Task < bool > JsonSetAsync ( this IRedisConnection connection , string key , string path , string json )
126127 {
127- var result = await connection . ExecuteAsync ( "JSON.SET" , key , path , json ) ;
128+ var result = await connection . ExecuteAsync ( "JSON.SET" , new RedisKey ( key ) , path , json ) ;
128129 return result == "OK" ;
129130 }
130131
@@ -139,7 +140,7 @@ public static async Task<bool> JsonSetAsync(this IRedisConnection connection, st
139140 public static async Task < bool > JsonSetAsync ( this IRedisConnection connection , string key , string path , object obj )
140141 {
141142 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 ) ;
143144 return result == "OK" ;
144145 }
145146
@@ -154,7 +155,7 @@ public static async Task<bool> JsonSetAsync(this IRedisConnection connection, st
154155 /// <returns>whether the operation succeeded.</returns>
155156 public static async Task < bool > JsonSetAsync ( this IRedisConnection connection , string key , string path , string json , TimeSpan timeSpan )
156157 {
157- var args = new [ ] { key , path , json } ;
158+ var args = new object [ ] { new RedisKey ( key ) , path , json } ;
158159 return ( await connection . SendCommandWithExpiryAsync ( "JSON.SET" , args , key , timeSpan ) ) . First ( ) == "OK" ;
159160 }
160161
@@ -227,7 +228,7 @@ public static async Task<bool> JsonSetAsync(this IRedisConnection connection, st
227228 public static int HSet ( this IRedisConnection connection , string key , TimeSpan timeSpan , params KeyValuePair < string , object > [ ] fieldValues )
228229 {
229230 var args = new List < object > ( ) ;
230- args . Add ( key ) ;
231+ args . Add ( new RedisKey ( key ) ) ;
231232 foreach ( var kvp in fieldValues )
232233 {
233234 args . Add ( kvp . Key ) ;
@@ -246,7 +247,7 @@ public static int HSet(this IRedisConnection connection, string key, TimeSpan ti
246247 /// <returns>How many new fields were created.</returns>
247248 public static int HSet ( this IRedisConnection connection , string key , params KeyValuePair < string , object > [ ] fieldValues )
248249 {
249- var args = new List < object > { key } ;
250+ var args = new List < object > { new RedisKey ( key ) } ;
250251 foreach ( var kvp in fieldValues )
251252 {
252253 args . Add ( kvp . Key ) ;
@@ -266,7 +267,7 @@ public static int HSet(this IRedisConnection connection, string key, params KeyV
266267 /// <returns>whether the operation succeeded.</returns>
267268 public static bool JsonSet ( this IRedisConnection connection , string key , string path , string json )
268269 {
269- var result = connection . Execute ( "JSON.SET" , key , path , json ) ;
270+ var result = connection . Execute ( "JSON.SET" , new RedisKey ( key ) , path , json ) ;
270271 return result == "OK" ;
271272 }
272273
@@ -281,7 +282,7 @@ public static bool JsonSet(this IRedisConnection connection, string key, string
281282 public static bool JsonSet ( this IRedisConnection connection , string key , string path , object obj )
282283 {
283284 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 ) ;
285286 return result == "OK" ;
286287 }
287288
@@ -296,7 +297,7 @@ public static bool JsonSet(this IRedisConnection connection, string key, string
296297 /// <returns>whether the operation succeeded.</returns>
297298 public static bool JsonSet ( this IRedisConnection connection , string key , string path , string json , TimeSpan timeSpan )
298299 {
299- var arr = new [ ] { key , path , json } ;
300+ var arr = new object [ ] { new RedisKey ( key ) , path , json } ;
300301 return connection . SendCommandWithExpiry ( "JSON.SET" , arr , key , timeSpan ) . First ( ) == "OK" ;
301302 }
302303
@@ -570,7 +571,7 @@ public static string Set(this IRedisConnection connection, object obj, TimeSpan
570571 /// <returns>the object pulled out of redis.</returns>
571572 public static T ? JsonGet < T > ( this IRedisConnection connection , string key , params string [ ] paths )
572573 {
573- var args = new List < string > { key } ;
574+ var args = new List < object > { new RedisKey ( key ) } ;
574575 args . AddRange ( paths ) ;
575576 var res = ( string ) connection . Execute ( "JSON.GET" , args . ToArray ( ) ) ;
576577 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
586587 /// <returns>the object pulled out of redis.</returns>
587588 public static async Task < T ? > JsonGetAsync < T > ( this IRedisConnection connection , string key , params string [ ] paths )
588589 {
589- var args = new List < string > { key } ;
590+ var args = new List < object > { new RedisKey ( key ) } ;
590591 args . AddRange ( paths ) ;
591592 var res = ( string ) await connection . ExecuteAsync ( "JSON.GET" , args . ToArray ( ) ) ;
592593 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
601602 public static IDictionary < string , RedisReply > HGetAll ( this IRedisConnection connection , string keyName )
602603 {
603604 var ret = new Dictionary < string , RedisReply > ( ) ;
604- var res = connection . Execute ( "HGETALL" , keyName ) . ToArray ( ) ;
605+ var res = connection . Execute ( "HGETALL" , new RedisKey ( keyName ) ) . ToArray ( ) ;
605606 for ( var i = 0 ; i < res . Length ; i += 2 )
606607 {
607608 ret . Add ( res [ i ] , res [ i + 1 ] ) ;
@@ -619,7 +620,7 @@ public static IDictionary<string, RedisReply> HGetAll(this IRedisConnection conn
619620 public static async Task < IDictionary < string , RedisReply > > HGetAllAsync ( this IRedisConnection connection , string keyName )
620621 {
621622 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 ( ) ;
623624 for ( var i = 0 ; i < res . Length ; i += 2 )
624625 {
625626 ret . Add ( res [ i ] , res [ i + 1 ] ) ;
@@ -664,7 +665,7 @@ public static async Task<IDictionary<string, RedisReply>> HGetAllAsync(this IRed
664665 sha ,
665666 keys . Count ( ) . ToString ( ) ,
666667 } ;
667- args . AddRange ( keys ) ;
668+ args . AddRange ( keys . Select ( x => new RedisKey ( x ) ) . Cast < object > ( ) ) ;
668669 args . AddRange ( argv ) ;
669670 try
670671 {
@@ -756,15 +757,15 @@ public static async Task<IDictionary<string, RedisReply>> HGetAllAsync(this IRed
756757 /// <param name="connection">the connection.</param>
757758 /// <param name="key">the key to unlink.</param>
758759 /// <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 ) ) ;
760761
761762 /// <summary>
762763 /// Unlinks array of keys.
763764 /// </summary>
764765 /// <param name="connection">the connection.</param>
765766 /// <param name="keys">the keys to unlink.</param>
766767 /// <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 ( ) ) ;
768769
769770 /// <summary>
770771 /// Unlinks the key and then adds an updated value of it.
@@ -835,7 +836,7 @@ private static RedisReply[] SendCommandWithExpiry(
835836 TimeSpan ts )
836837 {
837838 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 ) } ) ;
839840 return connection . ExecuteInTransaction ( new [ ] { commandTuple , expireTuple } ) ;
840841 }
841842
@@ -847,7 +848,7 @@ private static Task<RedisReply[]> SendCommandWithExpiryAsync(
847848 TimeSpan ts )
848849 {
849850 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 ) } ) ;
851852 return connection . ExecuteInTransactionAsync ( new [ ] { commandTuple , expireTuple } ) ;
852853 }
853854 }
0 commit comments