Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Zset type and operation of Redis

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Zset is an ordered set of string types

Zadd: add the element member,score to the zset named key for sorting. If the element exists, its order is updated.

127.0.0.1 6379 > zadd myzset 1 one

(integer) 1

127.0.0.1 6379 > zadd myzset 2 two

(integer) 1

127.0.0.1 6379 > zadd myzset 3 two

(integer) 0

127.0.0.1 6379 > zrange myzset 0-1 withscores

1) "one"

2) "1"

3) "two"

4) "3"

Zrem: delete the element member in the zset named key.

127.0.0.1 6379 > zrange myzset 0-1 withscores

1) "one"

2) "1"

3) "two"

4) "3"

127.0.0.1 purl 6379 > zrem myzset two

(integer) 1

127.0.0.1 6379 > zrange myzset 0-1 withscores

1) "one"

2) "1"

Zincrby: if the element member already exists in the zset named key, the score of that element is incremented by increment, otherwise the element is added to the collection, and its score value is increment.

127.0.0.1 6379 > zadd myzset2 1 one

(integer) 1

127.0.0.1 6379 > zadd myzset2 2 two

(integer) 1

127.0.0.1 6379 > zrange myzset2 0-1 withscores

1) "one"

2) "1"

3) "two"

4) "2"

127.0.0.1 6379 > zincrby myzset2 2 one

"3"

127.0.0.1 6379 > zrange myzset2 0-1 withscores

1) "two"

2) "2"

3) "one"

4) "3"

Zrank: returns the ranking of the member element in the zset with the name key (sorted by score from smallest to largest), which is the subscript.

127.0.0.1 6379 > zadd myzset3 1 one

(integer) 1

127.0.0.1 6379 > zadd myzset3 2 two

(integer) 1

127.0.0.1 6379 > zadd myzset3 3 three

(integer) 1

127.0.0.1 6379 > zadd myzset3 5 five

(integer) 1

127.0.0.1 6379 > zrange myzset3 0-1 withscores

1) "one"

2) "1"

3) "two"

4) "2"

5) "three"

6) "3"

7) "five"

8) "5"

127.0.0.1 purl 6379 > zrank myzset3 two

(integer) 1

127.0.0.1 purl 6379 > zrank myzset3 three

(integer) 2

Zrevrank: returns the ranking of the member element in the zset named key (sorted by score from largest to smallest), that is, the subscript

127.0.0.1 6379 > zrange myzset3 0-1 withscores

1) "one"

2) "1"

3) "two"

4) "2"

5) "three"

6) "3"

7) "five"

8) "5"

127.0.0.1 purl 6379 > zrevrank myzset3 five

(integer) 0

Zrevrange:

127.0.0.1 6379 > zrange myzset3 0-1 withscores

1) "one"

2) "1"

3) "two"

4) "2"

5) "three"

6) "3"

7) "five"

8) "5"

127.0.0.1 6379 > zrevrange myzset3 0-1 withscores

1) "five"

2) "5"

3) "three"

4) "3"

5) "two"

6) "2"

7) "one"

8) "1"

Zrangebyscore:

127.0.0.1 6379 > zrangebyscore myzset3 2 3 withscores

1) "two"

2) "2"

3) "three"

4) "3"

Zcount:

127.0.0.1 6379 > zrange myzset3 0-1 withscores

1) "one"

2) "1"

3) "two"

4) "2"

5) "three"

6) "3"

7) "five"

8) "5"

127.0.0.1 zcount myzset3 6379 > 1 3

(integer) 2

Zcard:

127.0.0.1 6379 > zrange myzset3 0-1 withscores

1) "one"

2) "1"

3) "two"

4) "2"

5) "three"

6) "3"

7) "five"

8) "5"

127.0.0.1 purl 6379 > zcard myzset3

(integer) 4

Zremrangebyrank: deletes elements in the collection that rank in a given interval.

127.0.0.1 6379 > zrange myzset3 0-1 withscores

1) "one"

2) "1"

3) "two"

4) "2"

5) "three"

6) "3"

7) "five"

8) "5"

127.0.0.1 zremrangebyrank myzset3 6379 > 1 1

(integer) 1

127.0.0.1 6379 > zrange myzset3 0-1 withscores

1) "one"

2) "1"

3) "three"

4) "3"

5) "five"

6) "5"

Zremrangbyscore:

127.0.0.1 6379 > zrange myzset3 0-1 withscores

1) "one"

2) "1"

3) "three"

4) "3"

5) "five"

6) "5"

127.0.0.1 6379 > zremrangebyscore myzset3 4 5

(integer) 1

127.0.0.1 6379 > zrange myzset3 0-1 withscores

1) "one"

2) "1"

3) "three"

4) "3"

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report