Redis Flashcards
What happens when redis server gets turned off?
- The first method is a point-in-time dump either when certain conditions are met ( For example makes snapshot only if something was written during 15 minutes )
- The second method uses an append-only file that writes every command that alters data
in Redis to disk as it happens.
What real cases can redis improve comparing to relational DB?
- you can avoid writing unnecessary temporary data, avoid needing to scan over and delete this temporary data, and ultimately improve performance.
- Write statistics
- Counters
- Write logs
What 5 redis data structure exists?
STRINGs, LISTs, SETs, HASHes, and ZSETs (sorted set)
How to add/get/remove string value in redis?
set mykey ‘hello’
get mykey
del mykey
How to get/add/remove values from the redis list?
rpush my_list 1 2 3
lindex my_list 0 # 1
lrange my_list 0 2 # 1 2 3
lpop my_list # removes first value from the left
rpop my_list # removes first value from the right
How to get/add/remove values from the redis set?
sadd my_set 1 sadd my_set 2 sadd my_set 3 srem my_set 3 smembers my_set # 1 2 sismember my_set 32 # 0
How to get/add/remove values from the redis hash?
hset my_hash key 12 hset my_hash key2 12 hget my_hash key hdel my_hash key hgetall my_hash # returns all
How to implement pub/sub in redis?
SUBSCRIBE channel
PUBLISH channel ‘Hello message’
How to use transaction in Redis?
MULTI
set key ‘hello’
….
EXEC
What is snapshot drawback?
- Snaphot creating could stop the redis for several seconds if there too much data inside.