Created
April 1, 2022 07:19
-
-
Save mhewedy/fbb89c862ab80f91174e409bc769bdd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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