Documentation
¶
Index ¶
- type Client
- func (c *Client) CheckLimit(ctx context.Context, key string, quantity, limit int64) (int64, error)
- func (c *Client) Clear(ctx context.Context) error
- func (c *Client) Close() error
- func (c *Client) DeductStock(ctx context.Context, key string, quantity int64) (int64, error)
- func (c *Client) Delete(ctx context.Context, key string) error
- func (c *Client) Exists(ctx context.Context, key string) (bool, error)
- func (c *Client) Extend(ctx context.Context, key string, ttl time.Duration) error
- func (c *Client) Get(ctx context.Context, key string, dest interface{}) error
- func (c *Client) HDel(ctx context.Context, key, field string) error
- func (c *Client) HExists(ctx context.Context, key, field string) (bool, error)
- func (c *Client) HGet(ctx context.Context, key, field string, dest interface{}) error
- func (c *Client) HGetAll(ctx context.Context, key string) (map[string]interface{}, error)
- func (c *Client) HSet(ctx context.Context, key, field string, value interface{}) error
- func (c *Client) Keys(ctx context.Context, pattern string) ([]string, error)
- func (c *Client) LLen(ctx context.Context, key string) (int64, error)
- func (c *Client) LPop(ctx context.Context, key string, dest interface{}) error
- func (c *Client) LPush(ctx context.Context, key string, values ...interface{}) error
- func (c *Client) LRange(ctx context.Context, key string, start, stop int64, dest interface{}) error
- func (c *Client) Lock(ctx context.Context, key string, ttl time.Duration) error
- func (c *Client) RPop(ctx context.Context, key string, dest interface{}) error
- func (c *Client) RPush(ctx context.Context, key string, values ...interface{}) error
- func (c *Client) Redis() *goredis.Client
- func (c *Client) RestoreStock(ctx context.Context, key string, quantity int64) error
- func (c *Client) RollbackLimit(ctx context.Context, key string, quantity int64) error
- func (c *Client) SAdd(ctx context.Context, key string, members ...interface{}) error
- func (c *Client) SCard(ctx context.Context, key string) (int64, error)
- func (c *Client) SIsMember(ctx context.Context, key string, member interface{}) (bool, error)
- func (c *Client) SMembers(ctx context.Context, key string, dest interface{}) error
- func (c *Client) SRem(ctx context.Context, key string, members ...interface{}) error
- func (c *Client) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (c *Client) Stats(ctx context.Context) (*defs.CacheStats, error)
- func (c *Client) TryLock(ctx context.Context, key string, ttl time.Duration) (bool, error)
- func (c *Client) Unlock(ctx context.Context, key string) error
- func (c *Client) ZAdd(ctx context.Context, key string, members ...*defs.ScoredMember) error
- func (c *Client) ZRange(ctx context.Context, key string, start, stop int64, dest interface{}) error
- func (c *Client) ZRangeByScore(ctx context.Context, key string, min, max float64, dest interface{}) error
- func (c *Client) ZRem(ctx context.Context, key string, members ...interface{}) error
- func (c *Client) ZScore(ctx context.Context, key string, member interface{}) (float64, error)
- type Config
- type Option
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 (*Client) CheckLimit ¶
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) DeductStock ¶
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) RestoreStock ¶
RestoreStock adds quantity back to the stock key. Uses a single INCRBY which is already atomic — no Lua needed.
func (*Client) RollbackLimit ¶
RollbackLimit decrements the user's purchase count by quantity. Used when stock deduction fails after limit check passed.