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);
}
相关推荐
卷心菜的学习路20 小时前
《计算》第九十章读书笔记
java·读书笔记·编程思维
^O^ ^O^20 小时前
pc端pdf预览
前端·javascript·pdf
开始学AI21 小时前
【Docker技术】docker-compose.yml与Dockerfile解析
java·docker·eureka
徐同保21 小时前
js class定义类,私有属性,类继承,子类访问父类的方法,重写父类的方法
前端·javascript·vue.js
写代码的小阿帆1 天前
Java体系总结——从基础语法到微服务
java·微服务·学习方法
CUMT_DJ1 天前
matlab计算算法的运行时间
开发语言·算法·matlab
SUPER52661 天前
FastApi项目启动失败 got an unexpected keyword argument ‘loop_factory‘
java·服务器·前端
sanx181 天前
专业电竞体育数据与系统解决方案
前端·数据库·apache·数据库开发·时序数据库
咕噜咕噜啦啦1 天前
Eclipse集成开发环境的使用
java·ide·eclipse
Overboom1 天前
[C++] --- 常用设计模式
开发语言·c++·设计模式