pom:
<dependency>
<groupId>org.redisson</groupId> <artifactId>redisson</artifactId> <version>3.15.6</version> </dependency>
配置类
package com.aila.config; import org.redisson.Redisson; import org.redisson.api.RedissonClient; import org.redisson.config.Config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * @author chenzhichao * @date 2021/6/18 15:18 */ @Configuration public class RedissonConfig { @Bean public RedissonClient redisson(){ Config config = new Config(); config.useSingleServer().setAddress(("redis://192.168.101.25:6379")).setDatabase(10); RedissonClient redissonClient = Redisson.create(config); return redissonClient; } }
test类
import com.aila.MyBootApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.redisson.api.RKeys; import org.redisson.api.RedissonClient; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** * @author chenzhichao * @date 2021/6/18 15:09 */ @RunWith(SpringRunner.class) @SpringBootTest(classes = MyBootApplication.class) public class MyTestYy { @Resource private RedissonClient redisson; @Test public void test(){ RKeys keys = redisson.getKeys(); System.out.println(keys); } }
结果
org.redisson.RedissonKeys@52f8a6f4
后续 继续