redis

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func FromClient

func FromClient(rdb *goredis.Client) *Client

func New

func New(addr string, opts ...Option) *Client

func (*Client) CheckLimit

func (c *Client) CheckLimit(ctx context.Context, key string, quantity, limit int64) (int64, error)

CheckLimit atomically checks if a user's purchase would exceed the limit and increments the counter. Key does not expire — in seckill scenarios Redis is the source of truth, expiry would cause DB penetration. Returns the updated purchase count, or an error if the limit would be exceeded.

func (*Client) Clear

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

func (*Client) Close

func (c *Client) Close() error

func (*Client) DeductStock

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

DeductStock atomically checks and deducts stock for a given key. Returns the remaining stock after deduction, or an error if key missing or stock insufficient.

func (*Client) Delete

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

func (*Client) Exists

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

func (*Client) Extend

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

func (*Client) Get

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

func (*Client) HDel

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

func (*Client) HExists

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

func (*Client) HGet

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

func (*Client) HGetAll

func (c *Client) HGetAll(ctx context.Context, key string) (map[string]interface{}, error)

func (*Client) HSet

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

func (*Client) Keys

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

func (*Client) LLen

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

func (*Client) LPop

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

func (*Client) LPush

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

func (*Client) LRange

func (c *Client) LRange(ctx context.Context, key string, start, stop int64, dest interface{}) error

func (*Client) Lock

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

func (*Client) RPop

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

func (*Client) RPush

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

func (*Client) Redis

func (c *Client) Redis() *goredis.Client

func (*Client) RestoreStock

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

RestoreStock adds quantity back to the stock key. Uses a single INCRBY which is already atomic — no Lua needed.

func (*Client) RollbackLimit

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

RollbackLimit decrements the user's purchase count by quantity. Used when stock deduction fails after limit check passed.

func (*Client) SAdd

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

func (*Client) SCard

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

func (*Client) SIsMember

func (c *Client) SIsMember(ctx context.Context, key string, member interface{}) (bool, error)

func (*Client) SMembers

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

func (*Client) SRem

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

func (*Client) Set

func (c *Client) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error

func (*Client) Stats

func (c *Client) Stats(ctx context.Context) (*defs.CacheStats, error)

func (*Client) TryLock

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

func (*Client) Unlock

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

func (*Client) ZAdd

func (c *Client) ZAdd(ctx context.Context, key string, members ...*defs.ScoredMember) error

func (*Client) ZRange

func (c *Client) ZRange(ctx context.Context, key string, start, stop int64, dest interface{}) error

func (*Client) ZRangeByScore

func (c *Client) ZRangeByScore(ctx context.Context, key string, min, max float64, dest interface{}) error

func (*Client) ZRem

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

func (*Client) ZScore

func (c *Client) ZScore(ctx context.Context, key string, member interface{}) (float64, error)

type Config

type Config struct {
	Addr         string
	Password     string
	DB           int
	PoolSize     int
	MinIdleConns int
	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

type Option

type Option func(*Config)

func WithDB

func WithDB(db int) Option

func WithPassword

func WithPassword(password string) Option

func WithPoolSize

func WithPoolSize(size int) Option

func WithTimeouts

func WithTimeouts(dial, read, write time.Duration) Option

Jump to

Keyboard shortcuts

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