RedisTemplate 怎么获取到链接信息?怎么获取到所有key?怎么获取指定key?

获取Redis的链接信息:

复制代码
(RedisTemplate<String, ?> redisTemplate) {
    RedisConnectionFactory connectionFactory = redisTemplate.getConnectionFactory();

    (!(connectionFactory LettuceConnectionFactory)) {
        System..println();
        ;
    }

    LettuceConnectionFactory lettuceConnectionFactory = (LettuceConnectionFactory) connectionFactory;

    RedisConnection connection = connectionFactory.getConnection();

    (connection == || connection.isClosed()) {
        System..println();
    } {
        System..println();

        String host = lettuceConnectionFactory.getHostName();
        port = lettuceConnectionFactory.getPort();

        System..println(+ host);
        System..println(+ port);

        System..println(+ connection.info());
    }
}

获取指定的key:

复制代码
Set<String> (RedisTemplate<String, ?> redisTemplate) {
    ScanOptions scanOptions = ScanOptions.().match().count().build();

    Set<String> keys = redisTemplate.execute(connection -> {
        Set<[]> keysBytes = connection.keys(.getBytes());
        keysBytes.stream()
                .map(String::)
                .collect(Collectors.());
    }, );

    keys;
}

获取所有key:

复制代码
Set<String> (RedisTemplate<String, ?> redisTemplate,String hashKey) {
    HashOperations<String, String, Object> hashOperations = redisTemplate.opsForHash();
    hashOperations.keys(hashKey);
}
相关推荐
不吃香菜学java13 小时前
Redis的java客户端
java·开发语言·spring boot·redis·缓存
码事漫谈13 小时前
大模型输出的“隐性结构塌缩”问题及对策
前端·后端
captain37613 小时前
事务___
java·数据库·mysql
北漂Zachary13 小时前
四大编程语言终极对比
android·java·php·laravel
小江的记录本13 小时前
【网络安全】《网络安全常见攻击与防御》(附:《六大攻击核心特性横向对比表》)
java·网络·人工智能·后端·python·安全·web安全
贵沫末13 小时前
python——打包自己的库并安装
开发语言·windows·python
这儿有一堆花13 小时前
前端三件套真的落后了吗?揭开现代 Web 开发的底层逻辑
前端·javascript·css·html5
文祐13 小时前
C++类之虚函数表及其内存布局(一个子类继承一个父类)
开发语言·c++
.Cnn14 小时前
JavaScript 前端基础笔记(网页交互核心)
前端·javascript·笔记·交互
zuowei288914 小时前
华为网络设备配置文件备份与恢复(上传、下载、导出,导入)
开发语言·华为·php