Question: Is Redis a key-value store?


Yes, Redis is primarily known as a key-value store, which is a type of NoSQL database that uses a simple key/value method to store data. Redis stands out due to its ability to store not just strings (which are the simplest form of data in key-value stores), but also more complex data types like lists, sets, sorted sets, and hashes. This capability allows for more complex applications beyond simple key-value storage.

Redis is often used for caching and as a message broker, among other things, due to its high performance and versatility. It supports various operations on these data types, making it an excellent choice for applications requiring high speed and flexibility in data manipulation and storage.

Here's a simple example of how you might interact with Redis as a key-value store using Python:

import redis # Connect to Redis r = redis.Redis(host='localhost', port=6379, db=0) # Set a key with a string value r.set('my_key', 'Hello, world!') # Retrieve and print the value associated with the key print(r.get('my_key').decode('utf-8'))

In this example, my_key is the key under which we store the value 'Hello, world!'. We then retrieve the value by referencing this key and decode it from bytes to a string to print it.

Redis's support for atomic operations and various data structures makes it highly effective for a wide range of tasks, including real-time analytics, leaderboards, session management, and much more.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book
Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.