Connecting: URLs, TLS, AUTH & Select
Connect to standalone, TLS, authenticated, or non-default DB indexes.
Code
# Basic connect (default localhost:6379)
redis-cli
# Explicit host/port, with DB index (0-15)
redis-cli -h redis.example.com -p 6380 -n 3
# URL form (preferred for config)
redis-cli redis://user:[email protected]:6379/0
rediss://user:[email protected]:6379/0 # rediss:// = TLS
# AUTH (Redis 6+ uses ACL users; legacy: single password)
redis-cli -a 'yourpassword' --no-auth-warning
redis-cli --user alice -a 'alicepass' --no-auth-warning
# TLS
redis-cli --tls --cert client.crt --key client.key --cacert ca.crt -h redis.example.com
# Inside an interactive session
> AUTH alice alicepass
> SELECT 3
> QUITExplanation
redis-cli defaults to 127.0.0.1:6379 with DB 0. Use -h/-p/-n for explicit target, or pass a redis:// (or rediss:// for TLS) URL. -a supplies a password but leaks it in process listings — prefer AUTH inside the session, or use REDISCLI_AUTH env var. In Redis 6+, ACL introduces named users (--user + -a). SELECT switches the logical DB (0-15 by default); transactions and keys are scoped per-DB. --tls with cert/key/cacert covers mTLS.
More Redis CLI Snippets
Interactive Mode, HELP & Inspecting
Navigate the REPL, discover commands, and introspect the server.
MULTI / EXEC / WATCH (Transactions)
Queue commands atomically and use optimistic locking with WATCH.
Pub/Sub: SUBSCRIBE, PUBLISH & PSUBSCRIBE
Fan-out messaging with channels and pattern subscriptions.
MONITOR, SLOWLOG & Latency Debugging
Watch every command in real time and find slow queries.
EVAL, Lua & Function Stats (Server-side Scripting)
Run atomic server-side Lua scripts; load and call functions.
RDB / AOF Persistence & Backup
Trigger snapshots, manage AOF rewrite, and capture a safe backup.