redis 清理缓存

 —-windos

方法1,重启redis也能请缓存。

方法2,清缓存前确保redis-server.exe进程已经启动,然后打开redis-cli.exe,跳出的CMD里面输入flushall,显示OK就可以了。

flushall:清空整个redis 服务器的数据(删除所有数据库的所有 key )。

flushdb:清空当前数据库中的所有 key。

方法3,清空指定Key,例如:

del key1

del key2

方法4,使用JAVA清理

public static void flushAll(){

Jedis jedis = new Jedis(“127.0.0.1”,5050);

jedis.connect();

jedis.flushAll();

jedis.disconnect();

}

方法5,使用脚本批量清空所有缓存,下面以Spring实现Redis批量清空缓存为例:

@Autowired

private StringRedisTemplate stringRedisTemplate;

public void deleteKeys(){

Set keys = stringRedisTemplate.keys(“*”);

stringRedisTemplate.delete(keys);

}

方法6,还有定时清理,具体百度

—-linux

 

1、先确保redis进程存活

ps -ef|grep redis

2、执行./redis-cli或者./redis-cli -h 127.0.0.1 -p 6379

[root@slave bin]# ./redis-cli

3、执行:dbsize命令

4、执行:flushall命令

5、使用keys * 进行验证是否为空

6、执行:exit

 

redis 清理缓存

参考:
linux下清理redis缓存 – 知乎

———————20231007 补充

如果是不能直连,需要通过redis -cli连接,

redis-cli -h 127.0.0.1 -p 22 -a “password” –bigkeys

默认端口是22 

连接上后,执行 flushall 也行,或者 查看大字段情况 –bigkeys

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://www.net2asp.com/8924e50248.html