redis sorted_set 命令操作


score 是set排序的值,越大越在前
1.添加 成员到sorted_set中,并设置score
ZADD key score member [score member ...]
summary: Add one or more members to a sorted set, or update its score if it already exists
since: 1.2.0
127.0.0.1:6379> zadd sset1 2 val4
(integer) 1

2. 查询sorted_set的成员数量
ZCARD key
summary: Get the number of members in a sorted set
since: 1.2.0
127.0.0.1:6379> ZCARD sset1
(integer) 5

3.获取score在min和max之间的数量
ZCOUNT key min max
summary: Count the members in a sorted set with scores within the given values
since: 2.0.0
127.0.0.1:6379> ZCOUNT sset1 12 100
(integer) 2
127.0.0.1:6379> ZCOUNT sset1 0 200000
(integer) 5

4.增加sorted_set中成员的score
ZINCRBY key increment member
summary: Increment the score of a member in a sorted set
since: 1.2.0
127.0.0.1:6379> ZINCRBY sset1 30 val1
"52"

5.将key1和key2...中重复的值得结果存到des-key中,numkeys为源key的数量
ZINTERSTORE des-key numkeys key1 [key2 ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
summary: Intersect multiple sorted sets and store the resulting sorted set in a new key
since: 2.0.0
127.0.0.1:6379> ZINTERSTORE sset5 2 sset1 sset2
(integer) 3

6.获取sorted_set中index值在start和stop之间的值(包含首末值)
ZRANGE key start stop [WITHSCORES]
summary: Return a range of members in a sorted set, by index
since: 1.2.0

6.获取sorted_set中index值在min 和max之间的值(包含首末值)
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
summary: Return a range of members in a sorted set, by score
since: 1.0.5
127.0.0.1:6379> ZRANGEBYSCORE sset5 6 11
1) "val4"

7.获取成员的索引位置
ZRANK key member
summary: Determine the index of a member in a sorted set
since: 2.0.0
127.0.0.1:6379> ZRANK sset5 val3
(integer) 2
127.0.0.1:6379> ZRANGE sset5 0 10
1) "val4"
2) "val2"
3) "val3"

8.从sorted_set 中删除指定的成员(可多个)
ZREM key member [member ...]
summary: Remove one or more members from a sorted set
since: 1.2.0

9.删除index值在start和stop之间的成员
ZREMRANGEBYRANK key start stop
summary: Remove all members in a sorted set within the given indexes
since: 2.0.0

10.删除score值在min和max之间的成员
ZREMRANGEBYSCORE key min max
summary: Remove all members in a sorted set within the given scores
since: 1.2.0

11.返回指定index在start和stop之间,并按score从高到底低排序
ZREVRANGE key start stop [WITHSCORES]
summary: Return a range of members in a sorted set, by index, with scores ordered from high to low
since: 1.2.0
127.0.0.1:6379> ZREVRANGE sset5 0 2
1) "val3"
2) "val2"
3) "val4"

12.返回指定score在min和max之间,并按score从高到底低排序
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
summary: Return a range of members in a sorted set, by score, with scores ordered from high to low
since: 2.2.0

13.获取成员的索引位置,并按score从高到低排序
ZREVRANK key member
summary: Determine the index of a member in a sorted set, with scores ordered from high to low
since: 2.0.0

14.获取指定成员的score
ZSCORE key member
summary: Get the score associated with the given member in a sorted set
since: 1.2.0

127.0.0.1:6379> ZSCORE sset5 val2
"12"

15.连sorted_key显示结果,并将显示结果放到目标key中,numkeys代表源key的数目
ZUNIONSTORE des-key numkeys key1 [key2 ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
summary: Add multiple sorted sets and store the resulting sorted set in a new key
since: 2.0.0

时间: 2024-12-26 22:40:20

redis sorted_set 命令操作的相关文章

redis hash命令操作

/*********redis hash命令操作 **********/ 1.删除一个或多个hash域 HDEL key field [field ...] summary: Delete one or more hash fields since: 2.0.0 127.0.0.1:6379> HDEL hash1 name (integer) 1 2.判断一个域是否存在 HEXISTS key field summary: Determine if a hash field exists si

Redis——常用命令操作

 一,启动   Centos6       进入到redis安装目录: cd redis-2.8.17     进入src目录: cd src     启动server:  ./redis-server    使用配置文件启动: ./redis-serverredis.conf      Ubuntu 启动server:redis-server 启动客户端:redis-cli    Windows   redis-cli.exe-h 127.0.0.1 -p 6379 二,使用命令对Redis基

redis set命令操作

1.添加一个或多个成员到set SADD key member [member ...] summary: Add one or more members to a set since: 1.0.0 127.0.0.1:6379> sadd set1 val1 val2 val3 (integer) 3 2.获取一个set的成员数量 SCARD key summary: Get the number of members in a set since: 1.0.0 127.0.0.1:6379>

redis list命令操作

1.将值追加到列表 RPUSH key value [value ...] summary: Append one or multiple values to a list since: 1.0.0 127.0.0.1:6379> RPUSH mylist value1 value2 value3 (integer) 3 2.获取列表的长度 LLEN key summary: Get the length of a list since: 1.0.0 127.0.0.1:6379> llen

redis transaction和connection命令操作

/*********** redis transaction命令操作 **********/ 1. DISCARD - summary: Discard all commands issued after MULTI since: 2.0.0 EXEC - summary: Execute all commands issued after MULTI since: 1.2.0 MULTI - summary: Mark the start of a transaction block sinc

redis server和scripting 命令操作

/********* redis server命令操作 *************/ BGREWRITEAOF - summary: Asynchronously rewrite the append-only file since: 1.0.0 BGSAVE - summary: Asynchronously save the dataset to disk since: 1.0.0 CLIENT GETNAME - summary: Get the current connection na

redis命令操作之generic和string.java

redis是键值对的内存数据库,属于Nosql范畴 登录redis自带的客户端 #redis-cli 127.0.0.1:6379> 1.设置redis 键值对 > set foo bar  #设置键foo的值为"bar" OK #设置成功 2.获得redis 键值对 > get foo #根据键获得值 "bar" #返回的结果 3.删除键值对  127.0.0.1:6379> del foo foo2 foo3 #删除键值对,可删除多个 (

第2讲 Redis常用命令与高级应用

目录 一.redis数据类型 5. sorted sets类型和操作 二.Redis常用命令 1.键值相关命令 2.服务器相关命令 三. redis高级应用 1. 给redis服务器设置密码 2.持久化 3.主从备份 一.redis数据类型 5. sorted sets类型和操作 sorted set是set的一个升级版本,它给集合中每个元素都定义一个分数,集合中的元素按照其分数排序. 1) zadd 键 分数1 值1 [分数2 值2-] 该命令添加指定的成员到key对应的有序集合中,每个成员都

redis-Ubuntu server 15.0.4安装Redis make命令不能执行

问题描述 Ubuntu server 15.0.4安装Redis make命令不能执行 按照官方的下载安装指导:http://redis.io/download#installation Download, extract and compile Redis with: $ wget http://download.redis.io/releases/redis-3.0.3.tar.gz $ tar xzf redis-3.0.3.tar.gz $ cd redis-3.0.3 $ make T