§ Redis is an in-memory data store.
§ It is used as a No SQL key-value database for
different purposes.
§ Redis primarily stores data in RAM, which
enables extremely fast access to information.
This makes it ideal for applications that
require low latency, such as caching systems,
real-time applications, and real-time
analytics.
§ Although Redis is an in-memory database, it
offers persistence options such as RDB
(Redis Database File), which periodically
takes snapshots of the database, and AOF
(Append-Only File), which logs every
operation received by the server, allowing
data recovery in case of failures.

Redis is used as a cache in front of
another "real" database like MySQL
or PostgreSQL to help improve
application performance.
§ Its operation is very similar to the
cache memory of a personal computer
or laptop.
§ It leverages the speed of memory and
alleviates the load on the central
application database.

Redis Write:
1. Check the cache for the key.
2a. If the key is present in the
cache (cache hit), update the
value if necessary.
2b. If the key is not in the cache
(cache miss), insert the data in
the cache
3. Insert or update the data in
the persistent database
(MySqL, Postgres, etc)

§ Redis Read:
1. Check the cache for the
key.
2a. If the key is present in the
cache (cache hit), return the
value.
2b. If the key is not in the
cache (cache miss), retrieve the
data from the persistent
database.
3. Return the data and update
the cache with this data.

§ RDB works by taking snapshots of the
database's state at regular intervals.
§ These snapshots are saved in a
compressed binary file that represents
the complete state of the database at a
specific point in time.
§ The main downside to this mechanism
is that data between snapshots will be
lost.
§ RDB snapshots can be configured to
occur at different intervals or triggered
manually. RDB files are generally more
compact and suitable for backup
purposes.

Advantages of RDB in Redis:
o Compactness: RDB snapshots are
compact, storing key-value pairs
efficiently with optional LZF
compression to further reduce file
size.
o Performance: Snapshots are
generated in the background, having
no impact on write performance.
However, the forking process may
slightly affect overall performance.
o Faster Restarts: RDB enables
quicker restarts by directly loading
the entire dataset from a snapshot,
which is faster than rebuilding the
database state from AOF entries.

§ Disadvantages of RDB in Redis:
o Durability: Pure RDB-based
persistence risks data loss between
snapshots. It may not be sufficient
for disaster recovery if losing
transactions after the last snapshot is
unacceptable.
o Performance: Creating RDB
snapshots involves forking the
server and processing the entire
dataset, which can be resourceintensive
and impact performance,
especially during large updates.

The Append Only File (AOF)
persistence mode logs all write
operations (commands that
modify data) to a log file.
§ This log file contains a sequence
of commands that can be
replayed to reconstruct the
dataset.
§ The AOF file is written
sequentially and can grow over
time.

Advantages of AOF:
o Durability: Operations are
logged in the appendonly.aof file,
allowing Redis to restore its state
by replaying commands. Unlike
RDB snapshots, AOF minimizes
data loss but may still lose data if
fsync is not configured to run
after every operation.
o Transparency: The
appendonly.aof file is easy to
inspect and modify with a text
editor, making it useful for
debugging and tracking issues.

Disadvantages of AOF:
o File Size: The appendonly.aof file is
usually much larger than dump.rdb,
especially with frequent key updates.
AOF can compact logs to reduce size
but still tends to be larger.
o Startup Time: AOF requires
replaying all commands to restore
state, which is slower than loading a
simple RDB snapshot, especially with
high write-loads.
o Performance: AOF may be slower
and less predictable compared to
RDB, which generally offers more
consistent performance, especially in
high write-load scenarios.

EXPLAIN EVERYTHING, TRY TO USE AS MUCH INFORMATION AS I ATTACHED, BUT MAKE THE EXPLANATION SIMPLER. MANTAIN THE ORDER OF THE INFORMATION.