Skip to content

Commit fa5c4ac

Browse files
committed
added test.py as an example of async cluster pipeline json commands
1 parent 01c76e8 commit fa5c4ac

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/examples/test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import redis.asyncio as redis
2+
import asyncio
3+
from redis.commands.json.path import Path as Jsonpath
4+
5+
host = "127.0.0.1"
6+
port = 46379
7+
tls = False
8+
ttl = 300
9+
10+
11+
async def main():
12+
r = await redis.RedisCluster(host=host, port=port)
13+
print(f"ping: {await r.ping()}")
14+
15+
async with r.pipeline() as pipe:
16+
set_json, set_expire = await (
17+
pipe
18+
.json().set('test:test6', Jsonpath.root_path(), {'test': 'works'}, nx=True) # nx: if key not exists
19+
.expire('test:test6', ttl)
20+
.execute()
21+
)
22+
assert set_json, "setting key failed"
23+
assert set_expire, "setting expire failed"
24+
print(f"get result: {await r.json().get('test:test6')}")
25+
await r.close()
26+
27+
asyncio.run(main())

0 commit comments

Comments
 (0)