Redis Cheat Wheet

Here is a Redis cheat sheet that covers some common commands and operations. Redis is an in-memory data structure store, and these commands can be used in the Redis command-line interface (CLI) or through client libraries in various programming languages.

Key-Value Operations

  • SET key value [EX seconds] [PX milliseconds] [NX|XX]
    • Set the value of a key.
    • Optional parameters: expiration time, NX (only set if key does not exist), XX (only set if key exists).
  • GET key
    • Get the value of a key.
  • DEL key [key …]
    • Delete one or more keys.

Lists

  • LPUSH key value [value …]
    • Prepend one or multiple values to a list.
  • RPUSH key value [value …]
    • Append one or multiple values to a list.
  • LPOP key
    • Remove and get the first element in a list.
  • RPOP key
    • Remove and get the last element in a list.

Sets

  • SADD key member [member …]
    • Add one or more members to a set.
  • SMEMBERS key
    • Get all the members in a set.
  • SREM key member [member …]
    • Remove one or more members from a set.

Hashes

  • HSET key field value
    • Set the value of a field in a hash.
  • HGET key field
    • Get the value of a field in a hash.
  • HGETALL key
    • Get all fields and values in a hash.

Sorted Sets

  • ZADD key score member [score member …]
    • Add one or more members to a sorted set with scores.
  • ZRANGE key start stop [WITHSCORES]
    • Get a range of members from a sorted set.
  • ZREM key member [member …]
    • Remove one or more members from a sorted set.

Expiration

  • EXPIRE key seconds
    • Set a key’s time to live in seconds.
  • TTL key
    • Get the remaining time to live of a key.

Other Operations

  • PING
    • Check if the server is running.
  • INFO
    • Get information and statistics about the server.
  • FLUSHDB
    • Remove all keys from the current database.
  • QUIT
    • Close the connection to the server.

This cheat sheet provides a quick reference for some commonly used Redis commands. For more detailed information and advanced commands, you can refer to the official Redis documentation.