好的,我使用jedis群集密钥方法:
@Autowired
private JedisCluster cluster;
Set<String> keys = new HashSet<>();
for (Map.Entry<String, JedisPool> entry :
cluster.getClusterNodes().entrySet()) {
Jedis jedis = entry.getValue().getResource();
Set<String> _keys = jedis.keys(pattern);
keys.addAll(_keys);
}
但是,此代码抛出异常,:
redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'KEYS'
at redis.clients.jedis.Protocol.processError(Protocol.java:127)
at redis.clients.jedis.Protocol.process(Protocol.java:161)
at redis.clients.jedis.Protocol.read(Protocol.java:215)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:276)
at redis.clients.jedis.Jedis.keys(Jedis.java:246)
POM:
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
我不知道自己写错了!请帮助我,非常感谢!!
答案 0 :(得分:1)
keys命令,我不确定将来是否会支持它。
您可以改用扫描。