缓存清理工具

redis缓存清理工具,测试环境可以一键清理所有,线上环境提供key删除

运行截图如下:

cache

 

核心删除缓存代码如下:

public void deleteTest() {
	try {
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxActive(3);
		config.setMaxIdle(10);
		config.setMaxWait(10000);
		String ip = nameJComboBox.getSelectedItem().toString();
		JedisPool pool = new JedisPool(config, ip, 6379, 10000, "taofen8redis");
		Jedis jedis = pool.getResource();
		name1 = passwordJPasswordField.getText();
		String key = "*" + name1 + "*";
		Set<String> set = jedis.keys(key);
		int count = set.size();
		if (name1 == null || name1.trim().length() <= 0) {
			jedis.flushDB();
			myButton.setLabel("cache delete");
			JOptionPane
					.showMessageDialog(this, "呵呵,成功清除所有缓存[" + count + "]条", "success", JOptionPane.INFORMATION_MESSAGE);
			return;
		}
		StringBuilder sb = new StringBuilder(128);
		for (String s : set) {
			sb.append(s).append("\r\n");
			jedis.del(s);
		}
		//使用结束后要将jedis放回pool中:
		pool.returnResource(jedis);
		msg.setText(sb.toString());
		myButton.setLabel("cache delete");
		JOptionPane.showMessageDialog(this, "呵呵,成功清除缓存[" + count + "]条", "success", JOptionPane.INFORMATION_MESSAGE);
	} catch (Exception e) {
		msg.setText(welcome);
		myButton.setLabel("cache delete");
		JOptionPane.showMessageDialog(this, "去喝杯咖啡吧:出现了异常"+e.getMessage(), "sorry", JOptionPane.INFORMATION_MESSAGE);
	}
}

 

 

下载地址>>:redis缓存清理工具

发表评论

邮箱地址不会被公开。