Introduction to Redis - Strings & Lists

Redis Commands for Strings

 
  redis 127.0.0.1:6379> set satish 20
  OK

  redis 127.0.0.1:6379> get satish
  (integer) 20

  redis 127.0.0.1:6379> set ram 50
  OK
  
  redis 127.0.0.1:6379> incr ram
  (integer) 51
  
  redis 127.0.0.1:6379> get ram
  "51"
  
  redis 127.0.0.1:6379> incr ram
  (integer) 52
  
  redis 127.0.0.1:6379> get ram
  "52"
  
  redis 127.0.0.1:6379> incr ram
  (integer) 53
  
  redis 127.0.0.1:6379> decr ram
  (integer) 52
  
  redis 127.0.0.1:6379> incrby ram 2
  (integer) 54
  
  redis 127.0.0.1:6379> get ram
  "54"
  
  redis 127.0.0.1:6379> decrby ram 3
  (integer) 51
  
  redis 127.0.0.1:6379> get ram
  "51"
  
  redis 127.0.0.1:6379> setex ram 33 1
  OK
  
  redis 127.0.0.1:6379> get ram
  "1"
  
  redis 127.0.0.1:6379> get ram
  "1"
  
  redis 127.0.0.1:6379> setex ram "20" 2
  OK
  
  redis 127.0.0.1:6379> get ram
  "2"
  
  redis 127.0.0.1:6379> get ram
  "2"
  
  redis 127.0.0.1:6379> get ram
  "2"
  
  redis 127.0.0.1:6379> get ram
  "2"
  
  redis 127.0.0.1:6379> get ram
  (nil)
  
  redis 127.0.0.1:6379> setex ram 20 2
  OK
  
  redis 127.0.0.1:6379> get ram
  "2"
  
  redis 127.0.0.1:6379> get ram
  "2"
  
  redis 127.0.0.1:6379> get ram
  (nil)
  
  redis 127.0.0.1:6379> setnx ram 20
  (integer) 1
  
  redis 127.0.0.1:6379> get ram
  "20"
  
  redis 127.0.0.1:6379> setnx ram 30
  (integer) 0
  
  redis 127.0.0.1:6379> get ram
  "20"
  
  redis 127.0.0.1:6379> strlen name
  (integer) 5
  
  redis 127.0.0.1:6379> get name
  "ruban"
  
  redis 127.0.0.1:6379> randomkey
  "tom"
  
  redis 127.0.0.1:6379> get satish
  "20testhello"
  
  redis 127.0.0.1:6379> del satish
  (integer) 1
  
  redis 127.0.0.1:6379> get satish
  (nil)
  
  redis 127.0.0.1:6379> get ram
  "20"
  
  redis 127.0.0.1:6379> ttl ram
  (integer) -1
  
  redis 127.0.0.1:6379> setex test 10 2
  OK
  
  redis 127.0.0.1:6379> ttl test
  (integer) 6
  
  redis 127.0.0.1:6379> ttl test
  (integer) -1
  
  redis 127.0.0.1:6379> get test
  (nil)
  
  redis 127.0.0.1:6379> setex test 10 myval
  OK
  
  redis 127.0.0.1:6379> ttl test
  (integer) 7
  
  redis 127.0.0.1:6379> ttl test
  (integer) 4
  
  redis 127.0.0.1:6379> get test
  "myval"
  
  redis 127.0.0.1:6379> ttl test
  (integer) -1
  
  redis 127.0.0.1:6379> get test
  (nil)
  
  redis 127.0.0.1:6379> randomkey
  "tom"
  
  redis 127.0.0.1:6379> get satish
  "20testhello"
  
  redis 127.0.0.1:6379> del satish
  (integer) 1
  
  redis 127.0.0.1:6379> get satish
  (nil)
  
  redis 127.0.0.1:6379> get ram
  "20"
  
  redis 127.0.0.1:6379> ttl ram
  (integer) -1
  
  redis 127.0.0.1:6379> setex test 10 2
  OK
  
  redis 127.0.0.1:6379> ttl test
  (integer) 6
  
  redis 127.0.0.1:6379> ttl test
  (integer) -1
  
  redis 127.0.0.1:6379> get test
  (nil)
  
  redis 127.0.0.1:6379> setex test 10 myval
  OK
  
  redis 127.0.0.1:6379> ttl test
  (integer) 7
  
  redis 127.0.0.1:6379> ttl test
  (integer) 4
  
  redis 127.0.0.1:6379> get test
  "myval"
  
  redis 127.0.0.1:6379> ttl test
  (integer) -1
  
  redis 127.0.0.1:6379> get test
  (nil)
  
  redis 127.0.0.1:6379> get satish
  (nil)
  
  redis 127.0.0.1:6379> set satish 20
  OK
  
  redis 127.0.0.1:6379> get satish
  "20"
  
  redis 127.0.0.1:6379> rename satish cj
  OK
  
  redis 127.0.0.1:6379> get satish
  (nil)
  
  redis 127.0.0.1:6379> get cj
  "20"
  
  redis 127.0.0.1:6379> exists cj
  (integer) 1
  
  redis 127.0.0.1:6379> exists mj
  (integer) 0
  
  redis 127.0.0.1:6379> keys t?m
  "tom"
  
  redis 127.0.0.1:6379> set tim 3
  OK
  
  redis 127.0.0.1:6379> keys t?m
  1 "tom"
  2 "tim"
  
  redis 127.0.0.1:6379> set toom 45
  OK
  
  redis 127.0.0.1:6379> keys t?m
  1 "tom"
  2 "tim"
  
  redis 127.0.0.1:6379> keys t*m
  1 "toom"
  2 "tom"
  3 "tim"
  
  redis 127.0.0.1:6379> set tm 55
  OK
  
  redis 127.0.0.1:6379> keys t*m
  1 "toom"
  2 "tom"
  3 "tm"
  4 "tim"
  
  redis 127.0.0.1:6379> keys t[oi]m
  1 "tom"
  2 "tim"
  
  redis 127.0.0.1:6379> set toim 33
  OK
  
  redis 127.0.0.1:6379> keys t[oi]m
  1 "tom"
  2 "tim"
  
  redis 127.0.0.1:6379> keys t[^o]m
  1 "tim"
  
  redis 127.0.0.1:6379> set tam 4
  OK
  
  redis 127.0.0.1:6379> keys t[^o]m
  1 "tam"
  2 "tim"
  
  redis 127.0.0.1:6379> set abc 2
  OK
  
  redis 127.0.0.1:6379> keys a[b-c]c
  1 "abc"
  
  redis 127.0.0.1:6379> keys a[b-c]
  (empty list or set)
  
  redis 127.0.0.1:6379> keys a[b-c]c
  1 "abc"
  
  redis 127.0.0.1:6379> set abcd 1
  OK
  
  redis 127.0.0.1:6379> keys a[b-c]d
  (empty list or set)
  
  redis 127.0.0.1:6379> set abd 2
  OK
  
  redis 127.0.0.1:6379> set acd 3
  OK
  
  redis 127.0.0.1:6379> keys a[b-c]d
  1 "abd"
  2 "acd"
  
  redis 127.0.0.1:6379> get satish
  (nil)
  
  redis 127.0.0.1:6379> get cj
  "20"
  
  redis 127.0.0.1:6379> rename cj satish
  OK
  
  redis 127.0.0.1:6379> get cj
  (nil)
  
  redis 127.0.0.1:6379> get satish
  "20"
  

Redis Commands for Lists

 
  redis 127.0.0.1:6379> lpush fruits apple
  (integer) 1
  (0.57s)
  
  redis 127.0.0.1:6379> llen fruits
  (integer) 1
  
  redis 127.0.0.1:6379> lpop fruits
  "apple"
  
  redis 127.0.0.1:6379> rpop fruits
  (nil)
  
  redis 127.0.0.1:6379> lpush fruits orange
  (integer) 1
  
  redis 127.0.0.1:6379> lrange fruits 0 1
  1 "orange"
  
  redis 127.0.0.1:6379> lpop fruits
  "orange"
  
  redis 127.0.0.1:6379> lpop fruits
  (nil)
  
  redis 127.0.0.1:6379> del fruits
  (integer) 0
  
  redis 127.0.0.1:6379> lpush fruits apple
  (integer) 1
  
  redis 127.0.0.1:6379> lpush fruits orange
  (integer) 2
  
  redis 127.0.0.1:6379> lpush fruits apple
  (integer) 3
  
  redis 127.0.0.1:6379> lpush fruits apple
  (integer) 4
  
  redis 127.0.0.1:6379> rpush fruits mango
  (integer) 5
  
  redis 127.0.0.1:6379> rpush fruits mango
  (integer) 6
  
  redis 127.0.0.1:6379> rpush fruits mango
  (integer) 7