Redis of scan fuzzy queries

According to a field in a fuzzy search 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;
    }
Published 51 original articles · won praise 11 · views 6081

Guess you like

Origin blog.csdn.net/weixin_42140261/article/details/104857794