接口:

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);
}
} }

最新文章

  1. Strust的基础情况
  2. java System.out
  3. code md5
  4. Quartz源码阅读
  5. spring中context:property-placeholder/元素 转载
  6. Mybatis3 框架理解
  7. 脚本语言:Xmas(二)
  8. 无网络环境下安装Dynamics CRM
  9. ThinkPHP5.1 + tufanbarisyildirim 解析apk
  10. VS2017 无法连接到Web服务器“IIS Express”终极解决方案
  11. leetcode 78,236,300
  12. Flagr 配置说明
  13. 深入浅出Tomcat/4 - Tomcat容器
  14. VC++常用数据类型及其操作详解
  15. android录音实现不再担心—一个案例帮你解决你的问题
  16. 图片3D旋转
  17. polymorphism多态
  18. Java实现批量插入
  19. 洛谷P1064 金明的预算方案
  20. Python基础之爬虫(持续更新中)

热门文章

  1. python学习三(数据保存到文件)
  2. wamp 下运行Drupal慢的解决方法
  3. launchctl
  4. Java开发笔记(九十八)利用Callable启动线程
  5. 关于wav文件fft处理后x,y轴坐标数据的问题
  6. 安卓usb数据接收
  7. 配置百度云盘python客户端bypy上传备份文件
  8. WPF根据数据项获取条目控件的方法-ItemContainerGenerator
  9. javascript动态修改对象的属性名
  10. ubuntu常见错误