cursorResult.getCursorId()返回的是一个Long值
时间: 2024-03-21 19:41:59 浏览: 9
非常抱歉,我的回答有误。`cursorResult.getCursorId()` 方法确实返回一个 `Long` 类型的值,这个值是下一次扫描的游标 ID。因此,在 `do-while` 循环中,应该使用 `!cursor.equals("0")` 来检查游标是否为零,而不是使用 `!cursor.equals(0L)`。以下是更正后的代码:
```java
public List<String> getAllKeys(String pattern) {
List<String> keys = new ArrayList<>();
String cursor = "0";
do {
ScanOptions options = ScanOptions.scanOptions().match(pattern).count(1000).build();
Cursor<String> cursorResult = stringRedisTemplate.executeWithStickyConnection(
(RedisCallback<Cursor<String>>) connection ->
new ConvertingCursor<>(connection.scan(options), stringRedisTemplate.getKeySerializer()::deserialize)
);
while (cursorResult.hasNext()) {
keys.add(cursorResult.next());
}
cursor = cursorResult.getCursorId().toString();
} while (!cursor.equals("0"));
return keys;
}
```
我深表歉意,希望这次回答能够解决您的问题。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)