# Redis Redis = **Re**mote **Di**ctionary **S**erver. Usually used as cache. Can be used as a "buffer" between endpoint and multiple app servers. ## Concepts - Pub/Sub - Transactions - LRU - Leader vs Follower server - Redis Cluster, sharding - Redis Sentinel, self-healing ## Usage ```redis SET name "Samuel" GET name SET user:sghuang:city "South Bend" SET visits 0 INCR visits INCRBY visits 2 MSET score:seahawks 43 score:brocos 8 EXISTS name // returns 1 or 0 DEL name SET color blue XX // set only if the key exists SET color blue NX // set if does not exist SET name "Samuel" EX 3600 // TTL, use PX for miliseconds TYPE visits // everything is a string RPUSH notifications "N1" "N2" "N3" // array LRANGE notifications 0 -1 RPOP notifications // also LPOP LTRIM and RTRIM HMSET sghuang title "X" name "X" HGET sghuang name HGETALL and HINCR SADD colors red blue ... SISMEMBER colors red SMEMBERS colors SPOP colors ZADD ordinals 3 third // sorted set ZADD ordinals 1 first EVAL "for i = 0,9,1 do redis.call('SET', 'lua_key' .. i, i * 5) end" 0 ``` Be aware of the [[thundering-herd]]. HyperLogLog and Streams