{"id":1673,"date":"2021-06-06T13:46:02","date_gmt":"2021-06-06T13:46:02","guid":{"rendered":"https:\/\/codeinsightacademy.com\/blog\/?p=1673"},"modified":"2024-01-06T06:48:04","modified_gmt":"2024-01-06T06:48:04","slug":"redis","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/database\/redis\/","title":{"rendered":"Redis"},"content":{"rendered":"\n<p>Redis Playground<br><br><a href=\"https:\/\/try.redis.io\/\">https:\/\/try.redis.io\/<\/a><br><br>Note: This try redis io is community version on web so few commands might not work. To use redis&#8217;s full power you can download and install on your local system<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Redis is an in-memory data structure store, used as a distributed, in-memory key\u2013value database, cache and message broker, with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices.<\/p>\n\n\n\n<h3>Installation<\/h3>\n\n\n\n<p>To install redis on windows download msi package from here<br><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/microsoftarchive\/redis\/releases\/\" target=\"_blank\">https:\/\/github.com\/microsoftarchive\/redis\/releases\/<\/a><\/p>\n\n\n\n<p>For Linux Distr<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install redis-server<\/code><\/pre>\n\n\n\n<p>To install PHPRedis client use following command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install php-redis\n#for specific version\nsudo apt-get install php7.4-redis<\/code><\/pre>\n\n\n\n<p>To verify redis installed in your system<br>Note: On windows you might need to add redis exe path in environment variables<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-cli PING<\/code><\/pre>\n\n\n\n<p>To see all keys<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>KEYS *<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-12.png\"><img loading=\"lazy\" width=\"336\" height=\"180\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-12.png\" alt=\"\" class=\"wp-image-1701\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-12.png 336w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-12-300x161.png 300w\" sizes=\"(max-width: 336px) 100vw, 336px\" \/><\/a><\/figure><\/div>\n\n\n\n<h2 class=\"has-text-align-center\">DATATYPES<\/h2>\n\n\n\n<ul><li>string <\/li><li>list<\/li><li>set<\/li><li>sorted set<\/li><li>hash<\/li><\/ul>\n\n\n\n<ol><li>String<br>Syntax to set string value<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>SET key value &#91;EX seconds] &#91;PX milliseconds] &#91;NX|XX]<\/code><\/pre>\n\n\n\n<p>To set only string value<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SET keyname value<\/code><\/pre>\n\n\n\n<p>To check whether key exist or not<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>EXISTS keyname<\/code><\/pre>\n\n\n\n<p>Get key&#8217;s value<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GET keyname<\/code><\/pre>\n\n\n\n<p>To delete any specific key<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DEL keyname<\/code><\/pre>\n\n\n\n<p>To delete all keys<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FLUSHALL<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-11.png\"><img loading=\"lazy\" width=\"396\" height=\"542\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-11.png\" alt=\"\" class=\"wp-image-1698\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-11.png 396w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-11-219x300.png 219w\" sizes=\"(max-width: 396px) 100vw, 396px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>SET string with expiry<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SET key value\nEXPIRE key expiry-time-in-seconds\n#shortcut\nSET key value EX expiry-time-in-seconds<\/code><\/pre>\n\n\n\n<p>To check expiry time of any key<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>TTL key<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-6.png\"><img loading=\"lazy\" width=\"441\" height=\"240\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-6.png\" alt=\"\" class=\"wp-image-1685\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-6.png 441w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-6-300x163.png 300w\" sizes=\"(max-width: 441px) 100vw, 441px\" \/><\/a><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-7.png\"><img loading=\"lazy\" width=\"509\" height=\"124\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-7.png\" alt=\"\" class=\"wp-image-1688\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-7.png 509w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-7-300x73.png 300w\" sizes=\"(max-width: 509px) 100vw, 509px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>SET string values using key:spaces<br>This is required when you want to set values related to one entity<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SET key:space value<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-13.png\"><img loading=\"lazy\" width=\"434\" height=\"326\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-13.png\" alt=\"\" class=\"wp-image-1703\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-13.png 434w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-13-300x225.png 300w\" sizes=\"(max-width: 434px) 100vw, 434px\" \/><\/a><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>2. List or Stack<\/h3>\n\n\n\n<p>To set list use LPUSH<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LPUSH key value1\nLPUSH key value2\nLPUSH key value3\nOR\nLPUSH key value1 value2 value3<\/code><\/pre>\n\n\n\n<p>To get length of list<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LLEN key<\/code><\/pre>\n\n\n\n<p>To access any value of list you need to use LRANGE<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LRANGE key from-index to-index<\/code><\/pre>\n\n\n\n<p>Use -1 in to-value to get all elements from list<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LRANGE key 0 -1<\/code><\/pre>\n\n\n\n<p>To get specific index value<br>NOTE this will act like stack so LIFO algorithm will apply here i.e. index 0 will give you last inserted\/pushed value<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LINDEX key 0<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-15.png\"><img loading=\"lazy\" width=\"663\" height=\"394\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-15.png\" alt=\"\" class=\"wp-image-1718\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-15.png 663w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-15-300x178.png 300w\" sizes=\"(max-width: 663px) 100vw, 663px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>LPUSH and RPUSH (left and right push)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LPUSH key value\nRPUSH key value<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-16.png\"><img loading=\"lazy\" width=\"412\" height=\"419\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-16.png\" alt=\"\" class=\"wp-image-1723\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-16.png 412w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-16-295x300.png 295w\" sizes=\"(max-width: 412px) 100vw, 412px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>LPOP and RPOP<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LPOP key\nRPOP key<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-18.png\"><img loading=\"lazy\" width=\"395\" height=\"413\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-18.png\" alt=\"\" class=\"wp-image-1731\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-18.png 395w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-18-287x300.png 287w\" sizes=\"(max-width: 395px) 100vw, 395px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>Remove specific element from list<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LREM key count value<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-19.png\"><img loading=\"lazy\" width=\"545\" height=\"307\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-19.png\" alt=\"\" class=\"wp-image-1734\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-19.png 545w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-19-300x169.png 300w\" sizes=\"(max-width: 545px) 100vw, 545px\" \/><\/a><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>3. Sets<\/h3>\n\n\n\n<p>Set is similar to list the main difference is it does not allow duplicate members<br>Order is not maintained in set<\/p>\n\n\n\n<p>To add member in sets<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SADD key value1 value2 value3<\/code><\/pre>\n\n\n\n<p>To view members of sets<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SMEMBERS key<\/code><\/pre>\n\n\n\n<p>To remove member from sets<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SREM key member<\/code><\/pre>\n\n\n\n<p>To get length of Sets<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SCARD key<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-21.png\"><img loading=\"lazy\" width=\"528\" height=\"367\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-21.png\" alt=\"\" class=\"wp-image-1743\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-21.png 528w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-21-300x209.png 300w\" sizes=\"(max-width: 528px) 100vw, 528px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>Compare Sets<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SINTER set1 set2\nSDIFF set1 set2\nSUNION set1 set2<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-24.png\"><img loading=\"lazy\" width=\"512\" height=\"650\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-24.png\" alt=\"\" class=\"wp-image-1750\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-24.png 512w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-24-236x300.png 236w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/a><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>4. Sorted Sets<\/h3>\n\n\n\n<p>Sorted set are similar to sets the major difference is it stored members based on score i.e. sorted by score<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ZADD key score member<\/code><\/pre>\n\n\n\n<p>To add multiple members<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ZADD key rank1 member1 rank2 member2<\/code><\/pre>\n\n\n\n<p>To get count of sorted sets<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ZCOUNT key<\/code><\/pre>\n\n\n\n<p>To See all members of sorted sets<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ZRANGE key 0 -1<\/code><\/pre>\n\n\n\n<p>To get rank(index) of specific member<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ZRANK key member<\/code><\/pre>\n\n\n\n<p>To get score of specific member<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ZSCORE key member<\/code><\/pre>\n\n\n\n<p>To remove member from sorted sets<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ZREM key member<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-31.png\"><img loading=\"lazy\" width=\"457\" height=\"643\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-31.png\" alt=\"\" class=\"wp-image-1780\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-31.png 457w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-31-213x300.png 213w\" sizes=\"(max-width: 457px) 100vw, 457px\" \/><\/a><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>5. Hashes<\/h3>\n\n\n\n<p>Hash is used to set field value pair it is similar to associative array<\/p>\n\n\n\n<p>To set hash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HGET key field1 value1\nHGET key field2 value2<\/code><\/pre>\n\n\n\n<p>To get field value<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HGET key field<\/code><\/pre>\n\n\n\n<p>To get all field values<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HGETALL key<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-25.png\"><img loading=\"lazy\" width=\"477\" height=\"401\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-25.png\" alt=\"\" class=\"wp-image-1754\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-25.png 477w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-25-300x252.png 300w\" sizes=\"(max-width: 477px) 100vw, 477px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>To get length of hash key<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HLEN key<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-30.png\"><img loading=\"lazy\" width=\"325\" height=\"132\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-30.png\" alt=\"\" class=\"wp-image-1766\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-30.png 325w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-30-300x122.png 300w\" sizes=\"(max-width: 325px) 100vw, 325px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>To add field values at once<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HMSET key field1 value1 field2 value2 field3 value3<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-27.png\"><img loading=\"lazy\" width=\"609\" height=\"245\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-27.png\" alt=\"\" class=\"wp-image-1758\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-27.png 609w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-27-300x121.png 300w\" sizes=\"(max-width: 609px) 100vw, 609px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>To get values at once<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HMGET key field1 field2 field2<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-28.png\"><img loading=\"lazy\" width=\"499\" height=\"129\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-28.png\" alt=\"\" class=\"wp-image-1761\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-28.png 499w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-28-300x78.png 300w\" sizes=\"(max-width: 499px) 100vw, 499px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>To delete specific field from hash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HDEL key field1 field2<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-29.png\"><img loading=\"lazy\" width=\"388\" height=\"367\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-29.png\" alt=\"\" class=\"wp-image-1764\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-29.png 388w, https:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/image-29-300x284.png 300w\" sizes=\"(max-width: 388px) 100vw, 388px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>Assignment (set and get values of each type)<\/p>\n\n\n\n<ol><li>Create string name age and city and set value in it<\/li><li>Create List of fruits, weekdays, planets and set values in it<br>Print length and values of list<\/li><li>Create Sets of employees and managers<br>Print length and values of Sets<\/li><li>Create Hash record1, record2, record3 and add fields name age city in each hash<br>Print length and values of each hash<\/li><\/ol>\n\n\n\n<p>Reference Links<\/p>\n\n\n\n<ul><li><a rel=\"noreferrer noopener\" href=\"https:\/\/redis.io\/documentation\" target=\"_blank\">https:\/\/redis.io\/documentation<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.digitalocean.com\/community\/cheatsheets\/how-to-manage-strings-in-redis\" target=\"_blank\">https:\/\/www.digitalocean.com\/community\/cheatsheets\/how-to-manage-strings-in-redis<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.digitalocean.com\/community\/cheatsheets\/how-to-manage-lists-in-redis\" target=\"_blank\">https:\/\/www.digitalocean.com\/community\/cheatsheets\/how-to-manage-lists-in-redis<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.digitalocean.com\/community\/cheatsheets\/how-to-manage-sets-in-redis\" target=\"_blank\">https:\/\/www.digitalocean.com\/community\/cheatsheets\/how-to-manage-sets-in-redis<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.digitalocean.com\/community\/cheatsheets\/how-to-manage-sorted-sets-in-redis\" target=\"_blank\">https:\/\/www.digitalocean.com\/community\/cheatsheets\/how-to-manage-sorted-sets-in-redis<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-manage-hashes-in-redis\" target=\"_blank\">https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-manage-hashes-in-redis<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Redis Playground https:\/\/try.redis.io\/ Note: This try redis io is community version on web so few commands might not work. To use redis&#8217;s full power you can download and install on your local system Redis is an in-memory data structure store, used as a distributed, in-memory key\u2013value database, cache and message broker, with optional durability. Redis [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1794,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/1673"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=1673"}],"version-history":[{"count":55,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/1673\/revisions"}],"predecessor-version":[{"id":2679,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/1673\/revisions\/2679"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media\/1794"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=1673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=1673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=1673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}