0% found this document useful (0 votes)
11 views7 pages

Redis

Redis is an open-source in-memory data structure server that functions as a NoSQL key/value store, supporting various data types such as strings, lists, and sets. It offers high performance, persistence options, and features like high availability through Redis Sentinel and Cluster, as well as pub/sub messaging and Lua scripting. Redis is widely used for caching, session management, real-time messaging, and managing geospatial data.

Uploaded by

lknvkllw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

Redis

Redis is an open-source in-memory data structure server that functions as a NoSQL key/value store, supporting various data types such as strings, lists, and sets. It offers high performance, persistence options, and features like high availability through Redis Sentinel and Cluster, as well as pub/sub messaging and Lua scripting. Redis is widely used for caching, session management, real-time messaging, and managing geospatial data.

Uploaded by

lknvkllw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

REDIS

Redis is an open source data structure server. It belongs to the class of


NoSQL databases known as key/value stores. Keys are unique identifiers,
whose value can be one of the data types that Redis supports. These data
types range from simple Strings, to Linked Lists, Sets and even Streams.
Each data type has its own set of behaviors and commands associated with
it.
Features of Redis
In-Memory Design:
●​ Data resides in RAM, enabling extremely fast read and write
operations. This makes Redis ideal for caching frequently accessed
data, real-time applications, and leaderboards.
Rich Data Structures:
●​ Redis goes beyond simple key-value pairs and offers various data
structures like:
○​ Strings: For storing text or binary data.
○​ Hashes: For associating keys with multiple fields and values (like
user profiles).
○​ Lists: Ordered collections of elements, useful for queues, stacks,
or task lists.
○​ Sets: Unordered collections of unique elements, good for
deduplication or membership checks.
○​ Sorted Sets: Ordered sets with scores, ideal for leaderboards or
prioritized task queues.
○​ Geospatial Indexes: Efficient storage and retrieval of geospatial
data for location-based applications.
○​ Streams: Efficient data structures for real-time data feeds and
message queues.
●​ This variety allows you to model different types of data and perform
complex operations efficiently.
High Performance:
●​ In-memory storage and optimized data structures translate to
blazing-fast performance. Redis can handle millions of requests per
second, making it suitable for demanding applications.
Persistence Options:
●​ While data resides in memory, Redis offers persistence options to
avoid data loss after restarts:
○​ RDB (Snapshotting): Creates periodic snapshots of the dataset
on disk for recovery.
○​ AOF (Append-Only File): Logs every write operation to a file,
allowing reconstruction of the dataset in case of failure.
●​ You can choose the persistence strategy that best suits your needs,
balancing speed with data durability.
High Availability:
●​ Redis Sentinel and Redis Cluster provide high availability options:
○​ Sentinel: Monitors multiple Redis instances, automatically
promoting a replica to primary if the master fails.
○​ Cluster: Distributes data across multiple nodes for horizontal
scaling and fault tolerance.
Pub/Sub Messaging:
●​ Redis supports publish-subscribe messaging, enabling real-time
communication between applications. Publishers send messages to
channels, and subscribers receive messages they're interested in. This
is useful for broadcasting updates, notifications, or chat applications.
Lua Scripting:
●​ Redis allows you to execute Lua scripts within the server. This enables
custom data processing logic and complex data manipulation at the
server-side.
Ease of Use:
●​ Redis has a simple and intuitive API, making it easy to learn and
integrate with various programming languages. It also offers a
web-based admin interface for monitoring and management.
Use Cases:
●​ Caching: Store frequently accessed data to reduce database load and
improve application responsiveness.
●​ Session Management: Store user session data for web applications.
●​ Real-time Messaging: Implement chat applications, leaderboards, or
live feeds.
●​ Task Queues: Manage background tasks efficiently.
●​ Geospatial Data: Store and retrieve location-based data for mapping
applications.
●​ Leaderboards: Implement competitive ranking systems.
What is Redis Stack?
In Redis, a "stack" typically refers to using a list data structure to simulate
the Last-In-First-Out (LIFO) behavior. Elements are added and removed from
one end, following stack principles. This is often achieved using list
commands like LPUSH (push to the left) and LPOP (pop from the left).
The Last-In-First-Out (LIFO) principle states that the last element added is
always the first one to be withdrawn from a stack. Redis lists let you do
operations like push (adding an element to the left end), pop (removing and
obtaining an element from the left end), and more.

Architecture of Redis
The Redis architecture comprises two primary components: the Redis client
and the Redis server. You can install both the Redis server and client either
on a single machine or on separate devices. Multiple clients can concurrently
connect to a shared server, facilitating the handling of various requests.
Servers bear the responsibility of housing data within memory, subsequently
overseeing all control aspects crucial to the architecture. As such, the Redis
server constitutes a highly significant facet of this structure.
Conversely, a Redis client essentially serves as a Redis console integrated
with a programming language tailored for the Redis API. In this setup, Redis
retains all data within primary memory. However, it's essential to note that
Redis's primary memory is impermanent; hence, restarting the server can
lead to data loss.
Redis provides compatibility with the subsequent storage platforms:
The subsequent illustration delineates two segments: the client side and the
server side.
1.​ AOF - primarily, enables data preservation by recording all write
operations received from the server.
2.​ Save the command – Significantly, the "SAVE" command compels the
Redis server to generate RDB snapshots on demand.
3.​ RDB - entails duplicating all data from memory and storing it in
persistent storage at predefined intervals.
4.​ Replication is additionally provided to enhance fault tolerance and
ensure data availability. Furthermore, you have the option to augment
storage capacity by grouping two or more servers within a designated
cluster.
The Redis architecture encompasses the following deployments:
1. Single Redis Instance
This represents the simplest way to deploy Redis. It requires users to
configure and operate small instances that facilitate the expansion and
acceleration of their services.'
Nevertheless, it comes with a disadvantage: if this active instance were to
crash or become inaccessible, any requests directed towards Redis would be
unsuccessful. As a result, there would be a decline in the overall system
performance and speed.
2. Redis High Availability (HA)
An alternative widely used arrangement involves a primary deployment
alongside a secondary deployment that consistently mirrors the replication
process.
These secondary instances encompass one or multiple units within our
deployment, facilitating the expansion of read capabilities from Redis.
Furthermore, they offer a failover mechanism in scenarios where the
primary instance becomes inaccessible.
High availability (HA) ensures consistent performance and uptime beyond
the ordinary. Such systems avoid single points of failure, allowing smooth
transitions between primary and secondary components without data loss,
and feature automated failure detection and recovery.

In this topology, various novel factors come into play as we step into a
distributed system realm laden with multiple fallacies that demand
attention. What was once simple now gains intricacy.
Redis Replication
In Redis, each main instance possesses a replication ID and an offset, crucial
for pinpointing a replication instance's progress and enabling sync decisions.
The offset increments with main instance actions.
When a replica is slightly behind the main instance, it catches up by
replaying commands, achieving sync. Mismatched IDs or unknown offsets
prompt full synchronization, where the main instance sends a snapshot to
the replica. Replication resumes once the sync is complete.
Matching ID and offset mean identical data. A replication ID helps infer past
primaries for partial sync after a restart or promotion. Similar IDs and
slightly differing offsets indicate matching datasets. Dissimilar IDs require
full sync unless common ancestry helps perform partial sync based on
previous replication ID knowledge.
3. Redis Sentinel
Sentinel represents a distributed system configuration. It's structured to
encompass a cluster of sentinel processes collaborating to coordinate the
system's state, ensuring uninterrupted accessibility of the Redis system. In
addition to caching, Redis Sentinel offers several other functionalities.

●​ Monitoring: Scrutinizing all instances, including both master and slave,


to ensure proper functionality.
●​ Notification: In case any Redis instance deviates from expected
behavior, Sentinel can alert system administrators or external
programs via an API.
●​ Automatic failover: If the master doesn't function as anticipated,
Sentinel elevates a slave to the master position and redirects
additional slaves to the new master.
Sentinel serves as the primary reference for clients. Clients connect to
Sentinel to obtain information about the present Redis master's location.
4. Redis Cluster
The Redis cluster stands as the definitive architecture within Redis, enabling
the horizontal expansion of its capabilities.
Within the Redis cluster framework, we opt to distribute the data we store
across numerous machines, a technique referred to as sharding. As a result,
each Redis instance present in the cluster is regarded as a shard
encompassing a portion of the complete dataset.

Algorithmic sharding is the approach employed by the Redis Cluster. When


determining the shard associated with a specific key, the key undergoes a
hashing process, followed by modulo division against the total number of
shards.

Refer To run Redis


https://medium.com/redis-with-raphael-de-lio/how-to-run-redis-locally-in-a
-docker-container-and-manage-it-with-redis-insight-and-redis-cli-14b0af54e
1d2

You might also like