ZADD key score member [score member ...]

Add one or more members to a sorted set, or update its score if it already exists

127.0.0.1:6379> ZADD foo 1 one
(integer) 1
127.0.0.1:6379> ZADD foo 2 two
(integer) 1
127.0.0.1:6379> ZADD foo 3 three
(integer) 1
127.0.0.1:6379> ZRANGE foo 0 -1
1) "one"
2) "two"
3) "three"

More: http://redis.io/commands/zaddhttp://www.redis.cn/commands/zadd.html

ZCARD key

Get the number of members in a sorted set

127.0.0.1:6379> ZRANGE foo 0 -1
1) "one"
2) "two"
3) "three"
127.0.0.1:6379> ZCARD foo
(integer) 3
127.0.0.1:6379> ZRANGE none 0 -1
(empty list or set)
127.0.0.1:6379> ZCARD none
(integer) 0

More: http://redis.io/commands/zcardhttp://www.redis.cn/commands/zcount.html

ZCOUNT key min max

Count the members in a sorted set with scores within the given values

127.0.0.1:6379> ZADD foo 90 A 80 B 70 C 60 D
(integer) 4
127.0.0.1:6379> ZCOUNT foo 70 80
(integer) 2
127.0.0.1:6379> ZCOUNT foo (70 80
(integer) 1
127.0.0.1:6379> ZCOUNT foo 70 (80
(integer) 1

More: http://redis.io/commands/zcounthttp://www.redis.cn/commands/zcount.html

ZINCRBY key increment member

Increment the score of a member in a sorted set

127.0.0.1:6379> ZADD foo 1 a 2 b
(integer) 2
127.0.0.1:6379> ZINCRBY foo 2 a
"3"
127.0.0.1:6379> ZRANGE foo 0 -1 WITHSCORES
1) "b"
2) "2"
3) "a"
4) "3"

More: http://redis.io/commands/zincrbyhttp://www.redis.cn/commands/zincrby.html

ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]

Intersect multiple sorted sets and store the resulting sorted set in a new key

127.0.0.1:6379> ZADD foo 1 a 2 b 3 c
(integer) 3
127.0.0.1:6379> ZADD bar 1 b 2 c 3 d
(integer) 3
127.0.0.1:6379> ZINTERSTORE result 2 foo bar
(integer) 2
127.0.0.1:6379> ZRANGE result 0 -1 WITHSCORES
1) "b"
2) "3"
3) "c"
4) "5"
127.0.0.1:6379> ZINTERSTORE result 2 foo bar AGGREGATE MAX
(integer) 2
127.0.0.1:6379> ZRANGE result 0 -1 WITHSCORES
1) "b"
2) "2"
3) "c"
4) "3"

More: http://redis.io/commands/zinterstorehttp://www.redis.cn/commands/zinterstore.html

ZLEXCOUNT key min max

Count the number of members in a sorted set between a given lexicographical range

127.0.0.1:6379> ZADD foo 0 r 0 e 0 d 0 i 0 s
(integer) 5
127.0.0.1:6379> ZRANGEBYLEX foo [d (i
1) "d"
2) "e"
127.0.0.1:6379> ZLEXCOUNT foo [d (i
(integer) 2

More: http://redis.io/commands/zlexcount

ZRANGE key start stop [WITHSCORES]

Return a range of members in a sorted set, by index

127.0.0.1:6379> ZADD foo 1 a 2 b 3 c 4 d
(integer) 4
127.0.0.1:6379> ZRANGE foo 0 -1
1) "a"
2) "b"
3) "c"
4) "d"
127.0.0.1:6379> ZRANGE foo 1 2 WITHSCORES
1) "b"
2) "2"
3) "c"
4) "3"

More: http://redis.io/commands/zrangehttp://www.redis.cn/commands/zrange.html

ZRANGEBYLEX key min max [LIMIT offset count]

Return a range of members in a sorted set, by lexicographical range

127.0.0.1:6379> ZADD foo 0 r 0 e 0 d 0 i 0 s
(integer) 5
127.0.0.1:6379> ZRANGEBYLEX foo [d (i
1) "d"
2) "e"

More: http://redis.io/commands/zrangebylex

ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]

Return a range of members in a sorted set, by score

127.0.0.1:6379> ZADD foo 1 a 2 b 3 c 4 d 5 e
(integer) 5
127.0.0.1:6379> ZRANGEBYSCORE foo -inf +inf
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"
127.0.0.1:6379> ZRANGEBYSCORE foo -inf +inf LIMIT 0 3
1) "a"
2) "b"
3) "c"
127.0.0.1:6379> ZRANGEBYSCORE foo 1 3 WITHSCORES
1) "a"
2) "1"
3) "b"
4) "2"
5) "c"
6) "3"
127.0.0.1:6379> ZRANGEBYSCORE foo (1 3
1) "b"
2) "c"
127.0.0.1:6379> ZRANGEBYSCORE foo 1 (3
1) "a"
2) "b"

More: http://redis.io/commands/zremrangebyscorehttp://www.redis.cn/commands/zrangebyscore.html

ZRANK key member
Determine the index of a member in a sorted set

127.0.0.1:6379> ZADD foo 1 a 2 b 2 c 3 d
(integer) 4
127.0.0.1:6379> ZRANK foo a
(integer) 0
127.0.0.1:6379> ZRANK foo b
(integer) 1
127.0.0.1:6379> ZRANK foo c
(integer) 2
127.0.0.1:6379> ZRANK foo e
(nil)

More: http://redis.io/commands/zrankhttp://www.redis.cn/commands/zrank.html

ZREM key member [member ...]

Remove one or more members from a sorted set

127.0.0.1:6379> ZADD foo 1 a 2 b 3 c 4 d
(integer) 4
127.0.0.1:6379> ZREM foo b d
(integer) 2
127.0.0.1:6379> ZRANGE foo 0 -1
1) "a"
2) "c"
127.0.0.1:6379> ZREM foo e
(integer) 0

More: http://redis.io/commands/zremhttp://www.redis.cn/commands/zrem.html

ZREMRANGEBYLEX key min max

Remove all members in a sorted set between the given lexicographical range

127.0.0.1:6379> ZADD foo 0 r 0 e 0 d 0 i 0 s
(integer) 5
127.0.0.1:6379> ZREMRANGEBYLEX foo [d (i
(integer) 2
127.0.0.1:6379> ZRANGE foo 0 -1
1) "i"
2) "r"
3) "s"

More: http://redis.io/commands/zremrangebylex

ZREMRANGEBYRANK key start stop

Remove all members in a sorted set within the given indexes

127.0.0.1:6379> ZADD foo 1 a 2 b 3 c 4 d 5 e
(integer) 5
127.0.0.1:6379> ZREMRANGEBYRANK foo 0 2
(integer) 3
127.0.0.1:6379> ZRANGE foo 0 -1 WITHSCORES
1) "d"
2) "4"
3) "e"
4) "5"

More: http://redis.io/commands/zremrangebyrankhttp://www.redis.cn/commands/zremrangebyrank.html

ZREMRANGEBYSCORE key min max

Remove all members in a sorted set within the given scores

127.0.0.1:6379> ZADD foo 1 a 2 b 3 c 4 d 5 e
(integer) 5
127.0.0.1:6379> ZREMRANGEBYSCORE foo 3 5
(integer) 3
127.0.0.1:6379> ZRANGE foo 0 -1 WITHSCORES
1) "a"
2) "1"
3) "b"
4) "2"

More: http://redis.io/commands/zremrangebyscorehttp://www.redis.cn/commands/zremrangebyscore.html

ZREVRANGE key start stop [WITHSCORES]

Return a range of members in a sorted set, by index, with scores ordered from high to low

127.0.0.1:6379> ZADD foo 1 a 2 b 3 c 4 d
(integer) 4
127.0.0.1:6379> ZREVRANGE foo 0 -1
1) "d"
2) "c"
3) "b"
4) "a"
127.0.0.1:6379> ZREVRANGE foo 0 1 WITHSCORES
1) "d"
2) "4"
3) "c"
4) "3"

More: http://redis.io/commands/zrevrangehttp://www.redis.cn/commands/zrevrange.html

ZREVRANGEBYLEX key max min [LIMIT offset count]

Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.

127.0.0.1:6379> ZADD foo 0 r 0 e 0 d 0 i 0 s
(integer) 5
127.0.0.1:6379> ZREVRANGEBYLEX foo (i [d
1) "e"
2) "d"

More: http://redis.io/commands/zrevrangebylex

ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]

Return a range of members in a sorted set, by score, with scores ordered from high to low

127.0.0.1:6379> ZADD foo 1 a 2 b 3 c 4 d
(integer) 4
127.0.0.1:6379> ZREVRANGEBYSCORE foo +inf -inf
1) "d"
2) "c"
3) "b"
4) "a"
127.0.0.1:6379> ZREVRANGEBYSCORE foo (3 1 WITHSCORES
1) "b"
2) "2"
3) "a"
4) "1"

More: http://redis.io/commands/zrevrangebyscorehttp://www.redis.cn/commands/zrevrangebyscore.html

ZREVRANK key member

Determine the index of a member in a sorted set, with scores ordered from high to low

127.0.0.1:6379> ZADD foo 1 a 2 b 3 c 2 d
(integer) 4
127.0.0.1:6379> ZREVRANK foo a
(integer) 3
127.0.0.1:6379> ZREVRANK foo b
(integer) 2
127.0.0.1:6379> ZREVRANK foo c
(integer) 0
127.0.0.1:6379> ZREVRANK foo d
(integer) 1

More: http://redis.io/commands/zrevrankhttp://www.redis.cn/commands/zrevrank.html

ZSCORE key member

Get the score associated with the given member in a sorted set

127.0.0.1:6379> ZADD foo 1 a 2 b 3 c 4 d
(integer) 4
127.0.0.1:6379> ZSCORE foo b
"2"
127.0.0.1:6379> ZSCORE foo e
(nil)

More: http://redis.io/commands/zscorehttp://www.redis.cn/commands/zscore.html

ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]

Add multiple sorted sets and store the resulting sorted set in a new key

127.0.0.1:6379> ZADD foo 1 a 2 b 3 c
(integer) 3
127.0.0.1:6379> ZADD bar 1 b 2 c 3 d
(integer) 3
127.0.0.1:6379> ZUNIONSTORE result 2 foo bar
(integer) 4
127.0.0.1:6379> ZRANGE result 0 -1 WITHSCORES
1) "a"
2) "1"
3) "b"
4) "3"
5) "d"
6) "3"
7) "c"
8) "5"
127.0.0.1:6379> ZUNIONSTORE result 2 foo bar AGGREGATE MIN
(integer) 4
127.0.0.1:6379> ZRANGE result 0 -1 WITHSCORES
1) "a"
2) "1"
3) "b"
4) "1"
5) "c"
6) "2"
7) "d"
8) "3"

More: http://redis.io/commands/zunionstorehttp://www.redis.cn/commands/zunionstore.html

ZSCAN key cursor [MATCH pattern] [COUNT count]

Incrementally iterate sorted sets elements and associated scores

More: http://redis.io/commands/zscanhttp://www.redis.cn/commands/sscan.html

Redis 命令 - Sorted Sets的更多相关文章

  1. redis的有序集合(Sorted Sets)数据类型

    和Sets相比,Sorted Sets增加了一个权重参数score,使得集合中的元素能够按score进行有序排列,比如一个存储全班同学成绩的Sorted Sets,其集合value可以是同学的学号,而 ...

  2. Redis数据类型:Sorted Sets操作指令

    Redis数据类型:Sorted Sets操作指令 Sorted Sets常用操作指令 Sorted Sets,本质是一个有序的Sets,其实在原来的Sets集合中对每一个元素新增了一个属性Score ...

  3. redis数据类型:sorted sets类型及操作

    sorted sets类型及操作: sorted set是set的一个升级版本,它是在set的基础上增加了一个顺序 属性,这一属性在添加修改元素的时候可以指定,每次指定后,zset会 自动重新按新的值 ...

  4. 常用 redis 命令(for php)

    Redis 主要能存储 5 种数据结构,分别是 strings,hashes,lists,sets 以及 sorted sets. 新建一个 redis 数据库 $redis = new Redis( ...

  5. redis windows下使用及redis命令

    出自:http://www.cnblogs.com/chenping-987123/archive/2012/01/29/2331079.html Redis 是一个开源,高级的键值对的存储.它经常作 ...

  6. redis命令大全

    redis windows下使用及redis命令 Redis 是一个开源,高级的键值对的存储.它经常作为服务端的数据结构,它的键的数据类型能够是strings, hashs, lists, sets( ...

  7. Redis详细讲解(Redis原理,Redis安装,Redis配置,Redis使用,Redis命令)

    一.Redis介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis的开发 ...

  8. redis 命令行 操作

    redis目前提供四种数据类型:string,list,set及zset(sorted set). * string是最简单的类型,你可以理解成与Memcached一模一个的类型,一个key对应一个v ...

  9. Redis 命令二

    一.连接控制 QUIT 关闭连接 AUTH (仅限启用时)简单的密码验证 二.适合全体类型的命令 EXISTS key 判断一个键是否存在;存在返回 1;否则返回0; DEL key 删除某个key, ...

随机推荐

  1. POJ 1751 Highways (kruskal)

    题目链接:http://poj.org/problem?id=1751 题意是给你n个点的坐标,然后给你m对点是已经相连的,问你还需要连接哪几对点,使这个图为最小生成树. 这里用kruskal不会超时 ...

  2. UVaLive 6628 Grachten (水题,数学)

    题意:给定一个平面图形并且且给了几条连,求一条. 析:简单么,三角形相似,很简单就AC. 代码如下: #pragma comment(linker, "/STACK:1024000000,1 ...

  3. UVaLive 7370 Classy (排序,比较)

    题意:给定 n 个人,和他们的数进行比较,从后面开始比,如果不够长,加middle接着比,直到没有,如果还相同比名字. 析:很水的题,就不用说了. 代码如下: #pragma comment(link ...

  4. UVALIVE 4970 最小权匹配

    首先贴一下这道题的BNU地址,UVA地址自己找吧. http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=11852 题意:这道题的意思就是,给你N个棋子的 ...

  5. 创建类模式(二):抽象工厂(Abstract Factory)

    定义 为创建一组相关或相互依赖的对象提供一个接口,而且无需指定他们的具体类. 抽象工厂模式是所有形态的工厂模式中最为抽象和最具一般性的一种形态.抽象工厂模式是指当有多个抽象角色时,使用的一种工厂模式. ...

  6. disque概要

    做项目过程接触到disque,记录一下. disque是redis之父开源的基于内存的分布式作业队列,用c语言实现的非阻塞网络服务器. disque的设计目标:Its goal is to captu ...

  7. IE 、Firefox、Chrome 浏览器在 F12 控制台下切换至不同框架介绍

    有不少网页的页面,还在使用 iframe 标签,而此时,相当于页面有两个 window 对象,一个为当前页面 window ,另一个则为 iframe 页面下的 window .因为,有时候需要在 c ...

  8. HCTF2016-杂项签到

    题目下载了一个+_+.pcapng ,用Wireshark打开, Ctrl-F搜索flag 发现python代码 将Data导出 #!/usr/bin/env python # coding:utf- ...

  9. Sonatype Nexus 搭建Maven 私服

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...

  10. 关于Token

    Token Token,即计算机术语:令牌 令牌是一种能够控制站点占有媒体的特殊帧,以区别数据帧及其他控制帧.token其实说的更通俗点可以叫暗号,在一些数据传输之前,要先进行暗号的核对,不同的暗号被 ...