Skip to content

Commit

Permalink
Python: modify json module to use custom_command (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon authored Mar 19, 2024
1 parent 58a3d63 commit 96f78c2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions glide-core/src/protobuf/redis_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,10 @@ enum RequestType {
PTTL = 85;
ZRemRangeByRank = 86;
Persist = 87;
JsonSet = 88;
JsonGet = 89;
ZRemRangeByScore = 90;
Time = 91;
Zrank = 92;
Rename = 93;
ZRemRangeByScore = 88;
Time = 89;
Zrank = 90;
Rename = 91;
}

message Command {
Expand Down
2 changes: 0 additions & 2 deletions glide-core/src/socket_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ fn get_command(request: &Command) -> Option<Cmd> {
RequestType::PTTL => Some(cmd("PTTL")),
RequestType::ZRemRangeByRank => Some(cmd("ZREMRANGEBYRANK")),
RequestType::Persist => Some(cmd("PERSIST")),
RequestType::JsonSet => Some(cmd("JSON.SET")),
RequestType::JsonGet => Some(cmd("JSON.GET")),
RequestType::ZRemRangeByScore => Some(cmd("ZREMRANGEBYSCORE")),
RequestType::Time => Some(cmd("TIME")),
RequestType::Zrank => Some(cmd("ZRANK")),
Expand Down
8 changes: 4 additions & 4 deletions python/python/glide/async_commands/redis_modules/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ async def set(
>>> await redisJson.set(client, "doc", "$", json_str)
'OK' # Indicates successful setting of the value at path '$' in the key stored at `doc`.
"""
args = [key, path, value]
args = ["JSON.SET", key, path, value]
if set_condition:
args.append(set_condition.value)

return cast(Optional[TOK], await client._execute_command(RequestType.JsonSet, args))
return cast(Optional[TOK], await client.custom_command(args))


async def get(
Expand Down Expand Up @@ -128,12 +128,12 @@ async def get(
>>> await redisJson.get(client, "doc", "$.non_existing_path")
"[]" # Returns an empty array since the path '$.non_existing_path' does not exist in the JSON document stored at `doc`.
"""
args = [key]
args = ["JSON.GET", key]
if options:
args.extend(options.get_options())
if paths:
if isinstance(paths, str):
paths = [paths]
args.extend(paths)

return cast(str, await client._execute_command(RequestType.JsonGet, args))
return cast(str, await client.custom_command(args))

0 comments on commit 96f78c2

Please sign in to comment.