diff --git a/src/NRedisStack/Json/JsonCommands.cs b/src/NRedisStack/Json/JsonCommands.cs index 7782408d..05df5b9f 100644 --- a/src/NRedisStack/Json/JsonCommands.cs +++ b/src/NRedisStack/Json/JsonCommands.cs @@ -16,30 +16,67 @@ public JsonCommands(IDatabase db) { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, }; - public RedisResult Set(RedisKey key, RedisValue path, object obj, When when = When.Always) + + + /// + /// Sets the JSON value at path in key. + /// + /// The key of the Json. + /// Json path. + /// Json object. + /// The item to add. + /// if executed correctly, or Null reply if the specified NX or XX conditions were not met. + /// + public bool? Set(RedisKey key, string path, object obj, When when = When.Always) { string json = JsonSerializer.Serialize(obj); return Set(key, path, json, when); } - public RedisResult Set(RedisKey key, RedisValue path, RedisValue json, When when = When.Always) + /// + /// Sets the JSON value at path in key. + /// + /// The key of the Json. + /// Json path. + /// Json object. + /// The item to add. + /// if executed correctly, or Null reply if the specified NX or XX conditions were not met. + /// + public bool? Set(RedisKey key, string path, string json, When when = When.Always) { + RedisResult result; switch (when) { case When.Exists: - return _db.Execute(JSON.SET, key, path, json, "XX"); + result = _db.Execute(JSON.SET, key, path, json, "XX"); + break; case When.NotExists: - return _db.Execute(JSON.SET, key, path, json, "NX"); + result = _db.Execute(JSON.SET, key, path, json, "NX"); + break; default: - return _db.Execute(JSON.SET, key, path, json); + result = _db.Execute(JSON.SET, key, path, json); + break; } + return (result.IsNull) ? null + : ResponseParser.OKtoBoolean(result); + } + /// + /// Returns the value at path in JSON serialized form. + /// + /// The key of the Json. + /// Sets the indentation string for nested levels + /// Sets the string that's printed at the end of each line. + /// Sets the string that's put between a key and a value. + /// Paths in JSON serialized form + /// if executed correctly, or Null reply if the specified NX or XX conditions were not met. + /// public RedisResult Get(RedisKey key, RedisValue? indent = null, RedisValue? newLine = null, RedisValue? space = null, - RedisValue? path = null) + RedisValue[]? paths = null) { List args = new List(){key}; @@ -62,9 +99,12 @@ public RedisResult Get(RedisKey key, args.Add(space); } - if (path != null) + if (paths != null) { - args.Add(path); + foreach (var path in paths) + { + args.Add(path); + } } return _db.Execute(JSON.GET, args);