MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / PubSubMiddleware

Function PubSubMiddleware

IceFireDB-Redis-Proxy/pkg/router/pubsub.go:34–49  ·  view source on GitHub ↗

Synchronize notification to peer node middleware

(router IRoutes, pubSub *p2p.PubSub)

Source from the content-addressed store, hash-verified

32
33// Synchronize notification to peer node middleware
34func PubSubMiddleware(router IRoutes, pubSub *p2p.PubSub) HandlerFunc {
35 subscribe(router, pubSub)
36 return func(context *Context) error {
37 // sync write operate cmd
38 if context.Op.IsMasterOnly() {
39 args := make([]string, len(context.Args))
40 for k, v := range context.Args {
41 args[k] = string(v.([]byte))
42 }
43 s, _ := json.Marshal(args)
44 pubSub.Outbound <- string(s)
45 // logrus.Info("outbound: ", string(s))
46 }
47 return context.Next()
48 }
49}
50
51func subscribe(router IRoutes, pubSub *p2p.PubSub) {
52 utils.GoWithRecover(func() {

Callers 1

NewFunction · 0.92

Calls 3

subscribeFunction · 0.70
IsMasterOnlyMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected