Skip to content

Commit cf3bcdc

Browse files
author
Alex Kouzemtchenko
committed
Hacky test + fixes for it
1 parent 1a7d474 commit cf3bcdc

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

redis/asyncio/cluster.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,9 @@ def __init__(self, client: RedisCluster) -> None:
14341434

14351435
self._command_stack: List["PipelineCommand"] = []
14361436

1437+
self.nodes_manager = self._client.nodes_manager
1438+
self.set_response_callback = self._client.set_response_callback
1439+
14371440
async def initialize(self) -> "ClusterPipeline":
14381441
if self._client._initialize:
14391442
await self._client.initialize()

redis/commands/json/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from json import JSONDecodeError, JSONDecoder, JSONEncoder
22

33
import redis
4+
import redis.asyncio as redis_asyncio
45

56
from ..helpers import get_protocol_version, nativestr
67
from .commands import JSONCommands
@@ -125,7 +126,10 @@ def pipeline(self, transaction=True, shard_hint=None):
125126
reinitialize_steps=self.client.reinitialize_steps,
126127
lock=self.client._lock,
127128
)
128-
129+
elif isinstance(self.client, redis_asyncio.RedisCluster):
130+
p = AsyncClusterPipeline(
131+
client = self.client
132+
)
129133
else:
130134
p = Pipeline(
131135
connection_pool=self.client.connection_pool,
@@ -143,5 +147,9 @@ class ClusterPipeline(JSONCommands, redis.cluster.ClusterPipeline):
143147
"""Cluster pipeline for the module."""
144148

145149

150+
class AsyncClusterPipeline(JSONCommands, redis_asyncio.cluster.ClusterPipeline):
151+
"""Cluster pipeline for the module."""
152+
153+
146154
class Pipeline(JSONCommands, redis.client.Pipeline):
147155
"""Pipeline for the module."""

redis/commands/redismodules.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ def graph(self, index_name="idx"):
8484

8585

8686
class AsyncRedisModuleCommands(RedisModuleCommands):
87+
def json(self, encoder=JSONEncoder(), decoder=JSONDecoder()):
88+
"""Access the json namespace, providing support for redis json."""
89+
90+
from .json import JSON
91+
92+
jj = JSON(client=self, encoder=encoder, decoder=decoder)
93+
return jj
94+
8795
def ft(self, index_name="idx"):
8896
"""Access the search namespace, providing support for redis search."""
8997

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
long_description_content_type="text/markdown",
99
keywords=["Redis", "key-value store", "database"],
1010
license="MIT",
11-
version="5.1.0b3",
11+
version="5.1.2",
1212
packages=find_packages(
1313
include=[
1414
"redis",

test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import asyncio
2+
from redis.asyncio.cluster import RedisCluster # type: ignore
3+
import redis.asyncio as redis # type: ignore
4+
5+
async def main():
6+
r = RedisCluster.from_url("redis://localhost:16379/0")
7+
p = r.pipeline()
8+
p.json().set("blah", ".", 1)
9+
p.set("blah2", 1)
10+
await p.execute()
11+
12+
13+
p = r.json().pipeline()
14+
p.set("blah3", ".", 1)
15+
await p.execute()
16+
print("done")
17+
18+
loop = asyncio.new_event_loop()
19+
asyncio.set_event_loop(loop)
20+
asyncio.get_event_loop().run_until_complete(main())

0 commit comments

Comments
 (0)