-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] expired eventListener 추가 (#1307)
- Loading branch information
1 parent
6d55b2b
commit 824f681
Showing
3 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
backend/src/main/java/org/ftclub/cabinet/redis/ExpirationListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.ftclub.cabinet.redis; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.data.redis.connection.Message; | ||
import org.springframework.data.redis.connection.MessageListener; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; | ||
import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Map; | ||
|
||
|
||
@Component | ||
public class ExpirationListener extends KeyExpirationEventMessageListener { | ||
|
||
@Autowired | ||
private RedisTemplate<String, Object> redisTemplate; | ||
|
||
/** | ||
* Creates new {@link MessageListener} for {@code __keyevent@*__:expired} messages. | ||
* | ||
* @param listenerContainer must not be {@literal null}. | ||
*/ | ||
public ExpirationListener( | ||
@Qualifier("redisMessageListenerContainer") | ||
RedisMessageListenerContainer listenerContainer) { | ||
super(listenerContainer); | ||
} | ||
|
||
/** | ||
* @param message redis key | ||
* @param pattern __keyevent@*__:expired | ||
*/ | ||
@Override | ||
public void onMessage(Message message, byte[] pattern) { | ||
|
||
System.out.println("########## onMessage pattern " + new String(pattern) + " | " + message.toString()); | ||
|
||
printExpiredKeyValue(message.toString()); | ||
} | ||
|
||
// 삭제된 키의 value를 출력하려고 해서 출력이 제대로 안 나옴 | ||
public void printExpiredKeyValue(String key) { | ||
// System.out.println("########## printExpiredKeyValue " + key); | ||
final Map<Object, Object> entries = | ||
redisTemplate.opsForHash().entries(key); | ||
System.out.println(entries); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters