Learning :
Redis for Beginners - Net Ninja Redis Crash Course - Web Dev Simplified
Redis is like Map in JS, KEY = VALUE and VALUE is usually/default stored as string
Terminal Commands :
- Open WSL :
wsl - Start Redis server :
redis-server - Open Redis server :
redis-cli - Quit CLI :
quit - SET pair :
SET KEY VALUE - GET VALUE :
GET KEY - DELETE VALUE :
DEL KEY - CHECK IF KEY EXIST :
EXISTS KEY - LIST ALL KEYS :
KEYS * - DELETE WHOLE REDIS DATA :
flushall
Expiration (time limit) of a key :
ttl KEY===-1then key exist but don’t have expiration timettl KEY===-2then key don’t existttl KEY=== positive integer is seconds left.- to set expiration time of stored KEY ⇒
expire KEY 10here 10 is 10sec - to set expiration time of NEW KEY ⇒
setex KEY 10 VALUE
List (doubly queue) :
lpush KEY VALUE⇒ make an array of nameKEY(if not exist) and pushVALUEat the START of array.rpush KEY VALUE⇒ make an array of nameKEY(if not exist) and pushVALUEat the END of array.lrange KEY 0 -1⇒ list all values in array.LPOP KEY⇒ pops out first element.RPOP KEY⇒ pops out last element.
Sets (like maths sets allow only unique values) :
SADD KEY VALUE⇒ creates setKEYif not exist and then addVALUESMEMBERS KEY⇒ list all values in setKEY.SREM KEY VALUE⇒ removesVALUEfromKEYset.
Hashes (key value pairs inside a key value pair (but hashes can’t be nested))
HSET KEY KEY VALUE===KEY = { KEY: VALUE }- Example :
HSET person name kyle===person = { name: kyle } HGET person nameoutputskyle.HSET person age 26HGETALL personoutputs :
"name"
"kyle"
"age"
"26"HDEL person age⇒ deletes age from person.HEXIST person age⇒ (checks if age exist) outputs 0 as age is deleted.