Databases 27 min read

Redis Guide: Installation, Configuration, Data Structures, Persistence, and Advanced Features

This comprehensive Redis guide explains the in‑memory key‑value store’s installation, basic commands, configuration options, supported data structures, persistence mechanisms, replication, transactions, pub/sub, performance testing, connection handling, pipelining, and partitioning, providing practical examples for developers.

Architecture Digest
Architecture Digest
Architecture Digest
Redis Guide: Installation, Configuration, Data Structures, Persistence, and Advanced Features

Redis is an open‑source, C‑implemented, in‑memory key‑value database that also offers persistence; it is widely used as a cache and for many other interesting applications. Understanding its inner workings is essential for effective use.

Installation : On macOS you can install Redis with brew install redis. After installation start the server with redis-server and you will see it listening on the default standalone mode on port 6379. The port number originates from the keypad sequence for the word “MERZ”.

Basic client commands can be issued via redis-cli. Common commands include: AUTH password – authenticate ECHO message – print a string PING – check server health (returns PONG) QUIT – close the connection SELECT index – switch database

Server status can be inspected with INFO, which reports memory usage, connected clients, and other metrics.

Configuration is stored in redis.conf. Important settings include: daemonize yes|no – run as a background daemon port 6379 – listening port bind 127.0.0.1 – network interface timeout 300 – client idle timeout loglevel verbose – logging level databases 16 – number of logical databases save 900 1, save 300 10, save 60 10000 – RDB snapshot conditions appendonly yes|no – enable AOF persistence maxmemory <bytes> – memory limit

Data structures supported by Redis are strings, lists, sets, sorted sets, and hashes. Keys should be neither too long nor too short, and a consistent naming scheme (e.g., user:10000:passwd) is recommended.

Strings behave like simple values; numeric operations automatically convert strings to numbers. Lists are implemented as linked lists, allowing O(1) push/pop at both ends; common commands are LPUSH, RPUSH, and LRANGE. Sets store unordered unique elements with commands for add, remove, and set algebra. Sorted sets associate each member with a score, enabling range queries via ZADD, ZRANGE, etc. Hashes are maps of field‑value pairs, useful for representing objects.

Redis also provides HyperLogLog for cardinality estimation, offering fixed‑size storage while approximating distinct element counts.

Persistence options:

RDB – snapshotting via SAVE or BGSAVE, creating a dump file ( dump.rdb) that can be restored by loading the file.

AOF – logs every write command; the file is rewritten periodically to keep it compact. The default policy fsyncs once per second, balancing durability and performance.

Both mechanisms can be used together for higher reliability.

Advanced features include:

Master‑slave replication : asynchronous replication using SYNC, BGSAVE, and incremental sync after the initial snapshot.

Transactions : MULTI, EXEC, DISCARD, and WATCH provide atomic execution and optimistic locking.

Publish/Subscribe : clients can SUBSCRIBE to channels and receive messages published with PUBLISH.

Connection & pipelining : Redis uses non‑blocking sockets with TCP_NODELAY and supports pipelining to batch commands for higher throughput.

Partitioning : data can be sharded across multiple instances using range or hash partitioning, improving scalability but introducing limitations on multi‑key operations.

Performance testing can be performed with the built‑in redis-benchmark tool to evaluate throughput and latency under various workloads.

Overall, Redis offers a versatile platform for caching, real‑time analytics, messaging, and many other use cases, with a rich set of commands and configuration knobs to tailor its behavior to specific requirements.

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.

ReplicationData StructuresIn-Memory Databasepub/sub
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

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.