Database cheatsheet
Redis 8 Cheatsheet
redis-cli and core commands for keys, data structures and server administration.
Connecting
- Open the CLI — Connect to a local server on the default port.
- Connect to a remote server — Connect with a user, prompting for the password so it stays out of shell history.
- Test the connection — Check that the server is reachable. It replies PONG.
- Switch database — Select numbered database 1.
- Show server information — Show version, uptime and other details. Use sections such as INFO memory.
Keys and strings
- Set a value — Store a string value under a key, replacing any existing value.
- Get a value — Read a string value. Returns nil if the key does not exist.
- Set a value that expires — Store a value that is deleted after 3600 seconds.
- Set only if the key does not exist — Useful as a simple lock. Returns nil if the key exists.
- Delete a key — Remove a key and its value. Returns the number of keys deleted.
- Check if a key exists — Returns 1 if the key exists, 0 if not.
- Check time to live — Seconds until expiry, -1 for no expiry, -2 if the key does not exist.
- Set an expiry — Make an existing key expire after 60 seconds.
- Increment a counter — Atomically add 1 to a numeric value, creating it at 0 if missing.
- Find keys by pattern — Iterate over keys without blocking the server.
- Check a key's type — Show whether a key holds a string, list, hash and so on.
Hashes, lists, sets and sorted sets
- Set hash fields — Store several fields on one key.
- Get all hash fields — Return every field and value.
- Add to a list — Push an item onto the head of a list.
- Take from a list — Pop an item from the tail, which gives first-in first-out with LPUSH.
- Read a list — Return every item in the list. 0 -1 means from the first item to the last.
- Add to a set — Add members to a set. Duplicates are ignored.
- List a set's members — Return every member of a set, in no particular order.
- Add to a sorted set — Add a member with a score.
- Read the top of a sorted set — Return the 10 highest scores, highest first.
Administration
- Count keys — Number of keys in the current database.
- Check memory use — Show memory statistics such as used_memory and the maxmemory limit.
- Check one key's size — Show how many bytes a key and its value use.
- See slow commands — Show the 10 most recent slow commands.
- List connected clients — Show each connection and what it last ran.
- Read a setting — Show the current maxmemory setting.
- Save a snapshot — Write the dataset to disk in the background.
- Delete every key in the database — Remove all keys from the current database.
- Watch every command — Stream all commands the server receives.
Related cheatsheets
- DuckDB 2 cheatsheet — Query CSV, Parquet and DataFrames with SQL from Python or the duckdb command line, without running a server.
- Elasticsearch 9 cheatsheet — curl requests for indexes, documents, searches, bulk loads and cluster health. Security is on by default, so the examples authenticate.
- MongoDB 8 cheatsheet — mongosh shell commands for documents, queries, aggregation, indexes, backups and administration.
- MySQL 8.4 cheatsheet — mysql client, backup and maintenance commands for MySQL 8.4.
- PostgreSQL 18 cheatsheet — psql, backup and maintenance commands for PostgreSQL 18.
- SQLite 3 cheatsheet — sqlite3 shell dot-commands, pragmas, import and export, and the SQL you use most.