February 2018
Intermediate to advanced
456 pages
9h 56m
English
In redis.py, let's amend our imports to include uuid4:
from uuid import uuid4
uuid4 generates us a unique random string that we can use for our message.
We can now add our new save_message method to the RedisClient:
def save_message(self, message):
message_id = uuid4().hex
self.redis.set(message_id, message)
return message_id
First off, we generate a new message ID using uuid4().hex. The hex attribute gives us the UUID as a 32-character hexadecimal string. We then use it as a key to save the message and return it.
Read now
Unlock full access