Skip to content

Instantly share code, notes, and snippets.

@kristoff-it
Created April 9, 2019 11:16
Show Gist options
  • Save kristoff-it/8b7e91595fa740341615dabee3a22574 to your computer and use it in GitHub Desktop.
Save kristoff-it/8b7e91595fa740341615dabee3a22574 to your computer and use it in GitHub Desktop.
import redis
r = redis.Redis(decode_responses=True)
data = {"hello": "world", "ans": 42}
p1 = r.pubsub(ignore_subscribe_messages=True)
p1.subscribe("channel")
# Assuming we have an exposed RESP3 parser from the library
r.publish("channel", redis.RESP3.to_string(data))
reply = redis.RESP3.from_string(p1.get_message()['data'])
assert reply == data # => true
# Maybe also a bit more sugar?
resp_p1 = redis.RESP3.respify(p1)
r.RESP3.publish("channel", data)
reply1 = resp_p1.get_message()
assert reply1.data == data # => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment