Nell’iperspazio con Rocket: il Framework Web di Rust!
Redis overview
1. Redis cache
Redis is a in-memory, key-value data store. it’s
the most popular key-value data store, used by all
big IT brands in this world. Amazon Elastic Cache
supports Redis which makes redis a very powerful
and must know key-value data store.
2. What Is In-Memory, Key-
Value Store
Key-Value store is a storage system where data is
stored in form of key and value pairs. When we
say in-memory key-value store, by that we mean
that the key-value pairs are stored in primary
memory(RAM). So we can say that Redis stored
data in RAM in form of key-value pairs.
In Redis, key has to be a string but value can be a
string, list, set, sorted set or hash.
3. What Is In-Memory, Key-
Value Store
Lists: collections of string elements sorted
according to the order of insertion. They are
basically linked lists.
Sets: collections of unique, unsorted string
elements.
4. What Is In-Memory, Key-
Value Store
Sorted sets, similar to Sets but where every string
element is associated to a floating number value,
called score. The elements are always taken
sorted by their score, so unlike Sets it is possible
to retrieve a range of elements (for example you
may ask: give me the top 10, or the bottom 10).
Hashes, which are maps composed of fields
associated with values. Both the field and the
value are strings. This is very similar to Ruby or
Python hashes
5. Advantage And Disadvantage
of Redis over DBMS
Database Management systems store everything
in second storage which makes read and write
operations very slow. But Redis stores everything
in primary memory which is very fast in read and
write of data.
6. Advantage And Disadvantage
of Redis over DBMS
Exceptionally fast − Redis is very fast and can
perform about 110000 SETs per second, about
81000 GETs per second.
Supports rich data types − Redis natively supports
most of the datatypes that developers already
know such as list, set, sorted set, and hashes.
This makes it easy to solve a variety of problems
as we know which problem can be handled better
by which data type.
7. Advantage And Disadvantage
of Redis over DBMS
Operations are atomic − All Redis operations are
atomic, which ensures that if two clients
concurrently access, Redis server will receive the
updated value.
Multi-utility tool − Redis is a multi-utility tool and
can be used in a number of use cases such as
caching, messaging-queues (Redis natively
supports Publish/Subscribe), any short-lived data
in your application, such as web application
sessions, web page hit counts, etc.
8. Advantage And Disadvantage
of Redis over DBMS
Primary memory is limited(much lesser size and
expensive than secondary) therefore Redis
cannot store large files or binary data. It can only
store those small textual information which needs
to be accessed, modified and inserted at a very
fast rate.
10. Redis Single Instance
Architecture
Redis client and server can be in the same
computer or in two different computers.
Redis server is responsible for storing data in
memory. It handles all kinds of management and
forms the major part of architecture. Redis client
can be Redis console client or any other
programming language’s Redis API.
11. Redis Single Instance
Architecture
As we saw that Redis stores everything in primary
memory. Primary memory is volatile and therefore
we will loose all stored data once we restart our
Redis server or computer. Therefore we need a
way for datastore persistance.
13. Redis Persistance
RDB Mechanism
RDB makes a copy of all the data in memory and
stores them in secondary storage(permanent
storage). This happens in a specified interval. So
there is chance that you will loose data that are
set after RDB’s last snapshot.
14. Redis Persistance
AOF
AOF logs all the write operations received by the
server. Therefore everything is persistance. The
problem with using AOF is that it writes to disk for
every operation and it is a expensive task and
also size of AOF file is large than RDB file.
16. Backup And Recovery Of
Redis DataStore
Redis does not provide any mechanism for
datastore backup and recovery. Therefore if there
is any hard disk crash or any other kind of
disaster then all data will be lost. You need to use
some third party server backup and recovery
softwares to workaround it.
If you are using Redis in a replicated environment
then there is no need for backup.
17. Redis commands (SET)
SET supports a set of options that modify its
behavior:
1- EX seconds -- Set the specified expire time, in seconds
Ex ( SETEX mykey 10 "Hello").
2- PX milliseconds -- Set the specified expire time, in milliseconds.
3- NX -- Only set the key if it does not already exist.
18. Redis commands (GET)
Get the value of key. If the key does not exist the
special value nil is returned. An error is returned if
the value stored at key is not a string, because
GET only handles string values.
20. Sets commands
1- SADD : Add the specified members to the set
stored at key
2- SMEMBERS : Returns all the members of the
set value stored at key.
3- SCARD : Returns the set cardinality (number of
elements) of the set stored at key.
4- SDIFF : Returns the members of the set
resulting from the difference between the first set
and all the successive sets.
21. Hash commands
HSET : Sets field in the hash stored at key to
value. If key does not exist, a new key holding a
hash is created. If field already exists in the hash,
it is overwritten.
ex : HSET myhash field1 "Hello"
HDEL : Removes the specified fields from the
hash stored at key.
ex : HDEL myhash field1
22. Hash commands
HGET : Returns the value associated with field in
the hash stored at key.
Ex : HGET myhash field1
HGETALL : Returns all fields and values of the
hash stored at key. In the returned value, every
field name is followed by its value, so the length of
the reply is twice the size of the hash.
Ex :HGETALL myhash