Redis hash and set-power node Java college collation

Time:2019-8-14

Redis hash values are a mapping between string fields and string values, so they are perfect data types representing objects in Redis and can store more than 40 billion key-value pairs.

Example


redis 127.0.0.1:6379> HMSET yiibai name "redis tutorial" description "redis basic commands for caching" likes 20 visitors 23000
OK
redis 127.0.0.1:6379> HGETALL yiibai

1) "name"
2) "redis tutorial"
3) "description"
4) "redis basic commands for caching"
5) "likes"
6) "20"
7) "visitors"
8) "23000"

In the example above, we have set up Redis’s detailed tutorial (name, description, likes, visitors) with the hash name yiibai.
Hash command of Redis
Hash some basic commands as shown in the following table:

list

The Redis list is a simple list of strings, sorted in insertion order. You can add elements to the list of Redis at the head or tail of the list.
The maximum length of the list is 232 – 1 (each list exceeds 4 billion elements 4294967295).

Example


redis 127.0.0.1:6379> LPUSH tutorials redis
(integer) 1
redis 127.0.0.1:6379> LPUSH tutorials mongodb
(integer) 2
redis 127.0.0.1:6379> LPUSH tutorials mysql
(integer) 3
redis 127.0.0.1:6379> LRANGE tutorials 0 10

1) "mysql"
2) "mongodb"
3) "redis"

The three values in the above example are inserted into the redis list named tutorials using the LPUSH command.

Redis command list

Some basic commands are listed as follows:

aggregate

Redis ordered collections are similar to Redis collections stored in set value uniqueness. The difference is that each member of an ordered set has a score, which is used to take the ordered set command, from the smallest to the largest.

Redis ordered set adds, deletes and tests O (1) existing members (fixed time, regardless of the number of elements contained in the set). The maximum length of the list is 232 – 1 elements (4294967295, a collection of more than 4 billion elements).

Example


redis 127.0.0.1:6379> ZADD tutorials 1 redis
(integer) 1
redis 127.0.0.1:6379> ZADD tutorials 2 mongodb
(integer) 1
redis 127.0.0.1:6379> ZADD tutorials 3 mysql
(integer) 1
redis 127.0.0.1:6379> ZADD tutorials 3 mysql
(integer) 0
redis 127.0.0.1:6379> ZADD tutorials 4 mysql
(integer) 0
redis 127.0.0.1:6379> ZRANGE tutorials 0 10 WITHSCORES

1) "redis"
2) "1"
3) "mongodb"
4) "2"
5) "mysql"
6) "4"

The three values in the above example are inserted by the command ZADD into the redis sorted set and named tutorials.

Redis Sort Command Set

The following table shows some basic commands with the sorting set:

Ordered set

Redis ordered collections are similar to Redis collections stored in set value uniqueness. The difference is that each member of an ordered set has a score, which is used to take the ordered set command, from the smallest to the largest.

Redis ordered set adds, deletes and tests O (1) existing members (fixed time, regardless of the number of elements contained in the set). The maximum length of the list is 232 – 1 elements (4294967295, a collection of more than 4 billion elements).

Example


redis 127.0.0.1:6379> ZADD tutorials 1 redis
(integer) 1
redis 127.0.0.1:6379> ZADD tutorials 2 mongodb
(integer) 1
redis 127.0.0.1:6379> ZADD tutorials 3 mysql
(integer) 1
redis 127.0.0.1:6379> ZADD tutorials 3 mysql
(integer) 0
redis 127.0.0.1:6379> ZADD tutorials 4 mysql
(integer) 0
redis 127.0.0.1:6379> ZRANGE tutorials 0 10 WITHSCORES

1) "redis"
2) "1"
3) "mongodb"
4) "2"
5) "mysql"
6) "4"

The three values in the above example are inserted by the command ZADD into the redis sorted set and named tutorials.

Redis Sort Command Set

The following table shows some basic commands with the sorting set:

The above is the whole content of this article. I hope it will be helpful to everyone’s study, and I hope you will support developpaer more.