Distributed lock: when multiple servers handle the same work (such as a scheduled job), use it to decide “who runs”.
Counter: likes, view counts, rate-limit tallies. The INCR command is atomic (safe under concurrency) — see Rate limiting.
Session: keep login state in Redis so any server that receives the user can recognize them.
How to do it
Persistence: does data survive a restart?
Mode
Plain-language
Trade-off
RDB snapshot
Take a full photo every so often
Fast restore, but you may lose the last few minutes
AOF log
Record every write
Loses less; files grow larger
Neither
Pure cache
Empty after restart; only for rebuildable data
Eviction: what happens when memory is full?
Memory is finite. Cap it with maxmemory, then pick a policy with maxmemory-policy. For pure cache, allkeys-lru (evict least recently used) is common. If the instance holds data you must not drop (locks, sessions), avoid policies that evict arbitrarily, and split cache from important data onto separate deployments.
🔀 Distributed lock: two workers race for the same job
Worker 1
Redis
Worker 2
1Acquire: set only if missing, expire in 30s
2Success
3Acquire
4Fail: lock already held
5Finish work; release only if still own the lock
6On crash, auto-expire after 30s
Component comparison
Self-hosted Redis
Self-hosted open sourceOpen sourceOpsMedium
Install Redis yourself on a server or in a container: a fast in-memory "small warehouse" commonly used for caching, sessions and counters.
Best forProjects with server ops capability that want to control cost and configuration themselves.
Avoid whenNobody on the team can maintain it, or you need high availability but cannot build a cluster yourself.
Pros
Extremely fast reads and writes with rich features (caching, counters, leaderboards, queues, locks)
The largest community, with the most complete documentation and clients
Fully under your control, with no extra cloud service fees
Cons
Data lives in memory; the more memory, the pricier the server, and exceeding the limit triggers eviction or errors
Primary-replica failover, persistence configuration and backups are your responsibility
Exposing it to the public internet without a password gets it compromised, a very common incident
An open-source fork of Redis: after Redis changed its license, the community and several companies maintain it based on the original code, and usage is basically the same as Redis.
Best forProjects that want Redis-style usage but a purely open-source license.
Avoid whenYou depend on certain Redis-proprietary new features or commercial modules.
Pros
Usage is largely compatible with Redis, and most existing clients can connect directly
Uses a permissive open-source license, with no commercial licensing concerns
Increasingly offered by major cloud providers and Linux distributions
Cons
Newer than Redis, and new features may gradually diverge from Redis, so check each one's docs for details
Some Redis modules and add-on features may not be fully compatible
Tutorials and troubleshooting experience in China are still mostly about Redis