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);
}
相关推荐
上去我就QWER1 小时前
Qt中如何获取系统版本信息
开发语言·qt
我是苏苏2 小时前
C#高级:程序查询写法性能优化提升策略(附带Gzip算法示例)
开发语言·算法·c#
木木子99992 小时前
业务架构、应用架构、数据架构、技术架构
java·开发语言·架构
qq_5470261794 小时前
Flowable 工作流引擎
java·服务器·前端
刘逸潇20055 小时前
CSS基础语法
前端·css
鼓掌MVP5 小时前
Java框架的发展历程体现了软件工程思想的持续进化
java·spring·架构
吃饺子不吃馅6 小时前
[开源] 从零到一打造在线 PPT 编辑器:React + Zustand + Zundo
前端·svg·图形学
编程爱好者熊浪6 小时前
两次连接池泄露的BUG
java·数据库
lllsure6 小时前
【Spring Cloud】Spring Cloud Config
java·spring·spring cloud
鬼火儿6 小时前
SpringBoot】Spring Boot 项目的打包配置
java·后端