liminfo

Redis Reference

Free reference guide: Redis Reference

27 results

About Redis Reference

The Redis Command Reference is a comprehensive, searchable cheat sheet covering all major Redis data structure commands across six categories: Strings, Lists, Hashes, Sets, Sorted Sets, and Cluster operations. Each entry includes the exact command syntax, a plain-English description, and a real-world usage example — making it easy to look up the right command whether you are building a caching layer, a message queue, a leaderboard, or a session store.

This reference is built for backend developers, DevOps engineers, and architects who work with Redis daily. It covers everyday commands like SET/GET and MSET/MGET for string storage, LPUSH/RPUSH/BLPOP for queue and stack patterns, HSET/HGETALL for object modeling with hashes, SADD/SUNION/SINTER for set operations, and ZADD/ZRANGE/ZRANK for sorted-set leaderboards. Cluster commands such as CLUSTER INFO and redis-cli --cluster create are also included for distributed deployments.

Entries are organized by data type category so you can quickly navigate to the commands relevant to your use case. The reference covers the SETNX distributed lock pattern, INCR/DECR atomic counters, BLPOP blocking queues, HINCRBY field increments, sorted-set score manipulation with ZINCRBY, and cluster node management — giving you a single reference that covers both single-instance and horizontally scaled Redis topologies.

Key Features

  • Full coverage of Redis String commands: SET, GET, MSET/MGET, INCR/DECR, SETNX with EX/NX options
  • List commands for queue and stack patterns: LPUSH, RPUSH, LPOP, RPOP, LRANGE, LLEN, BLPOP
  • Hash commands for object storage: HSET, HGET, HGETALL, HMSET/HMGET, HINCRBY
  • Set commands with union, intersection, and difference: SADD, SMEMBERS, SISMEMBER, SUNION, SINTER, SDIFF
  • Sorted Set leaderboard commands: ZADD, ZRANGE, ZREVRANGE, ZINCRBY, ZRANK with WITHSCORES examples
  • Redis Cluster management: CLUSTER INFO, CLUSTER NODES, redis-cli --cluster create with replica count
  • Real-world examples for distributed locks, session expiry, atomic counters, and blocking queues
  • Category-based navigation so you can jump directly to String, List, Hash, Set, Sorted Set, or Cluster commands

Frequently Asked Questions

What Redis data types does this reference cover?

This reference covers all six major categories used in day-to-day Redis development: Strings (SET, GET, MSET, INCR), Lists (LPUSH, RPUSH, BLPOP), Hashes (HSET, HGETALL, HMSET), Sets (SADD, SUNION, SINTER), Sorted Sets (ZADD, ZRANGE, ZRANK), and Cluster commands (CLUSTER INFO, redis-cli --cluster create).

How do I implement a distributed lock with Redis?

Use SETNX key value combined with an expiry to create a distributed lock. The modern recommended approach is SET key value NX EX 30, which atomically sets the key only if it does not exist (NX) and applies a 30-second expiration (EX). This prevents deadlocks if the lock holder crashes.

What is the difference between LPUSH and RPUSH?

LPUSH adds one or more elements to the head (left side) of a list, while RPUSH appends to the tail (right side). To implement a first-in-first-out queue, use RPUSH to enqueue and LPOP to dequeue. For a LIFO stack, use LPUSH and LPOP on the same side.

When should I use a Hash instead of a String in Redis?

Use a Hash (HSET, HGETALL) when you need to store multiple fields for a single entity, such as a user profile with name, email, and age fields. This is more memory-efficient than storing each field as a separate String key and lets you update individual fields with HSET without overwriting the entire object.

How does ZADD differ from SADD in Redis?

SADD adds members to an unordered Set where each member is unique but has no ranking. ZADD adds members to a Sorted Set where each member has an associated floating-point score. Sorted Sets let you retrieve members by rank order (ZRANGE, ZREVRANGE) or score range, making them ideal for leaderboards, priority queues, and time-series indexes.

What is BLPOP and when should I use it?

BLPOP is a blocking variant of LPOP. If the list is empty, BLPOP waits up to the specified timeout for a new element to appear, then pops and returns it. This makes it perfect for implementing worker queues where consumer processes should efficiently wait for jobs rather than polling in a loop with sleep.

How do I create a Redis Cluster with redis-cli?

Use the command: redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 --cluster-replicas 1. This creates a cluster with three master nodes and one replica per master (six nodes total). Redis Cluster automatically distributes 16384 hash slots across the masters and handles failover through replica promotion.

What is the difference between ZRANGE and ZREVRANGE?

ZRANGE returns members in ascending score order (lowest first), while ZREVRANGE returns them in descending order (highest first). Both accept a start and stop index (0-based) and support the WITHSCORES flag to include scores in the output. For a top-N leaderboard, use ZREVRANGE key 0 N-1 WITHSCORES.