Redis CLI Cheat Sheet

Below is a Redis CLI cheat sheet covering some common commands for interacting with Redis from the command line:

Connecting to Redis

Connect to Redis Server:

redis-cli

Connect to Redis Server with Host and Port:

redis-cli -h host -p port

Key-Value Operations

Set Key-Value:

SET key value

Get Value by Key:

GET key

Delete Key:

DEL key

Strings

Increment a Number:

INCR key

Append to a String:

APPEND key value

Lists

Push Element to List (Left):

LPUSH key value

Push Element to List (Right):

RPUSH key value

Pop Element from List (Left):

LPOP key

Pop Element from List (Right):

RPOP key

Sets

Add Element to Set:

SADD key member

Get Set Members:

SMEMBERS key

Hashes

Set Hash Field:

HSET key field value

Get Hash Field Value:

HGET key field

Get All Hash Fields:

HGETALL key

Sorted Sets

Add Element to Sorted Set:

ZADD key score member

Get Range from Sorted Set:

ZRANGE key start stop

Expiration

Set Key Expiration (Seconds):

EXPIRE key seconds

Check Time to Live (TTL) of Key:

TTL key

Persistence

Save to Disk (Blocking):

SAVE

Asynchronous Save to Disk:

BGSAVE

Server

Get Server Info:

INFO

Client List:

CLIENT LIST

Configuration

Get Configuration Parameter:

CONFIG GET parameter

Set Configuration Parameter:

CONFIG SET parameter value

This cheat sheet provides a quick reference for common Redis CLI commands. Always refer to the official Redis documentation for more detailed information and additional commands.