Connect to Redis
redis-cli
Connect to remote Redis
redis-cli -h hostname -p 6379
Connect with password
redis-cli -a password
Authenticate after connecting
AUTH password
Ping server
PING
Set key-value
SET mykey "Hello"
Get value
GET mykey
Check if key exists
EXISTS mykey
Delete key
DEL mykey
Set with expiration (seconds)
SETEX mykey 60 "expires in 60s"
Set if not exists
SETNX mykey "value"
Get and set
GETSET mykey "new value"
Increment number
INCR counter
Increment by amount
INCRBY counter 10
Decrement
DECR counter
Get all keys
KEYS *
Get keys matching pattern
KEYS user:*
Set expiration (seconds)
EXPIRE mykey 300
Check time to live
TTL mykey
Remove expiration
PERSIST mykey
List operations
LPUSH mylist "item1"
RPUSH mylist "item2"
LRANGE mylist 0 -1
LPOP mylist
Set operations
SADD myset "member1"
SMEMBERS myset
SISMEMBER myset "member1"
Hash operations
HSET user:1 name "John"
HGET user:1 name
HGETALL user:1
HDEL user:1 name
Sorted set operations
ZADD leaderboard 100 "player1"
ZRANGE leaderboard 0 -1 WITHSCORES
Get database size
DBSIZE
Flush current database
FLUSHDB
Flush all databases
FLUSHALL
Get server info
INFO
Monitor commands
MONITOR
Get config
CONFIG GET maxmemory