RedisTemplate 怎么获取到链接信息?怎么获取到所有key?怎么获取指定key?
- Redis
- 时间:2024-01-05 18:57
- 1769人已阅读
简介
获取Redis的链接信息:(RedisTemplate<String, ?> redisTemplate) { RedisConnectionFactory connectionFactory = redisTemplate.getConnectionFactory(); 
🔔🔔🔔好消息!好消息!🔔🔔🔔
有需要的朋友👉:联系凯哥
获取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); }
下一篇: java怎么把首字母大写