Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR unknown command `KEYS`, with args beginning with: `config_login_tokens:*`,
最近项目上出现以上的异常问题,是在获取redis数据的时候使用keys报的错误信息。以前功能是正常的最近突然出现的。于是网上找了不少对应的错误信息。综合下来应该是运维人员将Redis危险命令进行了禁用屏蔽。
ename-command FLUSHALL "" #将命令改名成空
rename-command FLUSHDB "" #将命令改名成空
rename-command KEYS "" #将命令改名成空
于是在网上又找到一篇对应的文章,springboot可以用scan代替keys的取值方式
public Set<String> keysOther(String keyPrefix) {
String realKey = "*" + keyPrefix + "*";
try {
return (Set<String>) redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
Set<String> binaryKeys = new HashSet<>();
Cursor<byte[]> cursor = connection.scan(new ScanOptions.ScanOptionsBuilder().match(realKey).count(Integer.MAX_VALUE).build());
while (cursor.hasNext()) {
binaryKeys.add(new String(cursor.next()));
}
return binaryKeys;
});
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
最后成功获取到了key的集合信息