Redis五大資料型別 ZSet常用命令(五)

2021-10-22 18:51:33 字數 1805 閱讀 6737

1、zadd和zrange命令

127.0.0.1:6379> zadd zset 1 one

(integer) 1

127.0.0.1:6379> zadd zset 2 two 3 three

(integer) 2

127.0.0.1:6379> zrange zset 0 -1

1)"one"

2)"two"

3)"three"

2、zrangebyscore 命令

127.0.0.1:6379> zadd salary 2500 zs

(integer) 1

127.0.0.1:6379> zadd salary 5000 ls

(integer) 1

127.0.0.1:6379> zadd salary 500 tb

(integer) 1

127.0.0.1:6379> zrangebyscore salary -inf +inf # 按照salary從小到大排序

1)"tb"

2)"zs"

3)"ls"

127.0.0.1:6379> zrangebyscore salary -inf +inf withscores # 按照salary從小到大排序,並且附帶對應的成績值

1)"tb"

2)"500"

3)"zs"

4)"2500"

5)"ls"

6)"5000"

127.0.0.1:6379> zrangebyscore salary -inf 3000 withscores # 按照salary從負無窮到3000之間的排序,並且附帶對應的成績值

3、zrem 和zcard 命令

127.0.0.1:6379> zrange salary 0 -1 # 顯示所有的字段

1)"tb"

2)"zs"

3)"ls"

127.0.0.1:6379> zrem salary tb # 移除指定的元素

(integer) 1

127.0.0.1:6379> zrange salary 0 -1

1)"zs"

2)"ls"

127.0.0.1:6379> zcard salary # 獲取所有欄位的個數

4、zrem 和zcard 命令

127.0.0.1:6379> zadd zset 1 one 2 twon 3 three

(integer) 3

127.0.0.1:6379> zcount zset 1 -3

(integer) 0

127.0.0.1:6379> zcount zset 1 3 # 獲取指定區間的成員的數量

Redis五大資料型別 Zset

向集合中增值 127.0.0.1 6379 zadd myset 1 one 新增乙個值 integer 1 127.0.0.1 6379 zadd myset 2 two 3 three 新增多個值 integer 2 127.0.0.1 6379 zrange myset 0 1 1 one 2...

Redis五大資料型別 Zset 有序集合

在set的基礎上,增加了乙個值,例如 總結就是,新增欄位的時候加乙個標誌 zadd key nx xx ch incr score member score member 127.0.0.1 6379 zadd zset 1 v1 integer 1 127.0.0.1 6379 zadd zset...

redis五大資料型別

redis支援五種資料型別 string 字串 hash 雜湊 list 列表 set 集合 及zset sorted set 有序集合 127.0 0.1 6379 set name yzl ok127.0 0.1 6379 get name yzl 127.0 0.1 6379 hmset my...