https://redis.io/topics/data-types-intro
- binary-safe strings
- lists: strings (insertion order) (linked list instead of array)
- sets: strings
- sorted sets: (strings, score)
- hashes: {string:string}
- bit array: bitmaps
- HyperLogLogs
- streams: append-only map-like
https://redis.io/topics/transactions
(Redis doesn't support roll backs. Even some cmds failed, it will execute the rest.)
- MULTI: enter a transaction
- EXEC: execute cmd
- DISCARD: flush the transaction queue (no cmds are executed)
- WATCH: check-and-set (CAS)
https://redislabs.com/redis-enterprise/technology/highly-available-redis/
- Replication
- store dataset
- failover
- serve asa a tiebreaker
- Auto failover
- node watchdog
- cluster watchdog
- Multi availability zone
https://redis.io/topics/distlock
Single instance: SET resource_name my_random_value NX PX 30000
(not exist, expire)
Redlock:
- get the current time in milliseconds
- try to aquire the lock in all the N Redis master sequentially with a small timeout
- the time elapsed is less than lock validity time and aquired lock in the majority instances
- validity time = initial validity time - time elapsed
- try to unlock all the instance if failed, and retry after a random delay
https://redis.io/topics/internals-sds
struct sdshdr {
long len;
long free;
char buf[];
};
https://redis.io/commands/expire
- passive: expire when access the key
- active: (10 times per second)
- test 20 random keys
- delete all the expired keys
- if more than 25%, start again
https://redis.io/topics/persistence
- RDB: point-in-time snapshots of dataset at specified intervals
- backup
- compact
- maximize performance (child process will do the disk I/O)
- allow faster restarts
- loss data
- fort() can be time consuming
- AOF: log every write operation that will be played again at server startup
- durable (no fsync, fsync every second, fsync at every query)
- append only
- automatically rewrite a minimal set of operations needed to create the current data set
- log format is easy to understand and parse
- bigger than RDB
- can be slower
https://redis.io/topics/lru-cache
approximated LRU algorithm