Redis Commands Cheat Sheet
A searchable reference of common Redis commands and what each one does.
| Command | What it does |
|---|---|
DEL <key> | Delete one or more keys and their values. |
EXISTS <key> | Return how many of the given keys currently exist. |
EXPIRE <key> <seconds> | Set a timeout in seconds after which the key is deleted. |
TTL <key> | Return the remaining time to live of a key in seconds. |
PERSIST <key> | Remove the expiry from a key so it stops being volatile. |
KEYS <pattern> | Return all keys matching a glob pattern (avoid on large production databases). |
SCAN <cursor> | Iterate over keys in batches using a cursor, safe for large databases. |
RENAME <key> <newkey> | Rename a key, overwriting the destination if it already exists. |
TYPE <key> | Return the data type stored at a key, such as string or hash. |
RANDOMKEY | Return a random key name from the current database. |
SET <key> <value> | Set a key to hold a string value, creating or overwriting it. |
GET <key> | Get the string value stored at a key. |
INCR <key> | Increment the integer value of a key by one, starting from zero if unset. |
DECR <key> | Decrement the integer value of a key by one. |
INCRBY <key> <n> | Increment the integer value of a key by a given amount. |
APPEND <key> <value> | Append a string to the value of a key and return the new length. |
GETSET <key> <value> | Set a new value and return the old value in one step. |
SETEX <key> <seconds> <value> | Set a key to a value that expires after the given number of seconds. |
SETNX <key> <value> | Set a key only if it does not already exist. |
MSET <key> <value> ... | Set several keys to several values in a single command. |
MGET <key> ... | Get the values of several keys at once. |
STRLEN <key> | Return the length in bytes of the string value at a key. |
HSET <key> <field> <value> | Set one or more field-value pairs on a hash. |
HGET <key> <field> | Get the value of a single field in a hash. |
HGETALL <key> | Return every field and value stored in a hash. |
HDEL <key> <field> | Delete one or more fields from a hash. |
HEXISTS <key> <field> | Return whether a field exists in a hash. |
HKEYS <key> | Return all field names in a hash. |
HVALS <key> | Return all values in a hash. |
HINCRBY <key> <field> <n> | Increment the integer value of a hash field by a given amount. |
HMGET <key> <field> ... | Get the values of several hash fields at once. |
HLEN <key> | Return the number of fields in a hash. |
LPUSH <key> <value> | Prepend one or more values to the head of a list. |
RPUSH <key> <value> | Append one or more values to the tail of a list. |
LPOP <key> | Remove and return the first element of a list. |
RPOP <key> | Remove and return the last element of a list. |
LRANGE <key> <start> <stop> | Return a range of elements from a list by index. |
LLEN <key> | Return the number of elements in a list. |
LINDEX <key> <index> | Return the list element at a given index. |
LREM <key> <count> <value> | Remove elements equal to a value from a list. |
LSET <key> <index> <value> | Set the list element at a given index to a new value. |
BLPOP <key> <timeout> | Pop the first element of a list, blocking until one is available or the timeout passes. |
SADD <key> <member> | Add one or more members to a set, ignoring ones already present. |
SREM <key> <member> | Remove one or more members from a set. |
SMEMBERS <key> | Return every member of a set. |
SISMEMBER <key> <member> | Return whether a value is a member of a set. |
SCARD <key> | Return the number of members in a set. |
SINTER <key> ... | Return the members common to all the given sets. |
SUNION <key> ... | Return the union of all the given sets. |
ZADD <key> <score> <member> | Add a member to a sorted set with a score, or update its score. |
ZRANGE <key> <start> <stop> | Return a range of sorted-set members ordered by score. |
ZRANK <key> <member> | Return the zero-based rank of a member ordered by ascending score. |
ZSCORE <key> <member> | Return the score of a member in a sorted set. |
ZINCRBY <key> <n> <member> | Increment the score of a sorted-set member by a given amount. |
FLUSHDB | Delete every key in the current database (destructive). |
FLUSHALL | Delete every key in every database on the server (destructive). |
DBSIZE | Return the number of keys in the current database. |
INFO | Return server statistics and configuration details. |
CONFIG GET <parameter> | Read the value of a runtime configuration parameter. |
SELECT <index> | Switch the connection to another numbered database. |
PING | Check that the server is responsive; it replies with PONG. |
SUBSCRIBE <channel> | Listen for messages published to one or more channels. |
PUBLISH <channel> <message> | Send a message to every subscriber of a channel. |
MULTI | Begin a transaction so the following commands are queued. |
EXEC | Run all commands queued since MULTI as a single atomic transaction. |
No commands match your search.
Runs entirely in your browser. Nothing you type is sent anywhere; open DevTools and watch the Network tab to verify zero requests.
What this tool does
This is a searchable quick reference for the Redis commands you reach for every day, grouped by data type and by server task. It covers key management, strings and counters, hashes, lists, sets and sorted sets, and the server, transaction, and pub/sub commands. Each row pairs the exact command with a plain-English note on what it does. Type in the filter box to search across both columns, or tap a category button to focus on one group. The whole list is built into the page, so it works offline and sends nothing anywhere.
How to use it
Start typing in the Filter box. Entering expire surfaces the
commands that control key lifetime; entering hset jumps to the hash commands;
entering zadd brings up sorted sets. The category buttons
(Keys, Strings, Hashes, Lists, Sets and sorted, Server and pubsub) narrow the table to one
group and combine with the text filter, so you can pick Lists and type pop to
compare LPOP, RPOP, and BLPOP. Clear the box to see
the full sheet again.
Common use cases
- Recalling the exact argument order for a command you use rarely, like
ZADDorSETEX. - Choosing the right data type for a task, such as a hash for a record or a sorted set for a leaderboard.
- Copying a safe command into
redis-cliinstead of guessing the syntax. - Finding a non-blocking option, such as
SCANin place ofKEYSon a busy server. - Reviewing the core Redis commands before an interview or a new project.
Common pitfalls
- Running KEYS in production.
KEYSscans the whole keyspace and can block the server on a large database. UseSCANwith a cursor to iterate in small batches instead. - Flushing the wrong scope.
FLUSHDBclears the current database whileFLUSHALLwipes every database on the server. Both are destructive and cannot be undone, so double-check which one you mean. - Losing an expiry on overwrite. Writing a new value with plain
SETremoves any timeout set byEXPIRE. UseSETEXor reapplyEXPIREif the key still needs to expire. - Assuming a key type. Calling a hash command on a key that holds a string
returns an error. Check the stored type with
TYPEwhen a command fails unexpectedly.
Frequently asked questions
- What is Redis?
- Redis is an in-memory data store that keeps its data in RAM for very fast reads and writes. It is often used as a cache, a session store, a message broker, and a lightweight database. Because it holds structured types like strings, hashes, lists, sets, and sorted sets, it can model many problems with simple commands instead of tables and joins.
- What is the difference between a string and a hash?
- A string holds a single value under one key, such as a counter, a token, or a serialized blob. A hash stores many field-value pairs under one key, so it works like a small dictionary or record, for example a user with fields for name and email. Reach for a hash when several related values belong together, and a string when you only need one value.
- How does EXPIRE work?
- EXPIRE sets a timeout in seconds on an existing key, and Redis deletes the key automatically once that time passes. You can check the remaining time with TTL and cancel the timeout with PERSIST. Writing a fresh value with plain SET clears any existing expiry, while SETEX sets the value and the timeout together in one command.
- What are sorted sets for?
- A sorted set stores unique members, each attached to a numeric score, and keeps them ordered by that score. This makes it ideal for leaderboards, priority queues, rate limiters, and time-ordered feeds, where you constantly need the top or bottom entries. Commands like ZADD, ZRANGE, and ZRANK let you add members and read ranges by rank or score efficiently.
- How do I delete all keys?
- Use FLUSHDB to remove every key in the current database, or FLUSHALL to wipe every database on the server. Both are destructive and cannot be undone, so avoid them on production data. To clear only a subset, iterate with SCAN and delete matching keys with DEL rather than running KEYS on a large database.
- What does SCAN do that KEYS does not?
- KEYS returns every matching key in one shot, which can block the server on a large database. SCAN instead walks the keyspace in small batches using a cursor you pass back on each call, so it never blocks for long. Prefer SCAN in production and keep KEYS for quick checks on small or local databases.
- Does this cheat sheet send my searches anywhere?
- No. The full command list is baked into the page, and every search and filter runs locally in your browser with JavaScript. Nothing you type is sent to any server. Open your browser DevTools and watch the Network tab while you search to confirm there are zero requests.
Cite this tool
For academic, journalistic, or technical references. Pick a format:
Citations use 2026 as the publication year. Access date is left as a fillable placeholder where the citation style expects one.