Repository navigation
added generic json path implementation - #336
Conversation
065c086 to
1c5f86f
Compare
| if paths.len() > 0 { | ||
| let mut res = None; | ||
| for p in paths { | ||
| res = Some(redis_key.str_append(p, json.clone())?); |
There was a problem hiding this comment.
-
Will not report on paths leading to non-String values (different behavior than before)
-
Might modify only a sub-set of
pathsand fail in the middle - not "atomic" (to be addressed by another PR?)
- Only reporting the first encountered error (using the
?operator)
There was a problem hiding this comment.
- Yes but we need to decide this behavior, I believe we can decide it when redefine the API on 2.0
- Looking at the API it can happened but looking at the impl it can not, again we should give an api that can expose such errors
- Yes but again this is an api limitation
| fn set_root(&mut self, v: Option<Value>) -> Result<(), RedisError> { | ||
| match v { | ||
| Some(inner) => { | ||
| let v = self.key.get_value::<RedisJSON>(&REDIS_JSON_TYPE)?; |
There was a problem hiding this comment.
Calling get_value could be redundant here, such as when coming from command_json_set calling WriteHolder::set_value calling set_root, where the value was already obtained before in command_json_set by
let current = redis_key.get_value()?;
| if path == JSON_ROOT_PATH { | ||
| if *op != SetOptions::NotExists { | ||
| redis_key.set_value(Vec::new(), val)?; | ||
| redis_key.apply_changes(ctx, "json.set")?; |
There was a problem hiding this comment.
Should apply_changes be called only when the return value from redis_key.set_value is Ok(true)?
(although currently it seems to be possible to get only Ok(false) or Err)
There was a problem hiding this comment.
Well, its updating the root so it can not failed (return false). We can assert it, WDYT?
There was a problem hiding this comment.
There are more calls to apply_changes, some consider the result of the "write" operation (set_value, del, etc.),
But some don't, or only consider the last result of a for iteration, such as in command_json_num_op , command_json_bool_toggle , command_json_str_append , command_json_arr_append , command_json_arr_insert , command_json_arr_trim , command_json_clear
However, this is also related to atomicity and the behavior needs to be decided as commented here
(also for command_json_arr_pop)
There was a problem hiding this comment.
Yes, the assumption is that the last result should be the same as the first result. but I agree this all story need to be handled together with the API changed
| } | ||
| } | ||
| if SetOptions::AlreadyExists != *option { | ||
| self.find_add_paths(path) |
There was a problem hiding this comment.
If option is NotExists we will reach here - may find_add_paths find and return an existing value?
There was a problem hiding this comment.
Yes this only gives you what need to be done, but the WriteHolder implementation will not let you set an existing value in a dictionary so it will be catch after.
All comments was fixed, I do not know why github still not allow merge.
No description provided.