集合为不重复的列表

无序集合

sadd(name,values):在name对应的集合中添加元素

smembers(name):获取name对应的集合的所有成员

127.0.0.1:6379> sadd name john jack jack andy
(integer) 3
127.0.0.1:6379> smembers name
1) "andy"
2) "john"
3) "jack"

scard(name):获取name对应的集合中元素个数

127.0.0.1:6379> smembers name
1) "andy"
2) "john"
3) "jack"
127.0.0.1:6379> scard name
(integer) 3

sdiff(keys, *args):在第一个name对应的集合中且不在其他name对应的集合的元素集合

127.0.0.1:6379> smembers name
1) "andy"
2) "john"
3) "css"
4) "jack"
5) "php"
127.0.0.1:6379> smembers web
1) "php"
2) "javascript"
3) "css"
4) "html"
127.0.0.1:6379> sdiff name web
1) "andy"
2) "john"
3) "jack"

sdiffstore(dest, keys, *args):获取第一个name对应的集合中且不在其他name对应的集合,再将其添加到dest对应的集合中

127.0.0.1:6379> smembers name
1) "andy"
2) "john"
3) "css"
4) "jack"
5) "php"
127.0.0.1:6379> smembers web
1) "php"
2) "javascript"
3) "css"
4) "html"
127.0.0.1:6379> sdiffstore name_web name web
(integer) 3
127.0.0.1:6379> smembers name_web
1) "andy"
2) "john"
3) "jack"

sismember(name, value):检查value是否是name对应的集合的成员

127.0.0.1:6379> smembers web
1) "php"
2) "javascript"
3) "css"
4) "html"
127.0.0.1:6379> sismember web asp
(integer) 0
127.0.0.1:6379> sismember web php
(integer) 1

smove(src, dst, value):将某个成员从一个集合中移动到另外一个集合,src为被移动成员的集合,移动成员到dst集合

127.0.0.1:6379> smembers name
1) "andy"
2) "john"
3) "jack"
127.0.0.1:6379> smembers web
1) "php"
2) "javascript"
3) "css"
4) "html"
127.0.0.1:6379> smove web name php
(integer) 1
127.0.0.1:6379> smembers name
1) "php"
2) "andy"
3) "john"
4) "jack"
127.0.0.1:6379> smembers web
1) "javascript"
2) "css"
3) "html"

spop(name):从集合的右侧(尾部)返回并移除一个成员

127.0.0.1:6379> smembers name
1) "php"
2) "andy"
3) "john"
4) "jack"
127.0.0.1:6379> spop name
"jack"
127.0.0.1:6379> smembers name
1) "php"
2) "andy"
3) "john"

srandmember(name, numbers):从name对应的集合中随机获取 numbers 个元素

127.0.0.1:6379> smembers web
1) "php"
2) "html"
3) "css"
4) "aspx"
5) "asp"
6) "ajax"
7) "javascript"
127.0.0.1:6379> srandmember web 2
1) "ajax"
2) "javascript"
127.0.0.1:6379> srandmember web 5
1) "html"
2) "css"
3) "aspx"
4) "javascript"
5) "ajax"

srem(name, values):在name对应的集合中删除某些值

127.0.0.1:6379> smembers web
1) "php"
2) "html"
3) "css"
4) "aspx"
5) "asp"
6) "ajax"
7) "javascript"
127.0.0.1:6379> srem web aspx
(integer) 1
127.0.0.1:6379> smembers web
1) "php"
2) "html"
3) "css"
4) "asp"
5) "ajax"
6) "javascript"

sinter(keys, *args):获取name对应集合的并集

sinterstore(dest, keys, *args):获取name对应集合的并集,并讲结果保存到dest对应的集合中

127.0.0.1:6379> smembers name
1) "jack"
2) "andy"
3) "php"
4) "john"
5) "jane"
6) "html"
7) "css"
127.0.0.1:6379> smembers web
1) "php"
2) "html"
3) "css"
4) "asp"
5) "ajax"
6) "javascript"
127.0.0.1:6379> sinter web name
1) "php"
2) "html"
3) "css"
127.0.0.1:6379> sinterstore web_name web name
(integer) 3
127.0.0.1:6379> smembers web_name
1) "php"
2) "css"
3) "html"

sunion(keys, *args):获取name对应的集合的并集

sunionstore(dest,keys, *args):获取name对应的集合的并集,并将结果保存到dest对应的集合中

127.0.0.1:6379> smembers name
1) "andy"
2) "php"
3) "john"
4) "jane"
5) "html"
6) "css"
7) "jack"
127.0.0.1:6379> smembers web
1) "php"
2) "html"
3) "css"
4) "asp"
5) "ajax"
6) "javascript"
127.0.0.1:6379> sunion name web
1) "john"
2) "jane"
3) "css"
4) "html"
5) "jack"
6) "asp"
7) "andy"
8) "javascript"
9) "ajax"
10) "php"
127.0.0.1:6379> sunionstore name_web name web
(integer) 10
127.0.0.1:6379> smembers name_web
1) "john"
2) "jane"
3) "css"
4) "html"
5) "jack"
6) "asp"
7) "andy"
8) "javascript"
9) "ajax"
10) "php"

sscan(name, cursor=0, match=None, count=None):匹配name对应的集合中的value

sscan_iter(name, match=None, count=None):为迭代匹配name对应的集合中的value

127.0.0.1:6379> smembers name_web
1) "john"
2) "jane"
3) "css"
4) "html"
5) "jack"
6) "asp"
7) "andy"
8) "javascript"
9) "ajax"
10) "php"
127.0.0.1:6379> sscan name_web 0 match j*
1) "7"
2) 1) "javascript"
2) "john"
3) "jane"
4) "jack"

有序集合

有序集合中每一个元素有一个值和一个分数,分数专门用来排序

zadd(name, *args, **kwargs):在name对应的有序集合中添加元素

zrange( name, start, end, desc=False, withscores=False, score_cast_func=float):按照索引范围获取name对应的有序集合的元素,start为有序集合索引起始位置(非分数),end为有序集合索引结束位置(非分数),desc为排序规则,默认按照分数从小到大排序,withscores为是否获取元素的分数,默认只获取元素的值,score_cast_func为对分数进行数据转换的函数
zrevrange(name, start, end, withscores=False, score_cast_func=float):从大到小排序

127.0.0.1:6379> zadd web 3 html 7 css 12 javascript 4 php
(integer) 4
127.0.0.1:6379> zrange web 0 -1 withscores
1) "html"
2) "3"
3) "php"
4) "4"
5) "css"
6) "7"
7) "javascript"
8) "12"
127.0.0.1:6379> zrevrange web 0 -1 withscores
1) "javascript"
2) "12"
3) "css"
4) "7"
5) "php"
6) "4"
7) "html"
8) "3"

zrangebyscore(name, min, max, start=None, num=None, withscores=False, score_cast_func=float):按照分数范围获取name对应的有序集合的元素,从小到大排序

zrevrangebyscore(name, max, min, start=None, num=None, withscores=False, score_cast_func=float):按照分数范围获取name对应的有序集合的元素,从大到小排序

127.0.0.1:6379> zadd web 3 html 7 css 12 javascript 4 php 15 asp 6 aspx
(integer) 6
127.0.0.1:6379> zrangebyscore web 0 5
1) "html"
2) "php"
127.0.0.1:6379> zrevrangebyscore web 20 10
1) "asp"
2) "javascript"

zcard(name):获取name对应的有序集合元素的数量

127.0.0.1:6379> zadd web 3 html 7 css 12 javascript 4 php 15 asp 6 aspx
(integer) 6
127.0.0.1:6379> zcard web
(integer) 6

zcount(name, min, max):获取name对应的有序集合中分数在min到max之间的个数

127.0.0.1:6379> zadd web 3 html 7 css 12 javascript 4 php 15 asp 6 aspx
(integer) 6
127.0.0.1:6379> zcount web 10 20
(integer) 2

zincrby(name, amount, value):自增name对应的有序集合中value对应的分数

127.0.0.1:6379> zrange web 0 -1 withscores
1) "html"
2) "3"
3) "php"
4) "4"
5) "aspx"
6) "6"
7) "css"
8) "7"
9) "javascript"
10) "12"
11) "asp"
12) "15"
127.0.0.1:6379> zincrby web 2 css
"9"
127.0.0.1:6379> zrange web 0 -1 withscores
1) "html"
2) "3"
3) "php"
4) "4"
5) "aspx"
6) "6"
7) "css"
8) "9"
9) "javascript"
10) "12"
11) "asp"
12) "15"

zrank(name, value):获取name对应的有序集合中value的排行,从小到大排序,第一位为0

zrevrank(name, value):获取name对应的有序集合中value的排行,从大到小排序,第一位为0

127.0.0.1:6379> zrange web 0 -1 withscores
1) "html"
2) "3"
3) "php"
4) "4"
5) "aspx"
6) "6"
7) "css"
8) "9"
9) "javascript"
10) "12"
11) "asp"
12) "15"
127.0.0.1:6379> zrank web php
(integer) 1
127.0.0.1:6379> zrevrank web php
(integer) 4

zrem(name, values):删除name对应的有序集合中的values

127.0.0.1:6379> zrange web 0 -1 withscores
1) "html"
2) "3"
3) "php"
4) "4"
5) "aspx"
6) "6"
7) "css"
8) "9"
9) "javascript"
10) "12"
11) "asp"
12) "15"
127.0.0.1:6379> zrem web aspx css
(integer) 2
127.0.0.1:6379> zrange web 0 -1 withscores
1) "html"
2) "3"
3) "php"
4) "4"
5) "javascript"
6) "12"
7) "asp"
8) "15"

zremrangebyrank(name, min, max): 根据排行范围删除

127.0.0.1:6379> zrange web 0 -1 withscores
1) "html"
2) "3"
3) "php"
4) "4"
5) "aspx"
6) "6"
7) "css"
8) "7"
9) "javascript"
10) "12"
11) "asp"
12) "15"
127.0.0.1:6379> zremrangebyrank web 0 2
(integer) 3
127.0.0.1:6379> zrange web 0 -1 withscores
1) "css"
2) "7"
3) "javascript"
4) "12"
5) "asp"
6) "15"

zremrangebyscore(name, min, max): 根据分数范围删除

127.0.0.1:6379> zrange web 0 -1 withscores
1) "html"
2) "3"
3) "php"
4) "4"
5) "aspx"
6) "6"
7) "css"
8) "7"
9) "javascript"
10) "12"
11) "asp"
12) "15"
127.0.0.1:6379> zremrangebyscore web 0 5
(integer) 2
127.0.0.1:6379> zrange web 0 -1 withscores
1) "aspx"
2) "6"
3) "css"
4) "7"
5) "javascript"
6) "12"
7) "asp"
8) "15"

zscore(name, value):获取name对应的有序集合中value对应的分数

127.0.0.1:6379> zrange web 0 -1 withscores
1) "aspx"
2) "6"
3) "css"
4) "7"
5) "javascript"
6) "12"
7) "asp"
8) "15"
127.0.0.1:6379> zscore web css
"7"

zinterstore(dest, number, keys, aggregate=None):获取number个有序集合的交集,并存入到dest集合中,如果遇到相同值不同分数,则按照aggregate进行操作,aggregate的值为:SUM,MIN,MAX

127.0.0.1:6379> zrange web 0 -1 withscores
1) "html"
2) "3"
3) "php"
4) "4"
5) "aspx"
6) "6"
7) "css"
8) "7"
9) "javascript"
10) "12"
11) "asp"
12) "15"
127.0.0.1:6379> zrange name 0 -1 withscores
1) "john"
2) "3"
3) "jane"
4) "7"
5) "php"
6) "9"
7) "jack"
8) "12"
9) "andy"
10) "17"
11) "css"
12) "32"
127.0.0.1:6379> zinterstore web_name 2 web name
(integer) 2
127.0.0.1:6379> zrange web_name 0 -1 withscores
1) "php"
2) "13"
3) "css"
4) "39"

zunionstore(dest, number, keys, aggregate=None):获取number个有序集合的并集,如果遇到相同值不同分数,则按照aggregate进行操作,aggregate的值为:SUM,MIN,MAX

127.0.0.1:6379> zrange web 0 -1 withscores
1) "html"
2) "3"
3) "php"
4) "4"
5) "aspx"
6) "6"
7) "css"
8) "7"
9) "javascript"
10) "12"
11) "asp"
12) "15"
127.0.0.1:6379> zrange name 0 -1 withscores
1) "john"
2) "3"
3) "jane"
4) "7"
5) "php"
6) "9"
7) "jack"
8) "12"
9) "andy"
10) "17"
11) "css"
12) "32"
127.0.0.1:6379> zunionstore web_name 2 web name
(integer) 10
127.0.0.1:6379> zrange web_name 0 -1 withscores
1) "html"
2) "3"
3) "john"
4) "3"
5) "aspx"
6) "6"
7) "jane"
8) "7"
9) "jack"
10) "12"
11) "javascript"
12) "12"
13) "php"
14) "13"
15) "asp"
16) "15"
17) "andy"
18) "17"
19) "css"
20) "39"

zscan(name, cursor=0, match=None, count=None, score_cast_func=float):匹配name对应的有序集合中的value

zscan_iter(name, match=None, count=None,score_cast_func=float):迭代匹配

127.0.0.1:6379> zrange web 0 -1 withscores
1) "html"
2) "3"
3) "php"
4) "4"
5) "aspx"
6) "6"
7) "css"
8) "7"
9) "javascript"
10) "12"
11) "asp"
12) "15"
127.0.0.1:6379> zscan web 0 match *a*
1) "0"
2) 1) "aspx"
2) "6"
3) "javascript"
4) "12"
5) "asp"
6) "15"

Python-Redis的Set操作的更多相关文章

  1. python之redis和memcache操作

    Redis 教程 Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理.Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据 ...

  2. python对redis的常用操作 上 (对列表、字符串、散列结构操作)

    这里的一切讨论均基于python的redis-py库. 安装使用: pip install redis 然后去获取一个redis客户端: redis_conn = redis.Redis(host=R ...

  3. Python redis 简单介绍

    Python redis 简单介绍 1.安装 终端输入: pip(or)pip3.6 install redis 安装成功 2.哈哈,发现我并没有redis服务可以访问,所以到这里,在本机安装了red ...

  4. 生产消费者模式与python+redis实例运用(基础篇)

    根据这个图,我们举个简单的例子:假如你去某个餐厅吃饭,点了很多菜,厨师要一个一个菜的做,一个厨师不可能同时做出所有你点的菜,于是你有两个选择:第一个,厨师把所有菜都上齐了,你才开始吃:还有一个选择,做 ...

  5. python -- redis连接与使用

    前面我们简单介绍了redis nosql数据库,现在我们在python里面来使用redis. 一.python连接redis 在python中,要操作redis,目前主要是通过一个python-red ...

  6. windows中实现python,redis服务自动重启(任务计划程序+bat脚本)

    需求:银行电脑无法自动开机,只能 通过 应用相关服务每天自动重启的方式实现 服务更新并且防止服务假死,内存过大 等情况 相关工具:win10系统中,使用windows自带的任务计划程序 和 bat脚本 ...

  7. python redis分布式锁改进

    0X01 python redis分布式锁通用方法 REDIS分布式锁实现的方式:SETNX + GETSET 使用Redis SETNX 命令实现分布式锁 python 版本实现上述思路(案例1) ...

  8. python redis之连接池的原理

    python redis之连接池的原理 转载地址 什么是连接池 通常情况下, 当我们需要做redis操作时, 会创建一个连接, 并基于这个连接进行redis操作, 操作完成后, 释放连接, 一般情况下 ...

  9. Redis数据类型及其操作

    redis数据类型即操作 1. 字符串 set 设置字符串 格式: set key value 例子: set name kainhuck get 获取字符串的值 格式: get key 例子: ge ...

  10. redis的一些操作

    public class WnsRedisFactory { private static Cache pool = null; private static JedisConnectionFacto ...

随机推荐

  1. Java找出一组数字的最大值

    形如:int [] nums = {7,2,8,9,1,12}; 解一:两两比较并记录下标,下次比较拿上次比较的最大值和上次比较的下一个进行比较,循环一次找出最大值 /** * @author 马向峰 ...

  2. ALV行 列颜色设置

    ALV的颜色设置分为3种:行.列.单元格.   1.列颜色的设置   在 slis_t_fieldcat_alv-emphasize 中,写入需要的颜色代码.   Eg:   DATA: fc TYP ...

  3. 工作中你肯定会有关于 Yii2 的小贴士用法,在下面评论分享出来吧。

    场景: 数据库有user表有个avatar_path字段用来保存用户头像路径 需求: 头像url需要通过域名http://b.com/作为基本url 目标: 提高代码复用 此处http://b.com ...

  4. Data Structure Linked List: Merge Sort for Linked Lists

    http://www.geeksforgeeks.org/merge-sort-for-linked-list/ #include <iostream> #include <vect ...

  5. JavaScript 从对象 new 说起,简单理解 this/call/apply

    new  创建一个新对象: 将构造函数的作用域赋给新对象(因此this就指向了这个新对象): 执行构造函数中的代码(为这个新对象添加属性): 返回新对象 用代码描述的话(先别管proyotype, a ...

  6. STL 之map解决 Message Flood(原字典树问题)

                                                                                      Message Flood Time ...

  7. form表单验证失败,阻止表单提交

    form表单验证失败,阻止表单提交 效果演示: 贴上完整代码: <!DOCTYPE html> <html lang="en"> <head> ...

  8. 简洁的支持展开关闭的tab标签代码

    简洁的支持展开关闭的tab标签代码,由huiyi8素材网提供. TAB标签代码下载:http://www.huiyi8.com/tab/

  9. java客户端文件的上传和下载

    java客户端文件的上传和下载 //上传 public JTable upload(String id){ JTable table=new JTable(); System.out.println( ...

  10. JavaWeb中文件的上传和下载

    JavaWeb中文件的上传和下载 转自: JavaWeb学习总结(五十)——文件上传和下载 - 孤傲苍狼 - 博客园https://www.cnblogs.com/xdp-gacl/p/4200090 ...