Documentation
¶
Index ¶
- func New[T any](ctx context.Context, redisConfig *redisutil.Config, keyFunc timer.KeyFunc[T], ...) (timer.Manager[T], error)
- func NewWithClient[T any](ctx context.Context, client redis.UniversalClient, keyFunc timer.KeyFunc[T], ...) (timer.Manager[T], error)
- type Option
- func WithBatchSize[T any](size int) Option[T]
- func WithMarshal[T any](fn func(T) ([]byte, error)) Option[T]
- func WithNamespace[T any](namespace string) Option[T]
- func WithPollInterval[T any](interval time.Duration) Option[T]
- func WithSelfContainedKey[T any]() Option[T]
- func WithUnmarshal[T any](fn func([]byte) (T, error)) Option[T]
- type RedisTimer
- func (r *RedisTimer[T]) Cancel(ctx context.Context, timerType string, key string) error
- func (r *RedisTimer[T]) Close() error
- func (r *RedisTimer[T]) GetPending(ctx context.Context, timerType string) (int64, error)
- func (r *RedisTimer[T]) Register(ctx context.Context, timerType string, item T, timeout time.Duration) error
- func (r *RedisTimer[T]) RegisterAt(ctx context.Context, timerType string, item T, expireAt time.Time) error
- func (r *RedisTimer[T]) RegisterAtIfNotExists(ctx context.Context, timerType string, item T, expireAt time.Time) (bool, error)
- func (r *RedisTimer[T]) RegisterIfNotExists(ctx context.Context, timerType string, item T, timeout time.Duration) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New[T any](ctx context.Context, redisConfig *redisutil.Config, keyFunc timer.KeyFunc[T], handlers timer.HandlerMap[T], opts ...Option[T]) (timer.Manager[T], error)
New creates a new Redis-based timer manager and starts processing
func NewWithClient ¶
func NewWithClient[T any](ctx context.Context, client redis.UniversalClient, keyFunc timer.KeyFunc[T], handlers timer.HandlerMap[T], opts ...Option[T]) (timer.Manager[T], error)
NewWithClient creates a timer manager with existing Redis client and starts processing
Types ¶
type Option ¶
type Option[T any] func(*RedisTimer[T])
Option configures a RedisTimer
func WithBatchSize ¶
WithBatchSize sets the batch size for processing expired timers
func WithMarshal ¶
WithMarshal sets custom marshal function
func WithNamespace ¶
WithNamespace sets the Redis key namespace
func WithPollInterval ¶
WithPollInterval sets the polling interval for checking expired timers
func WithSelfContainedKey ¶
WithSelfContainedKey indicates that the key itself contains all the data. This option is only valid for string types (T must be string). When enabled:
- No additional hash storage is used
- The ZSET member (key) is the data itself
- More efficient for simple string timers
Example usage:
manager := New[string](ctx, config, func(s string) string { return s }, handlers, WithSelfContainedKey[string]())
type RedisTimer ¶
type RedisTimer[T any] struct { // contains filtered or unexported fields }
RedisTimer implements timer.Manager using Redis
func (*RedisTimer[T]) Close ¶
func (r *RedisTimer[T]) Close() error
Close releases resources and stops processing
func (*RedisTimer[T]) GetPending ¶
GetPending returns the count of pending timers for a specific type
func (*RedisTimer[T]) Register ¶
func (r *RedisTimer[T]) Register(ctx context.Context, timerType string, item T, timeout time.Duration) error
Register adds an item with a timeout duration for a specific type If a timer with the same key already exists, it will be updated (upsert behavior)
func (*RedisTimer[T]) RegisterAt ¶
func (r *RedisTimer[T]) RegisterAt(ctx context.Context, timerType string, item T, expireAt time.Time) error
RegisterAt adds an item that expires at a specific time for a specific type
func (*RedisTimer[T]) RegisterAtIfNotExists ¶
func (r *RedisTimer[T]) RegisterAtIfNotExists(ctx context.Context, timerType string, item T, expireAt time.Time) (bool, error)
RegisterAtIfNotExists adds an item that expires at a specific time only if it doesn't exist Returns false if timer already exists, true if newly registered
func (*RedisTimer[T]) RegisterIfNotExists ¶
func (r *RedisTimer[T]) RegisterIfNotExists(ctx context.Context, timerType string, item T, timeout time.Duration) (bool, error)
RegisterIfNotExists adds an item with a timeout duration only if it doesn't exist Returns false if timer already exists, true if newly registered