-
Notifications
You must be signed in to change notification settings - Fork 216
/
test_pipe.py
64 lines (49 loc) · 1.28 KB
/
test_pipe.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /usr/bin/env python
from functools import partial
import time
import os
from pprint import pprint
import brukva
c = brukva.Client()
c.connect()
def delayed(dt, cmd, *args, **kwargs):
c._io_loop.add_timeout(
time.time()+dt,
partial(cmd, *args, **kwargs)
)
def ac(cmd, *args, **kwargs):
c._io_loop.add_callback(
partial(cmd, *args, **kwargs)
)
stt = time.time()
def on_resp(res):
pprint(res)
print (time.time() - stt)
c.set('gt', 'er', on_resp)
c.mget(['gt','sdfas'], on_resp)
c.get('gt', on_resp)
c.flushdb()
p = c.pipeline()#transactional=True)
p.set('foo1', 'bar')
p.get('foo1')
p.set('bar', '123')
p.mget(['foo1', 'bar',])
p.sadd('zar', '1')
p.sadd('zar', '4')
p.smembers('zar')
p.scard('zar')
c.zadd('nya', 1, 'n', on_resp)
c.zadd('nya', 2, 'sf', on_resp)
p.zrange('nya', 0, -1, with_scores=True, callbacks=on_resp)
ac( p.execute, [on_resp,])
delayed(0.1, p.set, 'aaa', '132')
delayed(0.1, p.set, 'bbb', 'eft')
delayed(0.1, p.mget, ('aaa', 'ccc', 'bbb'))
delayed(0.1, p.sadd, 'foo', '13d2')
delayed(0.1, p.sadd, 'foo', 'efdt')
delayed(0.1, p.lpop, 'aaa') # must fail
delayed(0.1, p.mget, ('aaa', 'bbb'))
delayed(0.1, p.smembers, 'foo' )
delayed(0.1, p.execute, [on_resp,])
delayed(0.3, os.sys.exit)
c.connection._stream.io_loop.start()