Redis

Introduction

  • It is store the data temporarily and obtain the data quickly from the server-side, as the data is stored in ram instead of hard disk in key-value pair

  • Traditionally, obtain the data from database is slower, as it is required to scan the table, there will be a delay, apart from that, multiple requests to obtain the data from database is not an ideal case

  • Sometimes, we want the real-time data or do caching , we can make good use of redis to do it

Caching Strategy

Data Type

String

  • A string in Redis can be up to 512MB in size. Its operation is atomic to prevent from inconsistency when facing multiple access

List

Hash

  • Redis Hashes are perfect for representing objects. They are a collection of key-value pairs.

  • Redis Hashes are ideal for storing structured data, like an object with many fields.

Set

  • Redis Sets are an unordered collection of strings. They support a variety of commands that perform operations based on set theory

Sorted Set

  • Redis Sortedarrow-up-right Sets, or ZSets, are similar to Redis Sets with an unique feature

  • Each member of a Sorted Set is associated with a score. This score is used to sort the set members from the smallest to the largest score and and search the result based on the score. The members in a Sorted Set are unique, but the scores may be repeated.

  • Sorted Sets are particularly useful for tasks that require maintaining a list sorted by a score. For example, they can be used to maintain a leaderboard in online games

Mode

Master-Slave Replication

  • Include 1 master and multiple slaves

  • Write and read can be conducted at master

  • Slave is for read - only

  • After the update of master, master will send snapshot to slave for data sync

  • Master-slave mode requires manual intervention for failover. If the master node fails, a slave node must be promoted manually to become the new master, which can introduce some downtime and administrative overhead.

Cluster Mode

  • Sharding. Each node is responsible for their slot (part of data)

  • Enabling horizontal scaling

  • Redis Cluster mode provides built-in support for high availability and fault tolerance. It uses a distributed consensus algorithm and automatic failover to ensure data availability even in the event of node failures. If one node is down, others will take its slot to prevent from downtime

References

Last updated

Was this helpful?