redisext

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name = "Redis"
)

Variables

This section is empty.

Functions

func ToContext

func ToContext(ctx context.Context, client *Client) context.Context

Types

type Client

type Client struct {
	Configs
	DB      *redis.Client
	Queue   rmq.Connection
	Lock    *redsync.Redsync
	Limiter *redis_rate.Limiter

	Atomic *redislock.Client
	// contains filtered or unexported fields
}

func Connect

func Connect(ctx context.Context, configs Configs) (*Client, error)

func FromContext

func FromContext(ctx context.Context) *Client

func (*Client) Close

func (c *Client) Close() error

func (*Client) Del

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

func (*Client) Exists

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

func (*Client) Expire

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

func (*Client) Get

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

func (*Client) Limit

func (c *Client) Limit(ctx context.Context, ns, key string, limit redis_rate.Limit) (*redis_rate.Result, error)

func (*Client) LimitReport

func (c *Client) LimitReport(ctx context.Context, ns, key string, limit redis_rate.Limit) (*redis_rate.Result, error)

func (*Client) NewMutex

func (c *Client) NewMutex(ns, key string, exp time.Duration) *redsync.Mutex

func (*Client) ObtainAtomic

func (c *Client) ObtainAtomic(ctx context.Context, ns, key string, exp time.Duration) (*redislock.Lock, error)

func (*Client) OpenQueue

func (c *Client) OpenQueue(name string) (*Queue, error)

func (*Client) Set

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

type Configs

type Configs struct {
	RedisAddress       string        `env:"REDIS_ADDRESS,required"`
	RedisUsername      string        `env:"REDIS_USERNAME"`
	RedisPassword      string        `env:"REDIS_PASSWORD"`
	RedisDatabase      int           `env:"REDIS_DATABASE"`
	RedisTLSRequired   bool          `env:"REDIS_TLS_REQUIRED"`
	RedisQueueCleaning time.Duration `env:"REDIS_QUEUE_CLEANING" envDefault:"1m"`
	RedisQueuePool     int64         `env:"REDIS_QUEUE_POOL" envDefault:"10"`
	RedisQueueApp      string        `env:"REDIS_QUEUE_APP" envDefault:"app"`
}

type Consumer

type Consumer interface {
	Tag() string
	Consume(delivery *Delivery) error
}

type Delivery

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

func (Delivery) Ack

func (d Delivery) Ack()

func (Delivery) Payload

func (d Delivery) Payload(value any) error

func (Delivery) Push

func (d Delivery) Push()

func (Delivery) Reject

func (d Delivery) Reject()

type Queue

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

func (*Queue) Publish

func (q *Queue) Publish(value any) error

func (*Queue) SetConsumer

func (q *Queue) SetConsumer(c Consumer) error

Jump to

Keyboard shortcuts

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