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 StrictRedis' from_url, which will allow us to specify all ...