osu合集(期望dp)
阿新 • • 發佈:2020-08-15
前面有簡單學習過redis,此處擴充套件之.. 阿里雲redis開發規範
redis工具
資料同步:redis-port
big-key搜尋
參考:工具彙總
命令列
redis-cli --bigkeys
find_bigkeys.py
阿里雲基於python工具,按key值長度
python find_bigkey.py host port password
rdb_bigkeys
基於go實現的分析rdb檔案查詢big-key工具
big-key刪除
//1、Hash刪除: hscan + hdel public void delBigHash(String host, int port, String password, String bigHashKey) { Jedis jedis = new Jedis(host, port); if (!StringUtils.isBlank(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)); jedis.del(bigHashKey); //刪除bigkey } //2、List刪除: ltrim public void delBigList(String host, int port, String password, String bigListKey) { Jedis jedis = new Jedis(host, port); if (!StringUtils.isBlank(password)) { jedis.auth(password); } long llen = jedis.llen(bigListKey); int counter = 0, left = 100; while (counter < llen) { jedis.ltrim(bigListKey, left, llen); //每次從左側截掉100個 counter += left; } jedis.del(bigListKey); //最終刪除key } //3、Set刪除: sscan + srem public void delBigSet(String host, int port, String password, String bigSetKey) { Jedis jedis = new Jedis(host, port); if (!StringUtils.isBlank(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)); jedis.del(bigSetKey);//刪除bigkey } //4、SortedSet刪除: zscan + zrem public void delBigZset(String host, int port, String password, String bigZsetKey) { Jedis jedis = new Jedis(host, port); if (!StringUtils.isBlank(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)); jedis.del(bigZsetKey); //刪除bigkey }
熱點key搜尋
命令列
redis-cli --hotkeys