Skip to content

Instantly share code, notes, and snippets.

@indyarocks
Created May 21, 2017 18:04
Show Gist options
  • Save indyarocks/19ed1ec98342cc88fce087cd53217291 to your computer and use it in GitHub Desktop.
Save indyarocks/19ed1ec98342cc88fce087cd53217291 to your computer and use it in GitHub Desktop.
Redis LIST data type
127.0.0.1:6379> RPUSH list-key item1 # Initializing list by pushing an item for key list-key
(integer) 1
127.0.0.1:6379> RPUSH list-key item2 # Pushing item2 on list
(integer) 2
127.0.0.1:6379> RPUSH list-key item3 # Pushing item3 on list
(integer) 3
127.0.0.1:6379> RPUSH list-key1 item # Initializing list by pushing an item for key list-key
(integer) 1
127.0.0.1:6379> RPUSH list-key1 item1 # Pushing item1 on list
(integer) 2
127.0.0.1:6379> RPUSH list-key1 item2 # Pushing item2 on list
(integer) 3
127.0.0.1:6379> RPUSH list-key1 item2 # Pushing item2 again on list
(integer) 4
127.0.0.1:6379> LRANGE list-key1 0 -1 # Fetching data from index 0 to the end of list (-1) from list-key1
1) "item"
2) "item1"
3) "item2"
4) "item2"
127.0.0.1:6379> LINDEX list-key 2 # Fetching data at index 2. Returns item3
"item3"
127.0.0.1:6379> LINDEX list-key 20 # Fetching data at index 20. Returns nil
(nil)
127.0.0.1:6379> LPOP list-key # POPing from LEFT of the list with key list-key
"item1"
127.0.0.1:6379> LRANGE list-key 0 -1 # Fetching data from index 0 to the end of list (-1)
1) "item2"
2) "item3"
127.0.0.1:6379> LPUSH list-key item # Pushing item on left side of list-key
(integer) 3
127.0.0.1:6379> LRANGE list-key 0 -1 # Fetching data from index 0 to the end of list (-1)
1) "item"
2) "item2"
3) "item3"
127.0.0.1:6379> LRANGE list-key 0 1 # Fetching data from index 0 to index 1
2) "item2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment