Documentation
¶
Index ¶
Constants ¶
const ( DefaultBlockInterval = 10 * time.Second DefaultConcurency = 25 )
Variables ¶
var ErrClientClosed = errors.New("client closed")
var ErrNilContext = errors.New("context is nil")
var ErrNoStash = errors.New("stash not found in context")
var ErrUnexpectedStashType = errors.New("unexpected stash type")
Functions ¶
func ParseStash ¶ added in v0.3.0
ParseStash parses the stash value from the context and unmarshals it into the provided value. It returns an error if the stash value is not found in the context or if it has an unexpected type.
func SetStash ¶ added in v0.3.0
SetStash sets the stash value in the context. It marshals the stash value to JSON and stores it in the context using a specific key. If the context is nil, it returns an error. If there is an error while marshalling the stash value, it returns an error with the specific error message. Otherwise, it returns the updated context with the stash value set.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(redisClient *redis.Client, channel string, opts ...ClientOption) *Client
NewClient creates a new instance of the Client struct. It takes a Redis client and a channel name as parameters. It returns a pointer to the newly created Client.
func (*Client) Call ¶
Call sends a request to the server using the specified method and parameters. It returns the response received from the server or an error if the request fails. The context `ctx` is used for cancellation and timeout. The `method` parameter specifies the method to be called on the server. The `params` parameter contains the parameters to be passed to the server method. The returned response is of type `*Response` and contains the result of the server method call. If an error occurs during the request or if the server returns an error response, an error is returned with a descriptive error message.
type ClientOption ¶ added in v0.3.0
type ClientOption func(*Client)
ClientOption is a function type that can be used to configure a Client. It takes a pointer to a Client and modifies its properties.
func WithInterceptors ¶ added in v0.3.0
func WithInterceptors(interceptors ...Interceptor) ClientOption
WithInterceptors adds the provided interceptors to the client.
type Interceptor ¶ added in v0.3.0
type Interceptor func(next RequestHandler) RequestHandler
type Request ¶
type Request struct { Method string ID string ReplyTo string // contains filtered or unexported fields }
func NewRequest ¶
NewRequest creates a new Request with the provided parameters. It returns a Request interface.
func (*Request) ParseParams ¶
ParseParams parses the JSON-encoded parameters of the request into the provided value. The value must be a pointer to the desired type.
type RequestHandler ¶ added in v0.3.0
type Response ¶
type Response struct { ID string `json:"id"` Error string `json:"error,omitempty"` Result json.RawMessage `json:"result,omitempty"` }
Response represents the response structure for a Redis RPC call.
func NewResponse ¶ added in v0.3.0
newResponse creates a new instance of the Response struct.
func (*Response) ParseResut ¶
ParseResut parses the result of the response into the provided value. The result is expected to be in JSON format and will be unmarshaled into the provided value.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(redisClient *redis.Client, stream, group, consumer string, opts ...ServerOption) *Server
NewServer creates a new instance of the Server struct. It takes a Redis client, stream name, consumer group name, and consumer name as parameters. It returns a pointer to the newly created Server instance.
func (*Server) AddHandler ¶
AddHandler adds a new RPC handler to the server. It associates the given `handler` with the specified `rpcName`. If a handler already exists for the same `rpcName`, it panics.
func (*Server) Close ¶
func (s *Server) Close()
Close stops the server gracefully by cancelling the context and waiting for all goroutines to finish.
func (*Server) Run ¶
Run starts the server and continuously reads messages from the Redis stream. It initializes the reader, sets up the read arguments, and enters an infinite loop to read messages from the stream. It processes each message by calling the `processMessage` method.
If an error occurs during initialization or reading the stream, it returns the error. If the stream is empty, it continues to the next iteration.
The `Run` method is responsible for running the server and handling the continuous message processing from the Redis stream.
type ServerOption ¶ added in v0.3.0
type ServerOption func(*Server)
ServerOption is a function type that can be used to configure a Server. It takes a pointer to a Server and modifies its properties.
func WithServerInterceptors ¶ added in v0.3.0
func WithServerInterceptors(interceptors ...Interceptor) ServerOption
WithMiddleware is a function that returns a ServerOption which sets the middleware for the server. Middleware is a list of Interceptor functions that will be applied to incoming requests.