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);
}
相关推荐
涔溪几秒前
uni-app环境搭建
前端·uni-app
安冬的码畜日常4 分钟前
【CSS in Depth 2 精译_032】5.4 Grid 网格布局的显示网格与隐式网格(上)
前端·css·css3·html5·网格布局·grid布局·css网格布局
洛千陨4 分钟前
element-plus弹窗内分页表格保留勾选项
前端·javascript·vue.js
小小19926 分钟前
elementui 单元格添加样式的两种方法
前端·javascript·elementui
day3ZY18 分钟前
清理C盘缓存,电脑缓存清理怎么一键删除,操作简单的教程
c语言·开发语言·缓存
前端没钱26 分钟前
若依Nodejs后台、实现90%以上接口,附体验地址、源码、拓展特色功能
前端·javascript·vue.js·node.js
学地理的小胖砸30 分钟前
【高分系列卫星简介】
开发语言·数码相机·算法·遥感·地理信息
爱喝水的小鼠32 分钟前
AJAX(一)HTTP协议(请求响应报文),AJAX发送请求,请求问题处理
前端·http·ajax
码农豆豆32 分钟前
4.C++中程序中的命名空间
开发语言·c++
怀九日35 分钟前
C++(学习)2024.9.19
开发语言·c++·学习·重构·对象·