Saving messages

Earlier, I introduced the Redis SET method. This will allow us to save a message to Redis, but first, we need to create a new method in our dependency provider that will handle this.

We could simply create a new method that called redis.set(message_id, message), but how would we handle new message IDs? It would be a bit troublesome if we expected the user to input a new message ID for each message they wanted to send, right? An alternative is to have the message service generate a new random message ID before it calls the dependency provider, but that would clutter our service with logic that could be handled by the dependency itself.

We'll solve this by having the dependency create a random string to be used as the message ...

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.