Skip to content

Instantly share code, notes, and snippets.

@72squared
Last active February 5, 2017 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 72squared/92262949a90b6ea12e5375d68b6ff5e6 to your computer and use it in GitHub Desktop.
Save 72squared/92262949a90b6ea12e5375d68b6ff5e6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import rediscluster
import uuid
import sys
import time
def create_connection():
startup_nodes = [
{'host': '127.0.0.1', 'port': 7000},
{'host': '127.0.0.1', 'port': 7001},
{'host': '127.0.0.1', 'port': 7002},
{'host': '127.0.0.1', 'port': 7003},
{'host': '127.0.0.1', 'port': 7004},
{'host': '127.0.0.1', 'port': 7005},
]
return rediscluster.StrictRedisCluster(startup_nodes=startup_nodes)
RECREATE_CONNECTION = False
conn = create_connection()
keys = {'a', 'b', 'c'}
ct = 0
while True:
try:
pipe = conn.pipeline(transaction=False)
xids = [uuid.uuid4().hex[0:6] for _ in range(0, 4)]
for xid in xids:
for k in keys:
pipe.hset(xid, k, "%s-%s" % (k, xid))
for xid in xids:
pipe.hgetall(xid)
result = pipe.execute()[ - len(xids):]
for i, row in enumerate(result):
xid = xids[i]
if keys != set(row.keys()):
raise Exception('xid %s keys invalid %s' % (xid, row))
for k in keys:
if row[k] != "%s-%s" % (k, xid):
raise Exception('xid %s has invalid value %s' % (xid, row[k]))
ct += 1
sys.stdout.write('\r%s' % ct)
except Exception as e:
sys.stdout.write('\n------\nException <%s> %s\n------\n' % (type(e), e))
time.sleep(1)
if RECREATE_CONNECTION:
conn = create_connection()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment