[C#/REDIS] ISubscriber 인터페이스 : Subscribe/Publish 메소드를 사용해 메시지 구독하기/발행하기
C#/Redis 2020. 11. 14. 13:42728x90
728x170
■ ISubscriber 인터페이스의 Subscribe/Publish 메소드를 사용해 메시지를 구독하고 발행하는 방법을 보여준다.
▶ 예제 코드 (C#)
using System;
using System.Threading.Tasks;
using StackExchange.Redis;
ConnectionMultiplexer multiplexer = ConnectionMultiplexer.Connect("192.168.29.197:6379");
ISubscriber subscriber = multiplexer.GetSubscriber();
subscriber.Subscribe("message1")
.OnMessage
(
async channelMessage =>
{
await Task.Delay(1000);
Console.WriteLine((string)channelMessage.Message);
}
);
subscriber.Publish("message1", "안녕하세요.");
Console.ReadKey(true);
※ 패키지 설치 : StackExchange.Redis
728x90
그리드형(광고전용)
'C# > Redis' 카테고리의 다른 글
[C#/REDIS] IDatabase 인터페이스 : KeyDelete 메소드를 사용해 키 제거하기 (0) | 2020.11.14 |
---|---|
[C#/REDIS] IDatabase 인터페이스 : KeyRandom 메소드를 사용해 임의의 저장된 키 구하기 (0) | 2020.11.14 |
[C#/REDIS] IServer 인터페이스 : ClientList 메소드를 사용해 클라이언트 정보 구하기 (0) | 2020.11.14 |
[C#/REDIS] IDatabase 인터페이스 : StringIncrement 메소드를 사용해 문자열 값 증가시키기 (0) | 2020.11.14 |
[C#/REDIS] IServer 인터페이스 : LastSave 메소드를 사용해 마지막 저장 시간 구하기 (0) | 2020.11.14 |
[C#/REDIS] ISubscriber 인터페이스 : Subscribe/Publish 메소드를 사용해 메시지 구독하기/발행하기 (0) | 2020.11.14 |
[C#/REDIS] IDatabase 인터페이스 : HashSet/HashGetAll 메소드를 사용해 해시값 저장하기/구하기 (0) | 2020.11.14 |
[C#/REDIS] IServer 인터페이스 : Keys 메소드를 사용해 키 나열하기 (0) | 2020.11.14 |
[C#/REDIS] ConnectionMultiplexer 클래스 : GetEndPoints 메소드를 사용해 엔드포인트 배열 구하기 (0) | 2020.11.14 |
[C#/REDIS] IDatabase 인터페이스 : StringSet/StringGet 메소드를 사용해 문자열 값 저장하기/구하기 (0) | 2020.11.14 |