其他计策如下:
- 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
- 下面操纵可以行使pipeline加快。
- redis 4.0已经支持key的异步删除,接待行使。
1、Hash删除: hscan + hdel
- public void delBigHash(String host, int port, String password, String bigHashKey) {
- Jedis jedis = new Jedis(host, port);
- if (password != null && !"".equals(password)) {
- jedis.auth(password);
- }
- ScanParams scanParams = new ScanParams().count(100);
- String cursor = "0";
- do {
- ScanResult<Entry<String, String>> scanResult = jedis.hscan(bigHashKey, cursor, scanParams);
- List<Entry<String, String>> entryList = scanResult.getResult();
- if (entryList != null && !entryList.isEmpty()) {
- for (Entry<String, String> entry : entryList) {
- jedis.hdel(bigHashKey, entry.getKey());
- }
- }
- cursor = scanResult.getStringCursor();
- } while (!"0".equals(cursor));
- //删除bigkey
- jedis.del(bigHashKey);
- }
2、List删除: ltrim
- public void delBigList(String host, int port, String password, String bigListKey) {
- Jedis jedis = new Jedis(host, port);
- if (password != null && !"".equals(password)) {
- jedis.auth(password);
- }
- long llen = jedis.llen(bigListKey);
- int counter = 0;
- int left = 100;
- while (counter < llen) {
- //每次从左侧截掉100个
- jedis.ltrim(bigListKey, left, llen);
- counter += left;
- }
- //最终删除key
- jedis.del(bigListKey);
- }
(编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|