Designing the Client

First, let's create a new folder named dependencies inside of our temp_messenger folder. Inside, place a new file, redis.py. We will now create a Redis client with a simple method that will get a message, given a key:

from redis import StrictRedis 
 
class RedisClient: 
 
    def __init__(self, url): 
        self.redis = StrictRedis.from_url( 
            url, decode_responses=True 
        ) 

We start off our code by implementing the __init__ method, which creates our Redis client and assigns it to self.redis. StrictRedis that can take a number of optional arguments, however, we have only specified the following:

  • url: Rather than specifying the host, port and database number separately, we can use StrictRedisfrom_url, which will allow us to specify all ...

Get Python Programming Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.