Skip to content

Instantly share code, notes, and snippets.

@mhewedy
Created April 1, 2022 07:19
Show Gist options
  • Save mhewedy/fbb89c862ab80f91174e409bc769bdd7 to your computer and use it in GitHub Desktop.
Save mhewedy/fbb89c862ab80f91174e409bc769bdd7 to your computer and use it in GitHub Desktop.
import socket
class RedisClient:
def __init__(self, **kwargs):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((kwargs['host'], kwargs['port']))
def subscribe(self, channel):
self.sock.send(bytes(f'subscribe {channel}\n\r', 'utf-8'))
def receive(self):
while True:
msg = self.sock.recv(1024).decode('utf-8')
print(msg)
redis = RedisClient(host='localhost', port=6379)
redis.subscribe('foo')
redis.receive()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment