加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码网 (https://www.900php.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

一份完整的阿里云Redis开发规范,值得收藏!

发布时间:2019-04-16 01:49:34 所属栏目:MySql教程 来源:付磊-起扬
导读:副标题#e# 本文主要介绍在使用阿里云Redis的开发规范,从下面几个方面进行说明。 键值设计 命令使用 客户端使用 相关工具 通过本文的介绍可以减少使用Redis过程带来的问题。 一、键值设计 1、key名设计 可读性和可管理性 以业务名(或数据库名)为前缀(防止ke

3、Set删除: sscan + srem

  1. public void delBigSet(String host, int port, String password, String bigSetKey) {  
  2.     Jedis jedis = new Jedis(host, port);  
  3.     if (password != null && !"".equals(password)) {  
  4.         jedis.auth(password);  
  5.     }  
  6.     ScanParams scanParams = new ScanParams().count(100);  
  7.     String cursor = "0";  
  8.     do {  
  9.         ScanResult<String> scanResult = jedis.sscan(bigSetKey, cursor, scanParams);  
  10.         List<String> memberList = scanResult.getResult();  
  11.         if (memberList != null && !memberList.isEmpty()) {  
  12.             for (String member : memberList) {  
  13.                 jedis.srem(bigSetKey, member);  
  14.             }  
  15.         }  
  16.         cursor = scanResult.getStringCursor();  
  17.     } while (!"0".equals(cursor));  
  18.     //删除bigkey  
  19.     jedis.del(bigSetKey);  

4、SortedSet删除: zscan + zrem

  1. public void delBigZset(String host, int port, String password, String bigZsetKey) {  
  2.     Jedis jedis = new Jedis(host, port);  
  3.     if (password != null && !"".equals(password)) {  
  4.         jedis.auth(password);  
  5.     }  
  6.     ScanParams scanParams = new ScanParams().count(100);  
  7.     String cursor = "0";  
  8.     do {  
  9.         ScanResult<Tuple> scanResult = jedis.zscan(bigZsetKey, cursor, scanParams);  
  10.         List<Tuple> tupleList = scanResult.getResult();  
  11.         if (tupleList != null && !tupleList.isEmpty()) {  
  12.             for (Tuple tuple : tupleList) {  
  13.                 jedis.zrem(bigZsetKey, tuple.getElement());  
  14.             }  
  15.         }  
  16.         cursor = scanResult.getStringCursor();  
  17.     } while (!"0".equals(cursor));  
  18.     //删除bigkey  
  19.     jedis.del(bigZsetKey);  

(编辑:源码网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读