3、Set删除: sscan + srem
- public void delBigSet(String host, int port, String password, String bigSetKey) {
- 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<String> scanResult = jedis.sscan(bigSetKey, cursor, scanParams);
- List<String> memberList = scanResult.getResult();
- if (memberList != null && !memberList.isEmpty()) {
- for (String member : memberList) {
- jedis.srem(bigSetKey, member);
- }
- }
- cursor = scanResult.getStringCursor();
- } while (!"0".equals(cursor));
- //删除bigkey
- jedis.del(bigSetKey);
- }
4、SortedSet删除: zscan + zrem
- public void delBigZset(String host, int port, String password, String bigZsetKey) {
- 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<Tuple> scanResult = jedis.zscan(bigZsetKey, cursor, scanParams);
- List<Tuple> tupleList = scanResult.getResult();
- if (tupleList != null && !tupleList.isEmpty()) {
- for (Tuple tuple : tupleList) {
- jedis.zrem(bigZsetKey, tuple.getElement());
- }
- }
- cursor = scanResult.getStringCursor();
- } while (!"0".equals(cursor));
- //删除bigkey
- jedis.del(bigZsetKey);
- }
【编辑推荐】
- Redis在项目中合理使用经验总结
- 数据库 | 一次非常有趣的SQL优化经历
- 查询数据库,你还在 Select * 吗?
- 2019年4月数据库流行度排行:Oracle持续增长股价获新高
- 一次诡异的线上数据库的死锁问题排查过程
【责任编辑:庞桂玉 TEL:(010)68476606】
点赞 0 (编辑:西安站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|