Go에서 Redis 7의 새로운 샤딩된 Pub/Sub 사용
5051 단어 gotutorialredisperformance
Sharded pubsub helps to scale the usage of pubsub in cluster mode. It restricts the propagation of message to be within the shard of a cluster. Hence, the amount of data passing through the cluster bus is limited in comparison to global pubsub where each message propagates to each node in the cluster. This allows users to horizontally scale the pubsub usage by adding more shards.
이제 사용자는 새로운
SPUBLISH
명령을 사용하여 전체 Redis 클러스터를 압도할 걱정 없이 메시지를 게시할 수 있습니다.그리고
SSUBSCRIBE
명령을 사용하여 해당 메시지를 수신하십시오.다음은 고성능 RESP3 go 클라이언트 라이브러리인 rueidis 과 함께 이 새로운 기능을 사용하는 방법을 보여주는 예입니다.
package main
import (
"context"
"fmt"
"time"
"github.com/rueian/rueidis"
)
func main() {
client, _ := rueidis.NewClient(rueidis.ClientOption{
InitAddress: []string{"127.0.0.1:7001", "127.0.0.1:7002", "127.0.0.1:7003"},
})
ctx := context.Background()
go func() {
for {
client.Do(ctx, client.B().Spublish().Channel("ch").Message("hi").Build())
time.Sleep(time.Second)
}
}()
client.Receive(ctx, client.B().Ssubscribe().Channel("ch").Build(), func(msg rueidis.PubSubMessage) {
fmt.Println(msg.Channel, msg.Message)
})
}
위의 스니펫은 다음을 수행합니다.
SPUBLISH
. client.Receive
명령 및 콜백 기능과 함께 SSUBSCRIBE
를 사용하여 수신된 메시지를 계속 처리합니다. client.Receive
는 ctx
가 완료되거나 클라이언트가 채널에서 구독 취소될 때까지 영원히 차단됩니다.그게 다야! rueidis 에 질문이나 문제가 있으면 Github에서 저에게 연락하십시오.
Reference
이 문제에 관하여(Go에서 Redis 7의 새로운 샤딩된 Pub/Sub 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/rueian/using-redis-7s-new-sharded-pubsub-in-go-2bi텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)