Redis Flashcards
What is Redis?
Distributed key-value store
Types allowed
Values are types:
* List of strings (with insertion on head or tail)
* Set of strings
* Sorted set of strings
* Hashes (similar to a struct/map)
* Bit array
* HyperLogLogs (probabilistic data structure for estimating the
number of elements in a set)
Each data type has a set of operations it supports.
How can redis be used as?
Redis can be used as a database, a cache or a message broker.
Characteristics of redis when used in cache
it uses a limited amount of memory;
* it uses a LRU algorithm for cache eviction. Possible to control
cache eviction by:
* Set a TTL for eviction;
* Define that only keys with a TTL can be evicted (making some
entries persistent).
Redis supports transactions including a sequence of operations.
Redis Architecture
Each server maintains key-value pairs.
Each server executes operations in the values.
Possible to create a cluster of Redis servers, with data
partitioned.
Primary-backup (remember Dist. Sys. course), with
asynchronous replication.
Multi-master replication with automatic conflict-resolution
(based on CRDTs).
Partitioning strategies
- Range partitioning;
- Hashing (some clients implement consistent hashing).
- Tag hashing to control location of data – a tag is a prefix to the
key; only the tag is hashed. - E.g. {CSS}key1 and {CSS}key2 are hashed to the same server, as
only CSS is hashed.
Replication is usually used in Redis
No, but it has support for it
Persistence (3)
Several alternatives:
* No persistence.
* RDB persistence: performs point-in-time snapshots of the
database state at specified intervals.
* Append-only fashion: logs every write operation received by
the server, that will be played again at server startup. Log
compressed in background.
* Durability depends on the parameters used for fsync. Remember
the OS course.
Uses
Simple caching (as with Memcached).
Advanced caching functionalities, using data types support.
How to guarantee that the cache is up-to-date with
the database.
With CosmosDB and Redis, a possible solution is to use the
timestamp associated with the document to guarantee that the
latest version is kept in the cache. The value set should include
both the key and the timestamp. When setting the value of the
cache, the old value can be returned, allowing the client to
check if it has overwritten a more recent value.