-
Notifications
You must be signed in to change notification settings - Fork 0
/
redisclientapp.py
52 lines (45 loc) · 1.27 KB
/
redisclientapp.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
# -*- coding: utf-8 -*-
import sys
from optparse import OptionParser
import signal
import time
import datetime
import redis
import keygen
def signal_handler(signal,frame):
print('was able to set %d keys' % count)
sys.exit(0)
signal.signal(signal.SIGINT,signal_handler)
try:
if len(sys.argv) == 1:
print('please supply redis ipaddr')
sys.exit(1)
parser = OptionParser()
parser.add_option('-n',dest='numofkeys')
(options,args) = parser.parse_args()
ipaddr = args[0].split(':')[0]
port = int(args[0].split(':')[1])
master = redis.StrictRedis(host=ipaddr,port=port)
except:
print(sys.exc_info()[0])
sys.exit(1)
print("key insert to commence in 3s ...")
time.sleep(3)
value = datetime.datetime.now()
key,value = keygen.generate_kv_pair()
num = int(options.numofkeys) if options.numofkeys else -1
count = 0
while count != num:
try:
print("[%s] setting %s -> %s [" % (datetime.datetime.now(),key,value)),
master.set(key,value)
print("✓]")
value = datetime.datetime.now()
# generate a test key/value pair
key,value = keygen.generate_kv_pair()
count = count + 1
except:
# fail to insert key into redis
print("x]")
# our artificial delay
time.sleep(0.2)