Redis之set类型操作
接口:
package com.net.test.redis.base.dao;
/**
* @author***
* @Time:2017年8月10日 下午2:32:12
* @version 1.0
* @description
*/
public interface IRedisDaoNoSotredSet { public void add(String key, String...values); public void diff(String key, String otherKey); public void diddStore(String destKey, String key, String otherKey); public void inter(String key, String otherKey); public void interStore(String destKey, String key, String otherKey); public void union(String key, String otherKey); public void unionStore(String destKey, String key, String otherKey); public void pop(String key); public void remove(String key,String...values); public void size(String key); public void smembers(String key); }
实现类:
package com.net.test.redis.base.dao.imp; import java.util.Set; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.stereotype.Repository; import com.net.test.redis.base.dao.IRedisDaoNoSotredSet; /**
* @author ***
* @Time:2017年8月10日 下午2:53:33
* @version 1.0
* @description
*/
@Repository
public class RedisDaoNoSotredSetImp implements IRedisDaoNoSotredSet{ @Autowired
private RedisTemplate<String, String> redis; /**
* @description 添加元素
* @param key
* @param values
*/
@Override
public void add(String key, String...values)
{
SetOperations<String, String> oper = redis.opsForSet();
int value = oper.add(key, values).intValue();
System.out.println("是否添加成功 :" + value);
} /**
* @description 找出两个集合不同的部分,并进行遍历
* @param key
* @param otherKey
*/
@Override
public void diff(String key, String otherKey)
{
SetOperations<String, String> oper = redis.opsForSet();
Set<String> set = oper.difference(key,otherKey);
for(String str : set)
{
System.out.println("两个set的不同元素 : " + str);
}
} /**
* @description 找出两个集合不同的部分,并存到destKey集合中
* @param destKey
* @param key
* @param otherKey
*/
@Override
public void diddStore(String destKey, String key, String otherKey)
{
SetOperations<String, String> oper = redis.opsForSet();
int value = oper.differenceAndStore(key, otherKey, destKey).intValue();
System.out.println("返回值 : " + value);
} /**
* @description 找出两个集合的相同部分,并进行遍历
* @param key
* @param otherKey
*/
@Override
public void inter(String key, String otherKey)
{
SetOperations<String, String> oper = redis.opsForSet();
Set<String> set = oper.intersect(key, otherKey);
for(String str : set)
{
System.out.println("两个set的相同元素 : " + str);
}
} /**
* @description 找出两个集合的相同部分,存到新集合destKey中
* @param destKey
* @param key
* @param otherKey
*/
@Override
public void interStore(String destKey, String key, String otherKey)
{
SetOperations<String, String> oper = redis.opsForSet();
int value = oper.intersectAndStore(key, otherKey, destKey).intValue();
System.out.println("返回值 : " + value);
} /**
* @description 找出兩個集合的并集,并進行遍歷
* @param key
* @param otherKey
*/
@Override
public void union(String key, String otherKey)
{
SetOperations<String, String> oper = redis.opsForSet();
Set<String> set = oper.union(key, otherKey);
for(String str : set)
{
System.out.println("两个set的相同元素 : " + str);
}
} /**
* @description 找出兩個集合的并集,并存放到新集合destKey中
* @param destKey
* @param key
* @param otherKey
*/
@Override
public void unionStore(String destKey, String key, String otherKey)
{
SetOperations<String, String> oper = redis.opsForSet();
int value = oper.unionAndStore(key, otherKey, destKey).intValue();
System.out.println("返回值 : " + value);
} /**
* @description 无序集合,随机移除一个元素
* @param key
*/
@Override
public void pop(String key)
{
SetOperations<String, String> oper = redis.opsForSet();
String value = oper.pop(key);
System.out.println("随机移除的value为 : " + value);
} /**
* @description 根据给定的元素,去移除
* @param key
* @param values
*/
@Override
public void remove(String key, String...values)
{
SetOperations<String, String> oper = redis.opsForSet();
int value = oper.remove(key, (Object[])values).intValue();
System.out.println("是否成功移除选定元素 : " + value);
} /**
* @description 获取集合长度
* @param key
*/
@Override
public void size(String key)
{
SetOperations<String, String> oper = redis.opsForSet();
int value = oper.size(key).intValue();
System.out.println("set 集合长度为 : " + value);
} /**
* @description 遍历整个集合
* @param key
*/
@Override
public void smembers(String key)
{
SetOperations<String, String> oper = redis.opsForSet();
Set<String> set = oper.members(key);
for(String str : set)
{
System.out.println("两个set的相同元素 : " + str);
}
} }
Redis之set类型操作的更多相关文章
- Redis之Hash类型操作
接口IRedisDaoHash: package com.net.test.redis.base.dao; import com.net.test.redis.base.entity.UserPsg; ...
- python之Redis的字符串类型操作
redis的数据类型: 字符串型 哈希 列表 集合 有序集合 1.String(字符串类型) set 命令: 设置一个键和值,键存在则只覆盖,返回ok > s ...
- Redis之String类型操作
接口IRedisDaoStr: package com.net.test.redis.base.dao; import java.util.List; import java.util.Map; /* ...
- Redis - sort set类型操作
sort set操作:sort set在set基础上增加了一列用于存储顺序序列设置操作:zadd key: zadd key sortnum value 指定key增加元素 ...
- Redis之List类型操作
接口: package com.net.test.redis.base.dao; import java.util.List; /** * @author *** * @Time:2017年8月10日 ...
- redis 的使用 ( set集合类型操作)
set 集合类型 释义: redis 的 set 是 string 类型的无序集合 set 元素最大可以包含(2的32次方-1)个元素 关于 set 集合类型除了基本的添加删除操 ...
- redis 的使用 ( list列表类型操作)
list 数据类型 列表类型 list 类型是一个双向操作 从链表的头部或者尾部添加删除元素 list 既可以用作栈 也可以用作队列 list 链表的类型应用场合: 获取最新的 10 个用户的信息 s ...
- redis 的使用 (基础, key操作, string类型操作)
使用redis set 类型: 没有重复元素 list 链表类型 有重复累型 sort set 类型 没有重复元素 1.1 存储数据 读取数据 // 数据储存在 内存中 set name laowen ...
- 第二百九十七节,python操作redis缓存-List类型,可以理解为列表
python操作redis缓存-List类型,可以理解为列表,是可以有重复元素的列表 List操作,redis中的List在在内存中按照一个name对应一个List来存储.如图: lpush(name ...
随机推荐
- Java文件与io——打印流和对象流
打印流的主要功能是用于输出,在整个IO包中打印流分为两种类型: 字节打印流:PrintStream 字符打印流:PrintWriter 打印流可以很方便的进行输出 public class Print ...
- java里如何使用输入流和输出流实现读取本地文件里内容和写出到本地文件里
不多说,直接上干货! 第一种方法 PWDemo.java package zhouls.bigdata.DataFeatureSelection.filter; import java.io.File ...
- struts2的执行流程
在浏览器端输入相应的访问地址>>>>把请求发送给tomact>>>>tomact判断应该交给那个webApplication>>>&g ...
- 谷歌插件 JSON-Handle
JSON-Handle http://jsonhandle.sinaapp.com/ 点击下载 插件下载后,在浏览器输入:chrome://extensions/ 将下载后的文件拖入 chrome浏览 ...
- Piwik-2.16.1 (OpenLogic CentOS7.2)
平台: CentOS 类型: 虚拟机镜像 软件包: centos7.2 piwik devops log analysis monitoring open-source 服务优惠价: 按服务商许可协议 ...
- Tomcat Stack-8.0.35 (OpenLogic CentOS7.2)
平台: CentOS 类型: 虚拟机镜像 软件包: apache2.4.20 mysql5.6.30 tomcat8.0.35 apache application server basic s ...
- linux 命令——55 traceroute(转)
通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径.当然每次数据包由某一同样的出发点(source)到达某一同样的目的地(destination)走的路径可能会不一 ...
- 【转】操作系统Unix、Windows、Mac OS、Linux的故事
电脑,计算机已经成为我们生活中必不可少的一部分.无论是大型的超级计算机,还是手机般小巧的终端设备,都跑着一个操作系统.正是这些操作系统,让那些硬件和芯片得意组合起来,让那些软件得以运行,让我们的世界在 ...
- 跑rbgirshick的fast-rcnn代码
需要安装Caffe.pycaffe cython.python-opencv.easydict matlab(主要用于对PASCALvoc数据集的评估) 为什么要bulid cython.caffe. ...
- MicroService 微服务提供者搭建
本机IP为 192.168.1.102 1. 新建Maven项目 microservice 2. pom.xml <project xmlns="http://maven. ...