err unknown command keys
切换redis后发现keys命令出现报错,经查询原因如下:
原因可能是:keys命令用于全局查询 一般不建议使用所以能在redis.conf中配置了置换该命令
解决方案: 检查redis.conf 中是否有该命令禁用配置
rename-command flushall "" 清空所有的库数据
rename-command flushdb "" 清空当前库数据
rename-command keys "" 查询所有库数据 (因为数据量大时 执行此操作会消耗大量的资源 一般不建议使用该命令)
如果有注释掉即可
但是因为使用的是统一部署的redis,无法进行修改操作,于是只好修改涉及kes命令的操作
使用scan获取rediskey
@autowired public redistemplate redistemplate; public set<string> scan(string matchkey) { set<string> keys = new hashset<>(); scanoptions scanoptions = scanoptions.scanoptions().match(matchkey).count(1000).build(); cursor<byte[]> cursor = (cursor<byte[]>) redistemplate.execute(redisconnection -> redisconnection.scan(scanoptions), true); redisserializer redisserializer = redistemplate.getkeyserializer(); while (cursor.hasnext()) { keys.add(string.valueof(redisserializer.deserialize(cursor.next()))); } return keys; }
到此这篇关于redis查询keys报错的实现的文章就介绍到这了,更多相关redis查询keys报错内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论