Documentation
¶
Index ¶
- Variables
- type PuzzleRedisClient
- func (c *PuzzleRedisClient) GetValue(ctx context.Context, key string, result any) error
- func (c *PuzzleRedisClient) LPopValue(ctx context.Context, key string, result any) error
- func (c *PuzzleRedisClient) LPushValue(ctx context.Context, key string, values ...any) error
- func (c *PuzzleRedisClient) RPopValue(ctx context.Context, key string, result any) error
- func (c *PuzzleRedisClient) RPushValue(ctx context.Context, key string, values ...any) error
- func (c *PuzzleRedisClient) RRangeValue(ctx context.Context, key string, start, stop int64, resultPtr any) error
- func (c *PuzzleRedisClient) RangeValue(ctx context.Context, key string, start, stop int64, resultPtr any) error
- func (c *PuzzleRedisClient) SetValue(ctx context.Context, key string, value any, expiration time.Duration) error
- func (c *PuzzleRedisClient) TryLock(ctx context.Context, key string, expiration time.Duration) error
- func (c *PuzzleRedisClient) TryLockWithTimeout(ctx context.Context, key string, expiration, timeout time.Duration) error
- func (c *PuzzleRedisClient) Unlock(ctx context.Context, key string) error
- type RedisConf
Constants ¶
This section is empty.
Variables ¶
var ( // ErrLockAcquireFailed indicates failure to acquire the lock ErrLockAcquireFailed = errors.New("failed to acquire lock") // ErrLockNotFound indicates the lock does not exist ErrLockNotFound = errors.New("lock not found") // ErrLockReleaseFailed indicates failure to release the lock ErrLockReleaseFailed = errors.New("failed to release lock") // ErrLockTimeout indicates lock acquisition timeout ErrLockTimeout = errors.New("lock timeout") )
Define error types
Functions ¶
This section is empty.
Types ¶
type PuzzleRedisClient ¶
type PuzzleRedisClient struct { *redis.Client // contains filtered or unexported fields }
func NewRedisClient ¶
func NewRedisClient(addr string, db int) *PuzzleRedisClient
func NewRedisClientWithAuth ¶
func NewRedisClientWithAuth(addr string, db int, user, pwd string) *PuzzleRedisClient
func (*PuzzleRedisClient) GetValue ¶
GetValue retrieves a value from Redis with automatic type conversion The result parameter must be a pointer Supported types: - string - []byte - int - int64 - float32 - float64 - bool - time.Time For other types, JSON deserialization will be performed
func (*PuzzleRedisClient) LPushValue ¶ added in v1.1.21
func (*PuzzleRedisClient) RPushValue ¶ added in v1.1.21
func (*PuzzleRedisClient) RRangeValue ¶ added in v1.1.21
func (c *PuzzleRedisClient) RRangeValue(ctx context.Context, key string, start, stop int64, resultPtr any) error
RRangeValue retrieves a range of values from the list starting from the right and converts them to the specified slice type start and stop are inclusive indices counted from the right For example: 0, 10 means get the first 11 elements from the right Note: start and stop are counted from the right, where 0 represents the rightmost element
func (*PuzzleRedisClient) RangeValue ¶ added in v1.1.21
func (c *PuzzleRedisClient) RangeValue(ctx context.Context, key string, start, stop int64, resultPtr any) error
RangeValue retrieves a range of values from the list and converts them to the specified slice type start and stop are inclusive indices For example: 0, 10 means get the first 11 elements -1 represents the last element, -2 represents the second to last element, and so on
func (*PuzzleRedisClient) SetValue ¶
func (c *PuzzleRedisClient) SetValue(ctx context.Context, key string, value any, expiration time.Duration) error
SetValue stores any type of value in Redis with automatic type handling
func (*PuzzleRedisClient) TryLock ¶
func (c *PuzzleRedisClient) TryLock(ctx context.Context, key string, expiration time.Duration) error
TryLock attempts to acquire a distributed lock
func (*PuzzleRedisClient) TryLockWithTimeout ¶
func (c *PuzzleRedisClient) TryLockWithTimeout(ctx context.Context, key string, expiration, timeout time.Duration) error
TryLockWithTimeout attempts to acquire a lock with a timeout
type RedisConf ¶
type RedisConf struct { Server string `desc:"redis server name (default localhost:6379)"` Db int `desc:"redis db (default 0)"` Username string `desc:"redis username"` Password string `desc:"redis server password"` }
func (*RedisConf) DialRedisClient ¶ added in v1.1.20
func (conf *RedisConf) DialRedisClient() *PuzzleRedisClient
func (*RedisConf) SetDefault ¶
func (conf *RedisConf) SetDefault()