Redis (REmote DIctionary Server) is an in-memory, key-value database, commonly referred to as a data structure server. One of the key differences between Redis and other key-value databases is Redis’s ability to store and manipulate high-level data types. These data types are fundamental data structures (lists, maps, sets, and sorted sets) that most developers are familiar with. Redis’s exceptional performance, simplicity, and atomic manipulation of data structures lends itself to solving problems that are difficult or perform poorly when implemented with traditional relational databases.
To start the Redis server
- redis-server
- redis-cli
Notes
{key :"value"} → value is always a string (key value pair)
Numbers ⇒ "10020"
Objects ⇒ {key : "{ a : '1' }" }
Array ⇒ {key : "[1,2,3,4]" }
Basic Commands
- SET → SET
- GET → GET
- DEL → DEL
- EXISTS → EXISTS
- KEYS * → displays all available keys
- FLUSHALL → Deletes everything
- TTL → Time to live { TTL }
- EXPIRE → EXPIRE
- SETEX → SETEX
ARRAY OPERATIONS
- LPUSH → insert from left side → LPUSH
- RPUSH → insert from right side → RPUSH
- LPOP → Delete from left → LPOP
- RPOP →Delete from right → RPOP
- LRANGE → Iterating through the array → LRANGE
SADD → Allows only unique String elements in the array ( tip : if you have to insert words with space write it within double quotes else it will take it as 2 words ; by default it takes input as Strings
{ SADD
SMEMBERS → SMEMBERS
HASHES (kind of objects)
- HSET → HSET
- HGET → HGET
- HGETALL → HGET
- HDEL → HDEL
- HEXISTS → HEXISTS → returns 0 or 1