There are 5 types of data types:
Strings:
Redis string is a sequence of bytes. Strings in Redis are binary safe, having fixed length, So, one can store anything up to 512 megabytes in one string.
127.0.0.1:6379> SET name "Dinesh Sachdev"
OK
127.0.0.1:6379> get name
"Dinesh Sachdev"
Hashes:
It is a collection of key value pairs. Every hash can store up to 232 - 1 field-value pairs (more than 4 billion).
127.0.0.1:6379> HMSET user:1 username dineshSachdev password dinesh123 address 123
OK
127.0.0.1:6379> HGETALL user:1
1) "username"
2) "dineshSachdev"
3) "password"
4) "dinesh123"
5) "address"
6) "123"
127.0.0.1:6379> HGET user:1 username
"dineshSachdev"
127.0.0.1:6379> HGET user:1 password
"dinesh123"
Lists:
Redis Lists are simply lists of strings, sorted by insertion order. You can add elements to a Redis List on the head or on the tail.
127.0.0.1:6379> LPUSH mylist redis
(integer) 1
127.0.0.1:6379> RPUSH mylist dinesh
(integer) 3
127.0.0.1:6379> LRANGE mylist 0 10
1) "dinesh"
2) "redis"
3) "dinesh"
The max length of a list is 232 - 1 elements.
Sets:
Sets are an unordered collection of unique Strings
127.0.0.1:6379> sadd myset dineshset1
(integer) 1
127.0.0.1:6379> sadd myset dineshset2
(integer) 1
127.0.0.1:6379> sadd myset dineshset3
(integer) 1
127.0.0.1:6379> SMEMBERS myset
1) "dineshset2"
2) "dineshset1"
3) "dineshset3"
127.0.0.1:6379> SREM myset dineshset1
(integer) 1
127.0.0.1:6379> SMEMBERS myset
1) "dineshset2"
2) "dineshset3"
The max number of members in a set is 232 - 1
Sorted Sets:
Non repeating collections of Strings. The difference between Set and Sorted Set is that every member is associated with score, that is used in order to take the sorted set ordered, from the smallest to the greatest score. While members are unique, scores may be repeated.
127.0.0.1:6379> ZADD mysortedset 0 dinesh
(integer) 1
127.0.0.1:6379> ZADD mysortedset 1 dinesh
(integer) 0
127.0.0.1:6379> ZADD mysortedset 1 ABC
(integer) 1
127.0.0.1:6379> ZADD mysortedset 2 ZBC
(integer) 1
127.0.0.1:6379> ZRANGEBYSCORE mysortedset 0 10
1) "ABC"
2) "dinesh"
3) "ZBC"
Strings:
Redis string is a sequence of bytes. Strings in Redis are binary safe, having fixed length, So, one can store anything up to 512 megabytes in one string.
127.0.0.1:6379> SET name "Dinesh Sachdev"
OK
127.0.0.1:6379> get name
"Dinesh Sachdev"
Hashes:
It is a collection of key value pairs. Every hash can store up to 232 - 1 field-value pairs (more than 4 billion).
127.0.0.1:6379> HMSET user:1 username dineshSachdev password dinesh123 address 123
OK
127.0.0.1:6379> HGETALL user:1
1) "username"
2) "dineshSachdev"
3) "password"
4) "dinesh123"
5) "address"
6) "123"
127.0.0.1:6379> HGET user:1 username
"dineshSachdev"
127.0.0.1:6379> HGET user:1 password
"dinesh123"
Lists:
Redis Lists are simply lists of strings, sorted by insertion order. You can add elements to a Redis List on the head or on the tail.
127.0.0.1:6379> LPUSH mylist redis
(integer) 1
127.0.0.1:6379> RPUSH mylist dinesh
(integer) 3
127.0.0.1:6379> LRANGE mylist 0 10
1) "dinesh"
2) "redis"
3) "dinesh"
The max length of a list is 232 - 1 elements.
Sets:
Sets are an unordered collection of unique Strings
127.0.0.1:6379> sadd myset dineshset1
(integer) 1
127.0.0.1:6379> sadd myset dineshset2
(integer) 1
127.0.0.1:6379> sadd myset dineshset3
(integer) 1
127.0.0.1:6379> SMEMBERS myset
1) "dineshset2"
2) "dineshset1"
3) "dineshset3"
127.0.0.1:6379> SREM myset dineshset1
(integer) 1
127.0.0.1:6379> SMEMBERS myset
1) "dineshset2"
2) "dineshset3"
The max number of members in a set is 232 - 1
Sorted Sets:
Non repeating collections of Strings. The difference between Set and Sorted Set is that every member is associated with score, that is used in order to take the sorted set ordered, from the smallest to the greatest score. While members are unique, scores may be repeated.
127.0.0.1:6379> ZADD mysortedset 0 dinesh
(integer) 1
127.0.0.1:6379> ZADD mysortedset 1 dinesh
(integer) 0
127.0.0.1:6379> ZADD mysortedset 1 ABC
(integer) 1
127.0.0.1:6379> ZADD mysortedset 2 ZBC
(integer) 1
127.0.0.1:6379> ZRANGEBYSCORE mysortedset 0 10
1) "ABC"
2) "dinesh"
3) "ZBC"
Comments
Post a Comment