valkey

package
v1.101.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2024 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultMessageDecodeFunc

func DefaultMessageDecodeFunc(_ context.Context, msg string, data any) error

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

func DefaultMessageEncodeFunc(_ context.Context, data any) (string, error)

DefaultMessageEncodeFunc is the default function to encode and serialize the input data for SendData().

func MessageDecode

func MessageDecode(msg string, data any) error

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

func MessageEncode(data any) (string, error)

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 New

func New(ctx context.Context, srvopt SrvOptions, opts ...Option) (*Client, error)

New creates a new instance of the Valkey client wrapper.

func (*Client) Close

func (c *Client) Close()

Close closes the client. All pending calls will be finished.

func (*Client) Del

func (c *Client) Del(ctx context.Context, key string) error

Del deletes the specified key from the datastore.

func (*Client) Get

func (c *Client) Get(ctx context.Context, key string) (string, error)

Get retrieves the raw string value of the specified key.

func (*Client) GetData

func (c *Client) GetData(ctx context.Context, key string, data any) error

GetData retrieves an encoded value of the specified key and extract its content in the data parameter.

func (*Client) HealthCheck

func (c *Client) HealthCheck(ctx context.Context) error

HealthCheck checks if the current data-store is alive.

func (*Client) Receive

func (c *Client) Receive(ctx context.Context) (string, string, error)

Receive receives a raw string message from a subscribed channel. Returns the channel name and the message value.

func (*Client) ReceiveData

func (c *Client) ReceiveData(ctx context.Context, data any) (string, error)

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.

func (*Client) Send

func (c *Client) Send(ctx context.Context, channel string, message string) error

Send publish a raw string value to the specified channel.

func (*Client) SendData

func (c *Client) SendData(ctx context.Context, channel string, data any) error

SendData publish an encoded value to the specified channel.

func (*Client) Set

func (c *Client) Set(ctx context.Context, key string, value string, exp time.Duration) error

Set a raw string value for the specified key with an expiration time.

func (*Client) SetData

func (c *Client) SetData(ctx context.Context, key string, data any, exp time.Duration) error

SetData sets an encoded value for the specified key with an expiration time. Zero expiration means the key has no expiration time.

type Option

type Option func(*cfg)

Option is a type to allow setting custom client options.

func WithChannels

func WithChannels(channels ...string) Option

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

func WithValkeyClient(vkclient VKClient) Option

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

type TDecodeFunc func(ctx context.Context, msg string, data any) error

TDecodeFunc is the type of function used to replace the default message decoding function used by ReceiveData().

type TEncodeFunc

type TEncodeFunc func(ctx context.Context, data any) (string, error)

TEncodeFunc is the type of function used to replace the default message encoding function used by SendData().

type VKClient

type VKClient = libvalkey.Client

VKClient represents the mockable functions in the parent Valkey Client.

type VKMessage

type VKMessage = libvalkey.PubSubMessage

VKMessage is an alias for the parent library Message type.

type VKPubSub

type VKPubSub = libvalkey.Completed

VKPubSub represents the mockable functions in the parent Valkey PubSub.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL