redis实现分布式锁
1. 环境
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'spring.redis.host=127.0.0.1
spring.redis.port=6379127.0.0.1:6379> keys *
1) "money:woms"
127.0.0.1:6379> get money:woms
"1000"import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@GetMapping("name")
public Object name() {
String womsMoney = stringRedisTemplate.opsForValue().get("money:woms");
return womsMoney;
}
}为什么要用分布式锁
redis实现分布式锁
Last updated