Documentation
¶
Index ¶
- Constants
- Variables
- type Error
- type Message
- func (m *Message) Get(redisKey string) (interface{}, error)
- func (m *Message) GetIP(nodeUID string) (string, error)
- func (m *Message) GetIPWaiting(ctx context.Context, nodeUID string) (string, error)
- func (m *Message) GetWaiting(ctx context.Context, redisKey string) (interface{}, error)
- func (m *Message) OnReceive(key string, handler func(value interface{}))
- func (m *Message) OnReceiveGlobal(key string, handler func(value interface{}))
- func (m *Message) Receive(key string) (interface{}, error)
- func (m *Message) ReceiveGlobal(key string) (interface{}, error)
- func (m *Message) Send(receiverUID, key string, value interface{}) error
- func (m *Message) SendGlobal(key string, value interface{}) error
- func (m *Message) Set(redisKey string, value interface{}) error
- func (m *Message) SetIP(ipAddr string) error
Constants ¶
const ( DefaultMsgExpireTime = 24 * time.Hour DefaultRetryIntervalForGetWaiting = 2 * time.Second EnvRedisAddr = "REDIS_ADDR" EnvRedisDB = "REDIS_DB" EnvRedisPassword = "REDIS_PASS" )
Variables ¶
var ( ErrSetGlobal = &Error{Code: "ErrSetGlobal", Message: "Error setting global message"} ErrPublish = &Error{Code: "ErrPublish", Message: "Error publishing a message"} ErrSetIP = &Error{Code: "ErrSetIP", Message: "Error setting IP"} ErrGetIP = &Error{Code: "ErrGetIP", Message: "Error getting IP"} ErrMsgNotFound = &Error{Code: "ErrMsgNotFound", Message: "Message not found"} ErrGetPubResult = &Error{Code: "ErrGetPubResult", Message: "Error getting publish result"} ErrNoSubscribers = &Error{Code: "ErrNoSubscribers", Message: "No subscribers"} ErrTypeCasting = &Error{Code: "ErrTypeCasting", Message: "Type casting failed"} ErrCtxDone = &Error{Code: "ErrCtxDone", Message: "Context Done"} )
Functions ¶
This section is empty.
Types ¶
type Message ¶
type Message struct { Client *redis.Client NodeUID string // the UID is used to identify the node and to receive messages }
func (*Message) GetIPWaiting ¶
GetIPWaiting gets the IP address of a node with the given UID. It waits until either the IP address is set by the node or the context is done.
func (*Message) GetWaiting ¶
GetWaiting gets the value of the given key from Redis. It waits until the value is set by someone or the context is done.
func (*Message) OnReceive ¶
OnReceive sets a handler to receive messages from the given key. The handler will be called when a message is received from the given key.
func (*Message) OnReceiveGlobal ¶
OnReceiveGlobal sets a handler to receive messages from the given key. The handler will be called when a message is received from the given key.
func (*Message) Receive ¶
Receive receives a message from the given key. It waits until a message is received from the given key.
func (*Message) ReceiveGlobal ¶
ReceiveGlobal receives a message from the given key. It waits until a message is received from the given key.
func (*Message) Send ¶
Send sends a message to the receiver with the given UID. Please note that the other node must be listening to the same key to receive the message.
func (*Message) SendGlobal ¶
SendGlobal sends a message to all nodes with the given key. Please note that the other nodes must be listening to the same key to receive the message.