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);
}
相关推荐
jyan_敬言5 分钟前
【C++】string类(二)相关接口介绍及其使用
android·开发语言·c++·青少年编程·visual studio
代码的余温9 分钟前
5种高效解决Maven依赖冲突的方法
java·maven
hahala23339 分钟前
ESLint 提交前校验技术方案
前端
慕y27412 分钟前
Java学习第十六部分——JUnit框架
java·开发语言·学习
paishishaba18 分钟前
Maven
java·maven
liulilittle29 分钟前
SNIProxy 轻量级匿名CDN代理架构与实现
开发语言·网络·c++·网关·架构·cdn·通信
夕水31 分钟前
ew-vue-component:Vue 3 动态组件渲染解决方案的使用介绍
前端·vue.js
我麻烦大了34 分钟前
实现一个简单的Vue响应式
前端·vue.js
Shartin38 分钟前
CPT208-Human-Centric Computing: Prototype Design Optimization原型设计优化
开发语言·javascript·原型模式
独立开阀者_FwtCoder42 分钟前
你用 Cursor 写公司的代码安全吗?
前端·javascript·github