Research about Memory

Here is some research about Redis.

1. Deploy Redis

  • Deploy Redis using the Linux operating system

2. Redis Sentinel

Redis sentinel

2.1. Redis Senitel

A Sentinel is a special Redis process that:

  • monitors Redis servers,
  • detects failures,
  • performs failover,
  • informs clients about topology changes.

Sentinel does not store application data.

Its job is management and monitoring.

2.2. Master

The master Redis server:

  • accepts write operations,
  • stores the main data,
  • replicates data to replicas.

Example: SET user:1 “Alice”

This write goes to the master.

2.3. Replica (slave)

A replica is a copy of the master.

It:

  • receives replicated data from master,
  • usually handles read requests,
  • can become new master during failover.

Example architecture:

        Master
       /      \
  Replica1   Replica2

2.4. Client

A client is the application using Redis.

Examples:

  • Java application,
  • Node.js backend,
  • Python service.

The client can:

  • connect directly to Redis,
  • or ask Sentinel for the current master address.

Example flow:

Client → Sentinel → “Who is master?” Client → Current

2.5. What is feature of Redis Sentinel

It mainly provides 4 functions:

  1. Monitoring
  • Watches Redis master and replica instances.

  • Detects whether they are alive and healthy.

  1. Notification
  • Sends alerts/events when something changes.

  • Example: master goes down, replica disconnects, failover completed.

  1. Automatic Failover
  • If the master fails, Sentinel automatically:
    • selects a replica,
    • promotes it to become the new master,
    • reconfigures other replicas.
  1. Configuration Provider
  • Clients can ask Sentinel: “Who is the current master?”

  • Useful because master may change after failover.

2.6. What is quorum ?

  • A quorum is the minimum number of Sentinel nodes that must agree that a master is down before failover can start.

Example: sentinel monitor mymaster 192.168.1.10 6379 2

Here:

  • 2 = quorum (đại biểu)

  • At least 2 Sentinels must agree that the master is unreachable.

2.7. Important Notes

  • Recommended Sentinel deployment:
    • at least 3 Sentinels
  • Sentinel uses distributed voting

  • Replicas improve:
    • availability
    • read scalability
    • disaster recovery
  • Sentinel is different from:
    • Redis Cluster
    • replication itself
  • Sentinel focuses on: High Availability (HA)

3. Redis Cluster

Redis Cluster

3.1. Master Nodes

Master nodes:

  • store actual data,
  • handle read/write requests,
  • own a subset of hash slots.

Examples:

Master 1 -> slots 0 - 5460 Master 2 -> slots 5461 - 10922 Master 3 -> slots 10923 - 16383

3.2. Replica Nodes

Replica nodes:

  • copy data from masters,
  • provide backup,
  • can replace failed masters.

If a master crashes:

Replica -> promoted to Master

4. Compare with Redis Senitel and Redis Cluster

  • Redis Senitel: HA.

  • Redis Cluster: sharding.

5. Persistence

Persistence refers to the writing of data to durable storage, such as a solid-state disk (SSD)

  • RDB (Redis Database): RDB persistence performs point-in-time snapshots of your dataset at specified intervals.

    • For instance you may want to archive your RDB files every hour for the latest 24 hours, and to save an RDB snapshot every day for 30 days.
  • AOF (Append Only File): AOF persistence logs every write operation received by the server.

  • No persistence: You can disable persistence completely. This is sometimes used when caching.

  • RDB + AOF: You can also combine both AOF and RDB in the same instance.

6. Replications

  • 1 master = N replicas

  • asynchronous replica: master-slave.

  • Read-only replicas

7. Security

7.1. ACL

7.2. TLS

8. Optimization

8.1. Benchmark

SET: 180180.17 requests per second, p50=0.143 msec

LPUSH: 188323.91 requests per second, p50=0.135 msec

8.2. CPU Profilling

8.3. Latency diagnosis

  • Explain the query patterns.

8.4. Latency monitoring

8.5. Memory Optimization

June 20, 2026