Documentation ¶
Overview ¶
Package redis provides a simple and basic wrapper client for interacting with Redis, an in-memory data store. It includes functions for setting, getting, and deleting key/value entries. Additionally, it supports sending and receiving messages from channels. The package also allows for custom message encoding and decoding functions.
This package is based on the official go-redis library.
For more information, please refer to the official Redis website: https://redis.io And the go-redis library on GitHub: https://github.com/redis/go-redis
Index ¶
- func DefaultMessageDecodeFunc(_ context.Context, msg string, data any) error
- func DefaultMessageEncodeFunc(_ context.Context, data any) (string, error)
- func MessageDecode(msg string, data any) error
- func MessageEncode(data any) (string, error)
- type ChannelOption
- type Client
- func (c *Client) Close() error
- func (c *Client) Del(ctx context.Context, key string) error
- func (c *Client) Get(ctx context.Context, key string, value any) error
- func (c *Client) GetData(ctx context.Context, key string, data any) error
- func (c *Client) HealthCheck(ctx context.Context) error
- func (c *Client) Receive(ctx context.Context) (string, string, error)
- func (c *Client) ReceiveData(ctx context.Context, data any) (string, error)
- func (c *Client) Send(ctx context.Context, channel string, message any) error
- func (c *Client) SendData(ctx context.Context, channel string, data any) error
- func (c *Client) Set(ctx context.Context, key string, value any, exp time.Duration) error
- func (c *Client) SetData(ctx context.Context, key string, data any, exp time.Duration) error
- type Option
- type RClient
- type RMessage
- type RPubSub
- type SrvOptions
- type TDecodeFunc
- type TEncodeFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultMessageDecodeFunc ¶
DefaultMessageDecodeFunc is the default function to decode a message for ReceiveData(). The value underlying data must be a pointer to the correct type for the next data item received.
func DefaultMessageEncodeFunc ¶
DefaultMessageEncodeFunc is the default function to encode and serialize the input data for SendData().
func MessageDecode ¶
MessageDecode decodes a message encoded with MessageEncode to the provided data object. The value underlying data must be a pointer to the correct type for the next data item received.
func MessageEncode ¶
MessageEncode encodes and serialize the input data to a string.
Types ¶
type ChannelOption ¶
type ChannelOption = libredis.ChannelOption
ChannelOption is an alias for the parent library ChannelOption.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a wrapper for the Redis Client.
func (*Client) Get ¶
Get retrieves the raw value of the specified key and extract its content in the value parameter.
func (*Client) GetData ¶
GetData retrieves an encoded value of the specified key and extract its content in the data parameter.
func (*Client) HealthCheck ¶
HealthCheck checks if the current data-store is alive.
func (*Client) Receive ¶
Receive receives a raw string message from a subscribed channel. Returns the channel name and the message value.
func (*Client) ReceiveData ¶
ReceiveData receives an encoded message from a subscribed channel, and extract its content in the data parameter. Returns the channel name in case of success.
type Option ¶
type Option func(*cfg)
Option is a type to allow setting custom client options.
func WithMessageDecodeFunc ¶
func WithMessageDecodeFunc(f TDecodeFunc) Option
WithMessageDecodeFunc allow to replace DefaultMessageDecodeFunc(). This function used by ReceiveData() to decode a message encoded with messageEncodeFunc to the provided data object. The value underlying data must be a pointer to the correct type for the next data item received.
func WithMessageEncodeFunc ¶
func WithMessageEncodeFunc(f TEncodeFunc) Option
WithMessageEncodeFunc allow to replace DefaultMessageEncodeFunc. This function used by SendData() to encode and serialize the input data to a string compatible with SQS.
func WithSubscrChannelOptions ¶
func WithSubscrChannelOptions(opts ...ChannelOption) Option
WithSubscrChannelOptions sets options for the subscribed channels.
func WithSubscrChannels ¶
WithSubscrChannels sets the channels to subscribe to and receive data from.
type RClient ¶
type RClient interface { Close() error Del(ctx context.Context, keys ...string) *libredis.IntCmd Get(ctx context.Context, key string) *libredis.StringCmd Ping(ctx context.Context) *libredis.StatusCmd // this function is used by the HealthCheck Publish(ctx context.Context, channel string, message any) *libredis.IntCmd Set(ctx context.Context, key string, value any, expiration time.Duration) *libredis.StatusCmd Subscribe(ctx context.Context, channels ...string) *libredis.PubSub }
RClient represents the mockable functions in the parent Redis Client.
type RPubSub ¶
type RPubSub interface { Channel(opts ...libredis.ChannelOption) <-chan *libredis.Message Close() error }
RPubSub represents the mockable functions in the parent Redis PubSub.
type SrvOptions ¶
SrvOptions is an alias for the parent library client options.
type TDecodeFunc ¶
TDecodeFunc is the type of function used to replace the default message decoding function used by ReceiveData().