redis

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: May 11, 2025 License: MIT Imports: 13 Imported by: 0

README

Redis Documentation

This package provides functionalities for connecting and interacting with Redis, including client initialization, stream management, and message pushing.

Environment Variables

Parameter Type Description Default
REDIS_URL string The URL of the Redis server. redis://127.0.0.1:6379

Structs

type Client

Encapsulates the Redis client and related configurations.

  • Fields:
    • Client: Underlying Redis client.
    • Logger: Logger for logging messages.
    • UUIDMapper: UUIDMapper for mapping UUIDs.
    • Configuration: Redis connection settings.
    • Context: Context for controlling operations.

Functions

func NewClient(logger *logrus.Logger, ctx context.Context, cancel context.CancelFunc) (*Client, error)

Initializes and returns a new Redis client.

  • Parameters:

    • logger: A logger instance for logging.
    • ctx: The context for client operations.
    • cancel: A cancel function to stop the context.
  • Returns:
    A pointer to the initialized Client and an error if any occurred.

func (rc *Client) Close() error

Closes the Redis client connection after synchronizing the UUID map.

  • Returns:
    An error if closing fails.
func (rc *Client) PushToRedis(uuid string, max int64, data map[string]interface{}) error

Adds data to a specified Redis stream with approximate pruning.

  • Parameters:

    • uuid: The name of the Redis stream.
    • max: The maximum number of records to retain in the stream.
    • data: The data to be added to the stream.
  • Returns:
    An error if the operation fails.

func (rc *Client) ListenForCommands(startFunc, stopFunc func() error)

Subscribes to the Redis channel and listens for start and stop commands.

  • Parameters:
    • startFunc: The function to execute when a start command is received.
    • stopFunc: The function to execute when a stop command is received.
func (rc *Client) GenerateUUIDMap(createValidKeysFunc func() map[string]interface{}) error

Verifies the current UUID mappings against the provided configurations.

  • Parameters:

    • createValidKeysFunc: A function that generates a set of valid keys as map[string]interface{}.
  • Returns:
    An error if the operation fails.

Documentation

Overview

*

  • Package redis provides functionalities for connecting and interacting with Redis,
  • including client initialization, stream management, and message pushing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Client        *redis.Client        // Underlying Redis client.
	Logger        *logrus.Logger       // Logger for logging messages.
	UUIDMapper    *uuid.UUIDMapper     // UUIDMapper for mapping UUIDs.
	Configuration *configuration.Redis // Redis connection settings.
	PubSub        *redis.PubSub        // PubSub client for listening to commands.
	Context       context.Context      // Context for controlling operations.
	// contains filtered or unexported fields
}

*

  • Client encapsulates the Redis client and related configurations.

func NewClient

func NewClient(logger *logrus.Logger, ctx context.Context) (*Client, error)

*

  • NewClient initializes and returns a new Redis client. *
  • @param logger A logger instance for logging.
  • @param ctx The context for client operations.
  • @return A pointer to the initialized Client and an error if any occurred.

func (*Client) Close

func (rc *Client) Close() error

*

  • Close closes the Redis client connection after synchronizing the UUID map.
  • Includes timeouts to prevent blocking indefinitely during shutdown. *
  • @return An error if closing fails.

func (*Client) DisableAsyncBatching

func (rc *Client) DisableAsyncBatching()

*

  • DisableAsyncBatching disables async batching and flushes remaining items.

func (*Client) EnableAsyncBatching

func (rc *Client) EnableAsyncBatching(batchSize int, batchTimeout time.Duration)

*

  • EnableAsyncBatching enables asynchronous batched XADD operations. *
  • @param batchSize The number of records per pipeline batch.
  • @param batchTimeout The maximum wait time before flushing a batch.

func (*Client) GenerateUUIDMap

func (rc *Client) GenerateUUIDMap(createValidKeysFunc func() map[string]interface{}) error

*

  • GenerateUUIDMap verifies the current UUID mappings against the provided configurations. *
  • @param createValidKeysFunc A function that generates a set of valid keys as map[string]interface{}.
  • @return An error if the operation fails.

func (*Client) ListenForCommands

func (rc *Client) ListenForCommands(startFunc, stopFunc func() error)

*

  • ListenForCommands subscribes to the Redis channel and listens for start and stop commands.
  • Includes timeout checks to prevent blocking during shutdown. *
  • @param startFunc The function to execute when a start command is received.
  • @param stopFunc The function to execute when a stop command is received.

func (*Client) PushToRedis

func (rc *Client) PushToRedis(uuid string, max int64, data map[string]interface{}) error

*

  • PushToRedis adds data to a specified Redis stream with approximate pruning. *
  • @param uuid The name of the Redis stream.
  • @param max The maximum number of records to retain in the stream.
  • @param data The data to be added to the stream.
  • @return An error if the operation fails.

func (*Client) PushToRedisAsync

func (rc *Client) PushToRedisAsync(uuid string, max int64, data map[string]interface{}) error

*

  • PushToRedisAsync enqueues a stream entry for asynchronous batched XADD. *
  • @param uuid The name of the Redis stream.
  • @param max The maximum number of records to retain in the stream.
  • @param data The data to be added to the stream.
  • @return An error if async batching is not enabled or context is canceled.

Directories

Path Synopsis
*
*
*
*
*

Jump to

Keyboard shortcuts

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