-
Notifications
You must be signed in to change notification settings - Fork 96
/
client_reply.py
40 lines (33 loc) · 1.48 KB
/
client_reply.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
`client reply off | on | skip` is hard to be supported by aredis gracefully because of the client pool usage.
The client is supposed to read response from server and release connection after the command being sent.
But the connection is needed to be always reused if you need to turn on | off | skip the reply,
it should always be the connection by which you send `client reply` command to server you use to send the rest commands.
However, you can use the connection by your self like the example below~
"""
from aredis import Connection
import asyncio
async def skip():
print('skip response example::')
conn = Connection(host='127.0.0.1', port=6379)
await conn.send_command('flushdb')
print(await conn.read_response())
await conn.send_command('CLIENT REPLY', 'SKIP')
await conn.send_command('SET', 'lalala', 1)
await conn.send_command('SET', 'lalala', 2)
print(await conn.read_response())
async def off_and_on():
print('turn off response and then turn it ')
conn = Connection()
await conn.send_command('flushdb')
print(await conn.read_response())
await conn.send_command('CLIENT REPLY', 'OFF')
await conn.send_command('SET', 'lalala', 10)
await conn.send_command('CLIENT REPLY', 'ON')
print(await conn.read_response())
await conn.send_command('GET', 'lalala')
print(await conn.read_response())
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(skip())
loop.run_until_complete(off_and_on())