3. Introduction
Redis is an in-memory data structure store.
Store data in the form of key/value pair.
Consistency is guaranteed by supporting "append-only file" and the
availability of data is guaranteed through cluster and master-slave
replication.
Can be used as Database, a Caching layer or a Message broker.
Redis can persist data to the disk
Redis is fast Redis is not only a key-value
store
4. Redis Datatypes (String)
Starting Redis is very easy, you just need to install the
desired redis package and write $ redis-server to run
the in memory redis server.
Key-value simple example:
$ SET fb www.facebook.com
$ GET fb
$ www.facebook.com
5. Complex Datatypes
(Hash)
Hashes are like nested Redis Objects that can take any number of
key-value pairs.
$ HMSET user:eric name "Eric Redmond" password s3cret
Single redis key can be used to retrieve all values of the hash.
6. Complex Datatypes (List)
Lists contain multiple ordered values that can
act as both queues (FIFO) and stacks (FILO).
Can exceute actions such as adding element in
the middle, deleting values, ...
7. Complex Datatypes (Set)
Sets are unordered collections that does
not allow for duplication.
Accepts set operations such as UNION
and INTERSECTION
8. Data Expiry
One of the best uses of Redis key-value store is fast-access cache for
data that's more expensive to retrieve or compute.
As we know cache should be expired and get updated periodically.
Using Redis you can mark a key for expiration by using EXPIRE command
and give the key time to live in seconds
9. Durability
With Redis you can choose between no persistent or save your data.
No persistent will keep the values in the main-memory.
No persistent is best choice if you run a caching server because durability
will increase the latency.
You can also force storing data to disk by using SAVE command (or
BGSAVE
for asynchronous save)
10. Durability (Cont.)
Redis also provides append-only file that keeps a record of all write
commands.
That ensures correct value even if the server craches before value saved.
The Redis server executes the commands on the startup.
By append-only file we can be sure that the data is eventually consistent.
11. Master-Slave Replication
Redis supports master-slave replication (one server is
master by defualt)
The replication feature allows Redis to ensure the
availability.
Even if the main server is down, slave servers already
have the replicated data and ready to serve clients.
12.
13. Redis Cluster
Clustering is the advanced mode of replication
In this mode the servers are master servers and are
connected to each other.
Clustering makes Redis suitable for distributed systems.
The clustering gives you the ability to automatically split
your dataset among multiple nodes.
The operation will continue even if some nodes are failed
without having to expire most keys.