Hash
Redis hashes are record types structured as collections of field-value pairs. You can use hashes to represent basic objects and to store groupings of counters, among other things.
HSETsets the value of one or more fields on a hash.HGETreturns the value at a given field.HMGETreturns the values at one or more given fields.HINCRBYincrements the value at a given field by the integer provided.
HSET "product:501" title "Laptop" price "799" description "Latest model..." stock "150"
(Retrieve title and price for the product)
HMGET "product:501" title price stock
(Decrement stock by 1 when a product is purchased)
HINCRBY "product:501" stock -1
HMGET "product:501" title price stock
HGETALL "product:501"
HDEL "product:501" "stock"Use Case: User Session Store
userid
1
name
Rachel
ip
10.20.133.233
hits
1
EXPIRE
Sets a Key's time to live (TTL). The key will be automatically deleted from Redis once a specific duration (in seconds) has elapsed.
DEL
Immediately deletes a key and its associated value from Redis
Last updated