Mark As Completed Discussion

Introduction to Redis

Redis is an open-source, in-memory data structure store used as a database, cache, and message broker. As an experienced engineer, it's essential to have Redis in your tool chest, particularly if you are working in financial systems or high-volume data processing like AI.

Compared to a relational database like PostgreSQL, Redis stores data in memory which allows it to provide blazing fast read and write operations – an essential feature for real-time applications. Furthermore, you can run atomic operations on these types, like appending to a string; incrementing the value in a hash; pushing an element to a list; computing set intersection, union and difference; or getting the member with highest ranking in a sorted set.

Several high-profile tech companies like GitHub and Snapchat have been known to leverage Redis due to its flexibility, performance, and a rich set of features.

In the Python script below, we demonstrate a simple interaction with Redis. We connect to a Redis server, set a key-value pair, and retrieve the value by its key.

SNIPPET
1if __name__ == '__main__':
2  import redis
3  # connect to Redis server
4  r = redis.Redis(host='localhost', port=6379, db=0)
5  # set a key and value
6  r.set('example_key', 'example_value')
7  # get the value by the key
8  print(r.get('example_key'))

In future screens, we will explore more features of Redis and their use cases.

PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment