加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

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

发布时间:2019-04-17 05:03:38 所属栏目:编程 来源:付磊-起扬
导读:本文首要先容在行使阿里云Redis的开拓类型,从下面几个方面举办声名。 键值计划 呼吁行使 客户端行使 相干器材 通过本文的先容可以镌汰行使Redis进程带来的题目。 一、键值计划 1、key名计划 可读性和可打点性 以营业名(或数据库名)为前缀(防备key斗嘴),

其他计策如下:

  •  allkeys-lru:按照LRU算法删除键,不管数据有没有配置超时属性,直到腾出足够空间为止。
  •  allkeys-random:随机删除全部键,直到腾出足够空间为止。
  •  volatile-random:随机删除逾期键,直到腾出足够空间为止。
  •  volatile-ttl:按照键值工具的ttl属性,删除最近将要逾期数据。假如没有,回退到noeviction计策。
  •  noeviction:不会剔除任何数据,拒绝全部写入操纵并返回客户端错误信息"(error) OOM command not allowed when used memory",此时Redis只相应读操纵。

四、相干器材

1、数据同步

redis间数据同步可以行使:redis-port

2、big key搜刮

redis大key搜刮器材

3、热门key探求

内部实现行使monitor,以是提议短时刻行使facebook的redis-faina

阿里云Redis已经在内核层面办理热门key题目

五、删除bigkey

  1.  下面操纵可以行使pipeline加快。
  2.  redis 4.0已经支持key的异步删除,接待行使。

1、Hash删除: hscan + hdel

  1. public void delBigHash(String host, int port, String password, String bigHashKey) {  
  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<Entry<String, String>> scanResult = jedis.hscan(bigHashKey, cursor, scanParams);  
  10.         List<Entry<String, String>> entryList = scanResult.getResult();  
  11.         if (entryList != null && !entryList.isEmpty()) {  
  12.             for (Entry<String, String> entry : entryList) {  
  13.                 jedis.hdel(bigHashKey, entry.getKey());  
  14.             }  
  15.         }  
  16.         cursor = scanResult.getStringCursor();  
  17.     } while (!"0".equals(cursor));  
  18.     //删除bigkey  
  19.     jedis.del(bigHashKey);  

2、List删除: ltrim

  1. public void delBigList(String host, int port, String password, String bigListKey) {  
  2.     Jedis jedis = new Jedis(host, port);  
  3.     if (password != null && !"".equals(password)) {  
  4.         jedis.auth(password);  
  5.     }  
  6.     long llen = jedis.llen(bigListKey);  
  7.     int counter = 0;  
  8.     int left = 100;  
  9.     while (counter < llen) {  
  10.         //每次从左侧截掉100个  
  11.         jedis.ltrim(bigListKey, left, llen);  
  12.         counter += left;  
  13.     }  
  14.     //最终删除key  
  15.     jedis.del(bigListKey);  

(编辑:湖南网)

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

热点阅读