Redis 101: A Comprehensive Guide to Redis

Listen to this Post

Redis (Remote Dictionary Server) is one of the most popular data stores in the world, known for its sub-millisecond latency and versatile features. It serves as both a cache and a full-fledged database, making it a critical component in high-traffic systems like Airbnb, Uber, and Slack.

You Should Know:

1. Basic Redis Commands

Here are some essential Redis commands to get started:

  • SET key value: Stores a value in a key.
    SET user:1 "John Doe"
    
  • GET key: Retrieves the value of a key.
    GET user:1
    
  • DEL key: Deletes a key.
    DEL user:1
    
  • INCR key: Increments the integer value of a key by 1.
    INCR counter
    
  • HSET key field value: Sets a field in a hash.
    HSET user:1 name "John Doe"
    

2. Redis Data Structures

Redis supports various data structures:

  • Strings: Basic key-value storage.
  • Lists: Ordered collections of strings.
  • Sets: Unordered collections of unique strings.
  • Sorted Sets: Sets with a score for ordering.
  • Hashes: Maps between string fields and values.
  • Bitmaps: Compact data structures for binary operations.

3. Redis Persistence

Redis ensures data durability through:

  • RDB (Redis Database Backup): Periodic snapshots of the dataset.
  • AOF (Append-Only File): Logs every write operation.

4. Redis Pub/Sub

Redis supports a publish-subscribe model for event-driven architectures:

  • PUBLISH channel message: Sends a message to a channel.
    PUBLISH notifications "Hello, World!"
    
  • SUBSCRIBE channel: Listens to messages on a channel.
    SUBSCRIBE notifications
    

5. Redis Modules

Extend Redis functionality with modules like:

  • RedisJSON: Adds JSON support.
  • RediSearch: Enables full-text search.

6. Redis Use Cases

  • Distributed Caching: Speeds up data access.
  • Session Storage: Manages user sessions.
  • Message Queue: Facilitates communication between services.
  • Rate Limiting: Controls request rates.

What Undercode Say:

Redis is a powerful tool for modern applications, offering speed, flexibility, and scalability. Whether you’re building a high-traffic website or a real-time messaging system, Redis can handle it. Here are some additional Linux and Windows commands to enhance your Redis experience: