Development Logs/Spring Ecosystem
[Spring GW + Boot] Reactive RedisTemplate SET Digging
유뱅유뱅뱅
2025. 2. 16. 21:30
반응형
@TestPropertySource(properties = {
"logging.level.org.springframework.data.redis=TRACE",
"logging.level.io.lettuce.core=TRACE"
})
위의 redis 관련 logging level 설정을 통해 실제 Redis Command 나가는 것을 볼 수 있다.
기본 SET 확인 (set)
return reactiveRedisTemplate.opsForValue().set(key, value);
2025-02-13 18:14:32.173 +0900 TRACE - [channel=0x85920165, /127.0.0.1:56016 -> localhost/127.0.0.1:6388] Sent: *3
$3 SET $77 routingRecord:get:/rule-command-active-test..생략.. (key 값) $637 {..생략..} (value 값)
- 기본 SET을 확인해보면, 그 키에 값이 있던 없는 overwrite하게된다.
SET NX 옵션 확인 (setIfAbsent)
return reactiveRedisTemplate.opsForValue().setIfAbsent(key, value);
2025-02-13 18:19:37.811 +0900 TRACE - [channel=0x57ddf892, /127.0.0.1:56986 -> localhost/127.0.0.1:6388] Sent: *4
$3 SET $77 routingRecord:get:/rule-command-active-test..생략.. (key 값) $637 {..생략..} (value 값) $2 NX
- SET NX 를 확인해보면 해당 key가 없는 경우에만 SET을 수행하게 된다.
추가로 SET EX 라는 것도 존재한다.(이거는 반대로 key가 있는 경우에만 SET을 수행한다)
Redis 공식문서 확인
SETNX
Set the string value of a key only when the key doesn't exist.
redis.io
반응형