其他策略如下:
- 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);
- }
(编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|