Documentation ¶
Overview ¶
Package valkey provides a simple and basic wrapper client for interacting with Valkey (https://valkey.io), an open source in-memory data store.
Based on https://github.com/valkey-io/valkey-go, it abstracts away the complexities of the valkey protocol and provides a simplified interface.
This package includes functions for setting, getting, and deleting key/value entries. Additionally, it supports sending and receiving messages from channels.
It allows to specify custom message encoding and decoding functions, including serialization and encryption.
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 Client
- func (c *Client) Close()
- func (c *Client) Del(ctx context.Context, key string) error
- func (c *Client) Get(ctx context.Context, key string) (string, 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 string) error
- func (c *Client) SendData(ctx context.Context, channel string, data any) error
- func (c *Client) Set(ctx context.Context, key string, value string, exp time.Duration) error
- func (c *Client) SetData(ctx context.Context, key string, data any, exp time.Duration) error
- type Option
- type SrvOptions
- type TDecodeFunc
- type TEncodeFunc
- type VKClient
- type VKMessage
- type VKPubSub
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 Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a wrapper for the Valkey Client.
func (*Client) Close ¶
func (c *Client) Close()
Close closes the client. All pending calls will be finished.
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 WithChannels ¶
WithChannels sets the channels to subscribe to and receive data from.
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.
func WithValkeyClient ¶
WithValkeyClient overrides the default Valkey client. This function is mainly used for testing.
type SrvOptions ¶
type SrvOptions = libvalkey.ClientOption
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().
type TEncodeFunc ¶
TEncodeFunc is the type of function used to replace the default message encoding function used by SendData().
type VKMessage ¶
type VKMessage = libvalkey.PubSubMessage
VKMessage is an alias for the parent library Message type.