Documentation
¶
Index ¶
- Variables
- func NewClient(host string) *redis.Client
- func NewGCSClient(ctx context.Context, credentialsFile, url string) (*gcs.Client, error)
- type GCSStorage
- func (s *GCSStorage[T]) Get(ctx context.Context, key string) (T, error)
- func (s *GCSStorage[T]) Remove(ctx context.Context, key string) error
- func (s *GCSStorage[T]) Set(ctx context.Context, key string, item T) error
- func (s *GCSStorage[T]) SetWithTTL(ctx context.Context, key string, item T, expiration time.Duration) error
- type Notifier
- type Observer
- type Queue
- type RedisStorage
- func (s *RedisStorage[T]) Clear(ctx context.Context) error
- func (s *RedisStorage[T]) Dequeue(ctx context.Context) (T, error)
- func (s *RedisStorage[T]) Enqueue(ctx context.Context, item T) error
- func (s *RedisStorage[T]) Get(ctx context.Context, key string) (T, error)
- func (s *RedisStorage[T]) Publish(ctx context.Context, channel string) error
- func (s *RedisStorage[T]) QueueLength(ctx context.Context) (int64, error)
- func (s *RedisStorage[T]) Remove(ctx context.Context, key string) error
- func (s *RedisStorage[T]) Set(ctx context.Context, key string, item T) error
- func (s *RedisStorage[T]) SetWithTTL(ctx context.Context, key string, item T, expiration time.Duration) error
- func (s *RedisStorage[T]) Subscribe(ctx context.Context, channel string) Subscription
- type Storage
- type Subscription
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyKey = errors.New("empty key")
ErrEmptyKey is returned by Set/SetWithTTL when called with an empty key, which Redis treats as a no-op.
var ErrEmptyQueue = errors.New("empty queue")
ErrEmptyQueue signals that Dequeue had no item to return; callers use it to distinguish empty from error.
var ErrNotFound = errors.New("not found")
ErrNotFound is returned by Storage implementations when a key does not exist or has expired.
Functions ¶
func NewGCSClient ¶ added in v0.0.20
NewGCSClient creates a new Google Cloud Storage client.
If credentialsFile is empty, Application Default Credentials are used. If url is non-empty, it is used as the endpoint without authentication — intended for emulators (e.g. fake-gcs-server) in tests.
Types ¶
type GCSStorage ¶ added in v0.0.20
type GCSStorage[T any] struct { // contains filtered or unexported fields }
GCSStorage is a Storage backed by a Google Cloud Storage bucket, holding one object per key under the given name prefix.
func NewGCSStorage ¶ added in v0.0.20
func NewGCSStorage[T any](client *gcs.Client, bucket, prefix string) *GCSStorage[T]
NewGCSStorage creates a new GCSStorage[T] storing objects as <prefix>/<key> in bucket.
func (*GCSStorage[T]) Get ¶ added in v0.0.20
func (s *GCSStorage[T]) Get(ctx context.Context, key string) (T, error)
func (*GCSStorage[T]) Remove ¶ added in v0.0.20
func (s *GCSStorage[T]) Remove(ctx context.Context, key string) error
func (*GCSStorage[T]) Set ¶ added in v0.0.20
func (s *GCSStorage[T]) Set(ctx context.Context, key string, item T) error
func (*GCSStorage[T]) SetWithTTL ¶ added in v0.0.20
type Notifier ¶
type Notifier interface {
// Publish sends a notification on the given channel.
Publish(ctx context.Context, channel string) error
// Subscribe returns a Subscription for the given channel.
Subscribe(ctx context.Context, channel string) Subscription
}
Notifier provides pub/sub functionality for key-based notifications.
func NewNotifier ¶
NewNotifier creates a new Notifier backed by Redis.
type Observer ¶ added in v0.0.19
Observer records the outcome and latency of a single storage operation. It is injected from the caller so this package stays free of a metrics dependency.
type Queue ¶
type Queue[T any] interface { Enqueue(ctx context.Context, item T) error Dequeue(ctx context.Context) (T, error) QueueLength(ctx context.Context) (int64, error) }
Queue is a generic FIFO queue backed by a persistent store.
type RedisStorage ¶
type RedisStorage[T any] struct { // contains filtered or unexported fields }
RedisStorage is a storage backed by Redis. All storing keys are prefixed with keyPrefix-.
func NewRedisStorage ¶
func NewRedisStorage[T any](keyPrefix string, client *redis.Client) *RedisStorage[T]
NewRedisStorage creates a new RedisStorage with the Redis client and storing key prefix.
func (*RedisStorage[T]) Clear ¶
func (s *RedisStorage[T]) Clear(ctx context.Context) error
Clear deletes all entries under this storage's keyPrefix.
func (*RedisStorage[T]) Dequeue ¶
func (s *RedisStorage[T]) Dequeue(ctx context.Context) (T, error)
Dequeue dequeues an item from the queue. If no item is available, ErrEmptyQueue error is returned.
func (*RedisStorage[T]) Enqueue ¶
func (s *RedisStorage[T]) Enqueue(ctx context.Context, item T) error
Enqueue enqueues an item to the queue.
func (*RedisStorage[T]) Get ¶
func (s *RedisStorage[T]) Get(ctx context.Context, key string) (T, error)
Get retrieves the value by the key.
func (*RedisStorage[T]) Publish ¶
func (s *RedisStorage[T]) Publish(ctx context.Context, channel string) error
Publish sends a notification on the given channel.
func (*RedisStorage[T]) QueueLength ¶
func (s *RedisStorage[T]) QueueLength(ctx context.Context) (int64, error)
func (*RedisStorage[T]) Remove ¶
func (s *RedisStorage[T]) Remove(ctx context.Context, key string) error
Remove deletes the value stored for the key.
func (*RedisStorage[T]) Set ¶
func (s *RedisStorage[T]) Set(ctx context.Context, key string, item T) error
Set stores the item with the key without expiration.
func (*RedisStorage[T]) SetWithTTL ¶
func (s *RedisStorage[T]) SetWithTTL(ctx context.Context, key string, item T, expiration time.Duration) error
SetWithTTL stores the item with the key and expiration.
func (*RedisStorage[T]) Subscribe ¶
func (s *RedisStorage[T]) Subscribe(ctx context.Context, channel string) Subscription
Subscribe returns a Subscription for the given channel.
type Storage ¶
type Storage[T any] interface { Set(ctx context.Context, key string, item T) error SetWithTTL(ctx context.Context, key string, item T, expiration time.Duration) error Get(ctx context.Context, key string) (T, error) Remove(ctx context.Context, key string) error }
Storage is a generic key-value store.
func WithMetrics ¶ added in v0.0.19
WithMetrics wraps s so each operation reports to obs under the given backend and namespace. It returns s unchanged when obs is nil, so a disabled observer adds no overhead to the hot path.