"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

August 23, 2022

Redis - Examples

 In an eCommerce site

  • Preserve user cart information
  • User browsing history
  • User past purchases
  • Automatically Expire sessions on timeout
Redis - Remote Dictionary Service
Redis - open-source key-value database server



#https://try.redis.io/#run
SET - allows you to set a key to a value in Redis.
SET cart_session1 "SKU110,SKU121,SKU142"
GET - GET allows you to get the keys you've set.
GET cart_session1
SETNX - This key will set a value only if the key does not exist.
SET key1 value1
SETNX key1 value2
SETNX key2 value2
SET key1 value1
SETNX key1 value2
SET cart_session1 "SKU110,SKU121,SKU142"
SETNX cart_session1 "SKU110,SKU121,SKU144"
GET cart_session1
MSET - MSET is like SET, but you can set multiple keys together in one command. Here's how it works:
MSET key1 "value1" key2 "value2" key3 "value3"
MSET cart_session1 "SKU110,SKU121,SKU142" cart_session2 "SKU110,SKU121,SKU144" cart_session3 "SKU110,SKU121,SKU148"
MGET
MGET is similar to GET, but it can return multiple values at once, like this:
MGET key1 key2 key3 key4
MGET cart_session1 cart_session2 cart_session3
DEL - This command deletes a key – simple enough, right?
Here's an example:
SET key value
GET key # gives you "value"
DEL key
GET key # null
DEL cart_session3
DEL cart_session2
EXPIRE - The EXPIRE command is used to set an expiration timer to a key. Technically it's not a timer, but a kill timestamp beyond which the key will always return null unless it's set again.
EXPIRE cart_session1 10
Keep Experimenting!!!

No comments: