1.maven仓库查询Redisson并倒入项目
<dependency> <groupId>org.redisson</groupId> <artifactId>redisson-spring-boot-starter</artifactId> <version>3.35.0</version> </dependency>
2.配置文件(采用yml配置方式)
spring:
redis:
host: 120.46.41.01
port: 6379
3.编写测试类
@SpringBootTest
class ProductApplicationTests {
@Resource
RedissonClient redissonClient;
@Test
void redisTest() {
RLock lock = redissonClient.getLock("lock");
lock.lock();
System.out.printf("加锁");
lock.unlock();
System.out.printf("解锁");
}
}
打印结果:
Redis查看