我正在使用 spring redisTemplate 和 redis 扫描
它可以在单节点的情况下查找。
但在集群环境下就不行了
我无法获取数据。
有没有办法在集群环境中获取扫描数据?
这是我的 spring redisTemplate 代码。
//String key="products:aa";
//String key="products:aac";
//String key="products:ab";
//String key="products:ac";
String workKey="products:aa*";
ScanOptions options = ScanOptions.scanOptions().match(workKey).count(100).build();
ScanOptions options1 = ScanOptions.scanOptions().build();
RedisConnectionFactory factory = redisTemplate.getConnectionFactory();
RedisConnection conn = factory.getConnection();
Cursor<byte[]> cursor = conn.scan(options);
List<Product> result = new ArrayList<Product>();
while(cursor.hasNext()){
String key=new String((byte[]) cursor.next());
Product pa=getById(key.replace("products:",""));
result.add(pa);
}
//result
//String key="products:aa";
//String key="products:aac";
Run Code Online (Sandbox Code Playgroud)