list
data type is just a string list that is ordered in insertion and sorted.127.0.0.1:6379> RPUSH list 'object' (integer)1 127.0.0.1:6379> RPUSH list 'rocket' (integer)2 |
127.0.0.1:6379> RPUSHX list 'Tutorial' (integer)3 |
127.0.0.1:6379> LPUSH newlist 'There' (integer)1 127.0.0.1:6379> LPUSH newlist 'Hey' (integer)2 |
LRANGE
command returns a subset of the list based on the specified parameters.127.0.0.1:6379> LRANGE list 0-1 1)'object' 2)'rocket' 3)'Tutorial' 127.0.0.1:6379> LRANGE newlist 0-1 1)'Hey' 2)'There' |
LINDEX
command returns an element of the list at a particular index of the list stored at the key.127.0.0.1:6379> LINDEX newlist 0 'There' 127.0.0.1:6379> LINDEX newlist 1 'Hey' 127.0.0.1:6379> LINDEX newlist 2 (nil) 127.0.0.1:6379> LINDEX newlist 3 (nil) |
LINSERT
is used to insert an element into a list either before or after a specified reference value.127.0.0.1:6379> LINSERT list BEFORE 'rocket''Basic' (integer)4 |
127.0.0.1:6379> LPOP newlist 'Hey' |
LSET
command is used to set the value of an element at the specified index in the list.127.0.0.1:6379> LSET list1 0'd' OK 127.0.0.1:6379> LSET list1 -3'f' OK |
127.0.0.1:6379> RPOP list 'Tutorial' |
set
datatype differs from a list
in that each string element must be unique with no repeated values.SADD
command adds an item to the specified set that is stored at the key.SADD set'Redis' (integer)1 SADD set'Cheat' (integer)1 SADD set'Sheet' (integer)1 |
SREM set'Cheat' (integer)1 SREM set'Cheat' (integer)0 |
SISMEMBER set'Redis' (integer)1 SISMEMBER set'Cheat' (integer)0 |
SMEMBERS
command returns all of the items or members in the set.SADD newset1 ten (integer)1 SADD newset2 nine (integer)1 SADD newset3 eight (integer)1 SUNION newset1 newset2 newset3 1)'eight' 2)'nine' 3)'ten' |
SADD sv 'z' (integer)1 SADD sv 'x' (integer)1 SADD sv 'y' (integer)1 SADD sv1 'y' (integer)1 SADD sv1 'w' (integer)1 SADD sv1 'u' (integer)1 SINTER sv sv1 1)'y' |
sorted set
in Redis consists of a unique collection of strings, just like a regular set
. However, each member of a sorted set has a score associated with it, and members of the set are sorted in order of that score, from the smallest to the largest score.ZADD player 1'Dominic' (integer)1 ZADD player 2'Juan' (integer)1 |
ZADD znum 1'ten' (integer)1 ZADD znum 2'eleven' (integer)1 ZINCRBY znum 2'ten' '3' |
3
shows that Redis increased the original score of 1
by adding the specified amount of 2
.ZRANK
command returns the rank of a specified member of the sorted set.ZADD zset 1'five' (integer)1 ZADD zset 2'six' (integer)1 ZADD zset 3'seven' (integer)1 ZRANK zset 'seven' (integer)2 |
ZREMRANGEBYRANK zset 01 (integer)2 |
ZADD zset 1'twelve' (integer)1 ZSCORE zset 'twelve' '1' |