redis

package
v0.0.0-...-20e6d49 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Nil          = redis.Nil
	ErrConfigNil = eris.New("redis config is nil")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*redis.Client
	// contains filtered or unexported fields
}

Client wraps the Redis client with additional functionality

func NewClient

func NewClient(p ClientParams) (*Client, error)

NewClient creates a new Redis client instance with the provided configuration and logger.

func (*Client) Del

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

Del is a helper function to delete a key from redis

func (*Client) Exists

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

Exists checks if a key exists

func (*Client) Expire

func (c *Client) Expire(ctx context.Context, key string, expiration time.Duration) error

Expire sets an expiration time for a key in Redis.

func (*Client) Get

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

Get is a helper function to get a value from redis

func (*Client) GetInt

func (c *Client) GetInt(ctx context.Context, key string, defaultVal int) (int, error)

GetInt retrieves an integer value for a key from Redis, returning a default value if the key does not exist.

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, key string, dest any) error

GetJSON retrieves a JSON-encoded value from Redis and unmarshals it into the provided destination.

func (*Client) GetTTL

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

GetTTL returns the remaining TTL for a key

func (*Client) HGet

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

HGet retrieves a field's value from a Redis hash.

func (*Client) HSet

func (c *Client) HSet(ctx context.Context, key, field string, value interface{}) error

HSet sets a field in a Redis hash to a specified value.

func (*Client) Incr

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

Incr increments the integer value of a key in Redis by 1.

func (*Client) IncrBy

func (c *Client) IncrBy(ctx context.Context, key string, value int64) (int64, error)

IncrBy increments the integer value of a key in Redis by a specified amount.

func (*Client) IncreaseWithExpiry

func (c *Client) IncreaseWithExpiry(ctx context.Context, key string, expiry time.Duration) (int64, error)

IncreaseWithExpiry increments a key's value and sets an expiration time atomically.

func (*Client) Keys

func (c *Client) Keys(ctx context.Context, pattern string) ([]string, error)

Keys returns all keys matching a pattern

func (*Client) Pipeline

func (c *Client) Pipeline() redis.Pipeliner

Pipeline returns a new pipeline for batch operations

func (*Client) SAdd

func (c *Client) SAdd(ctx context.Context, key string, members ...interface{}) error

SAdd adds one or more members to a Redis set.

func (*Client) SMembers

func (c *Client) SMembers(ctx context.Context, key string) ([]string, error)

SMembers retrieves all members of a Redis set.

func (*Client) SRem

func (c *Client) SRem(ctx context.Context, key string, members ...interface{}) error

SRem removes one or more members from a Redis set.

func (*Client) Set

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

Set sets a value in Redis with a specified expiration time.

func (*Client) SetJSON

func (c *Client) SetJSON(ctx context.Context, key string, value any, expiration time.Duration) error

SetJSON marshals a value as JSON and stores it in Redis with a specified expiration time.

func (*Client) Transaction

func (c *Client) Transaction(ctx context.Context, fn func(tx *redis.Tx) error) error

Transaction executes a transactional operation on Redis.

type ClientParams

type ClientParams struct {
	fx.In

	Config *config.Manager
	Logger *logger.Logger
}

type Pipeliner

type Pipeliner struct {
	// contains filtered or unexported fields
}

func (*Pipeliner) Exec

func (p *Pipeliner) Exec(ctx context.Context) error

func (*Pipeliner) Queue

func (p *Pipeliner) Queue(cmd infra.CacheCommand)

type StringCmd

type StringCmd = redis.StringCmd

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳