-
Notifications
You must be signed in to change notification settings - Fork 0
/
redisclusterclientapp.py
57 lines (48 loc) · 1.44 KB
/
redisclusterclientapp.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
# -*- coding: utf-8 -*-
from optparse import OptionParser
import sys
import signal
import time
import datetime
import keygen
from rediscluster import StrictRedisCluster
count = 0
parser = OptionParser()
parser.add_option("-n","--numofkeys",dest='numofkeys')
(options, args) = parser.parse_args()
def signal_handler(signal,frame):
print("\nwas able to set %d keys" % count)
sys.exit(0)
signal.signal(signal.SIGINT,signal_handler)
if len(sys.argv) == 1:
print("./%s ipaddr1 ipaddr2 ipaddr3 [...]" % sys.argv[0])
sys.exit(1)
try:
'''
startup_nodes = [
{'host':'172.17.0.4','port':'6379'},
{'host':'172.17.0.3','port':'6379'},
{'host':'172.17.0.2','port':'6379'}
]
'''
startup_nodes = [{'host':'%s' % arg.split(':')[0],'port':'%s' % arg.split(':')[1]} for arg in args]
cluster = StrictRedisCluster(startup_nodes = startup_nodes,decode_responses = True)
#master = redis.StrictRedis(host='172.17.0.7')
except:
print(sys.exc_info()[0])
sys.exit(1)
print("commencing SET operations in 3s ...")
time.sleep(3)
count = 0
num = int(options.numofkeys) if options.numofkeys else -1
key,value = keygen.generate_kv_pair()
while count != num:
try:
print("[%s] setting %s -> %s [" % (datetime.datetime.now(),key,value)),
cluster.set(key,value)
print("✓]")
count = count + 1
key,value = keygen.generate_kv_pair()
except:
print("x]")
time.sleep(0.1)