根据某个字段模糊搜索 Redis 中的某个 key
public String searchTokenFirst(String key) {
//execute():搜索 Redis 中某个 key
Cursor<byte[]> cursor =
redisTemplate.execute((RedisCallback<Cursor<byte[]>>) connection ->
connection.scan(ScanOptions.scanOptions().match("*" + key + "*").build()));
//将 redis scan 迭代的结果的第一条转为字符串
if (cursor.hasNext()) {
return new String(cursor.next());
}
return null;
}