Using Redis

Let's briefly look at the types of Redis commands that could be useful to us for TempMessenger:

  • SET: Sets a given key to hold a given string. It also allows us to set an expiration in seconds or milliseconds.
  • GET: Gets the value of the data stored with the given key.
  • TTL: Gets the time-to-live for a given key in seconds.
  • PTTL: Gets the time-to-live for a given key in milliseconds.
  • KEYS: Returns a list of all keys in the data store.

To try them out, we can use redis-cli which is a program that ships with our Redis container. To access it, first log in to the container by executing the following in your terminal:

docker exec -it redis /bin/bash

Then access redis-cli in the same terminal window by simply running:

redis-cli 

There ...

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.