Developer

Redis Guide

Install Redis, learn core data types, and copy common Redis CLI commands.

TypeCommandExplanation
Connectionredis-cliConnect to a local Redis server.
Connectionredis-cli -h 127.0.0.1 -p 6379 -a passwordConnect to a Redis server with host, port, and password.
ServerPINGCheck whether Redis is responding.
StringSET user:1:name "Ada"Set a string value.
StringGET user:1:nameRead a string value.
StringSET session:abc "value" EX 3600Set a value with expiration in seconds.
StringINCR counter:visitsIncrement an integer value.
KeyEXISTS user:1:nameCheck whether a key exists.
KeyDEL user:1:nameDelete one or more keys.
KeyTTL session:abcShow remaining expiration time.
HashHSET user:1 email ada@example.com age 36Set fields on a hash.
HashHGETALL user:1Read all fields from a hash.
ListLPUSH queue:emails job-1Push an item to the left of a list.
ListRPOP queue:emailsPop an item from the right of a list.
SetSADD tags:post:1 redis cache databaseAdd unique values to a set.
SetSMEMBERS tags:post:1Read all set members.
Sorted SetZADD leaderboard 100 user:1 90 user:2Add scored members.
Sorted SetZREVRANGE leaderboard 0 9 WITHSCORESRead top scores.
Pub/SubPUBLISH events:user.created "1"Publish a message to a channel.
Pub/SubSUBSCRIBE events:user.createdSubscribe to a channel.
StreamXADD orders * user_id 1 total 39.99Append an entry to a stream.
StreamXRANGE orders - + COUNT 10Read stream entries.
AdminINFOShow server metrics and configuration summary.
AdminFLUSHDBDelete all keys from the current database. Use carefully.

Concepts

Common Redis data types

TypeUse caseExamples
StringCache values, counters, feature flags, sessions.SET, GET, INCR, MGET
HashObject-like field storage.HSET, HGET, HGETALL
ListQueues and ordered collections.LPUSH, RPOP, LRANGE
SetUnique unordered values.SADD, SMEMBERS, SINTER
Sorted SetLeaderboards and ranked data.ZADD, ZRANGE, ZREVRANGE
StreamAppend-only event streams.XADD, XRANGE, XREAD

FAQ

Questions people ask

What is Redis used for?

Redis is commonly used for caching, sessions, queues, rate limiting, pub/sub, leaderboards, and fast in-memory data structures.

Is Redis a database or a cache?

Redis can be used as a cache, message broker, or primary data store depending on persistence and architecture choices.

How should I avoid deleting data accidentally?

Be careful with FLUSHDB, FLUSHALL, and broad key deletion patterns. Prefer explicit keys and use separate databases or instances for environments.

Related tools

Continue working