Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import protofile.bus_arch.message.python.message_pb2 as bm
- from rediscluster import StrictRedisCluster
- import redis
- import zlib
- import uuid
- import struct
- def connectStandalone(host, port):
- return redis.Redis(host=host, port=port)
- def connectCluster(host, port):
- # Requires at least one node for cluster discovery. Multiple nodes is recommended.
- startup_nodes = [{"host": host, "port": port}]
- # Note: See note on Python 3 for decode_responses behaviour
- return StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)
- def craftData(function, msg):
- data = bm.BusMessage()
- data.version = "0.3.0"
- data.replyChannel = "qa-k1"
- data.function = function
- data.data = str.encode(msg)
- data.crc = struct.pack("<I", zlib.crc32(msg.encode('utf-8'))%(1<<32))
- return data.SerializeToString()
- # rc = connectStandalone('localhost', 6379)
- rc = connectCluster('10.10.20.191', 30039)
- rc.lpush("{bus:bms-channel}", craftData('create-building', '{"name": "orgNmae"}'))
- reply = rc.brpop("qa-k1")
- message = bm.BusMessage()
- message.ParseFromString(reply[1])
- print (message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement