Databases 38 min read

Comprehensive Guide to Redis: Data Structures, Commands, Persistence, Performance Tuning, and Deployment

This article provides a thorough overview of Redis, covering its core data structures, common commands, persistence options, memory management, pipelining, transactions, performance optimization, replication, clustering, and Java client choices for developers and architects.

Architect
Architect
Architect
Comprehensive Guide to Redis: Data Structures, Commands, Persistence, Performance Tuning, and Deployment

Overview

Redis is an open‑source, in‑memory, structured data store that can be used as a database, cache or message broker. It supports strings, hashes, lists, sets, sorted sets, bitmaps and HyperLogLog, provides LRU eviction, transactions, scripting, high‑availability via replication, Sentinel and Cluster.

Data Structures and Common Commands

Key

Any binary sequence can be used as a key; keep keys reasonably short and readable, e.g., “user:1000”. Maximum key size is 512 MB.

String

Basic type; commands include SET, GET, GETSET, MSET, MSETNX, MGET, INCR, INCRBY, DECR, DECRBY. Strings can store numeric values for atomic counters.

SET inv:remain "100"
DECR inv:remain

List

Linked‑list structure; commands LPUSH, RPUSH, LPOP, RPOP, LLEN, LRANGE, etc. Use for queues, avoid O(N) operations on large lists.

Hash

Field‑value map similar to a hashmap; commands HSET, HGET, HMSET, HMGET, HSETNX, HEXISTS, HDEL, HINCRBY. Prefer for object‑like data.

Set

Unordered collection of unique strings; commands SADD, SREM, SRANDMEMBER, SPOP, SCARD, SISMEMBER, SMOVE. Use SCAN for large sets.

Sorted Set

Ordered set with a score; commands ZADD, ZREM, ZRANGE, ZRANK, ZINCRBY, etc. Ideal for ranking.

Bitmap & HyperLogLog

Bitmap uses a string as a bit array for boolean flags; HyperLogLog provides cardinality estimation with low memory.

Other Common Commands

EXISTS, DEL, EXPIRE/PEXPIRE, TTL/PTTL, RENAME/RENAMENX, TYPE, CONFIG GET/SET/REWRITE.

Persistence

RDB

Snapshotting to disk; minimal performance impact, fast recovery, but may lose recent writes. Configured with save directives and triggered by BGSAVE.

AOF

Append‑only log of every write; can be configured with appendonly yes and appendfsync policies (always, everysec, no). Supports rewrite to compact the log.

Memory Management & Eviction

Set maxmemory to limit usage; choose an eviction policy such as volatile‑lru (default) or allkeys‑lru. Proper key design and monitoring are essential.

Pipelining

Batch multiple commands in a single round‑trip to reduce latency. Example:

$ (printf "PING
PING
PING
" ; sleep 1) | nc localhost 6379
+PONG
+PONG
+PONG

Transactions & Scripting

Use MULTI/EXEC for atomic command groups; WATCH provides optimistic locking (CAS). Lua scripting via EVAL/EVALSHA offers more flexibility and can replace transactions.

Performance Tuning

Avoid long‑running O(N) commands, use pipelining, disable Transparent Huge Pages, prefer physical machines, monitor Slow Log, and tune persistence settings.

Replication & Cluster

Master‑slave replication enables read‑write separation and high availability with Sentinel. Redis Cluster adds automatic sharding (16384 hash slots), failover, and scaling, but imposes restrictions on multi‑key operations.

Redis Java Clients

Jedis: lightweight, supports pooling, pipelining, transactions, Sentinel, Cluster. Redisson: Netty‑based, asynchronous, supports pipelining, scripting, Sentinel, Cluster, read‑write splitting, and provides additional utilities such as distributed locks.

Conclusion

The article targets developers and architects who need a practical understanding of Redis fundamentals, advanced features, and operational best practices.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

redisperformance tuningPersistenceClusterData StructuresIn-Memory Database
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.