Documentation
¶
Index ¶
- Variables
- func NewClient(host string) *redis.Client
- func NewFirestoreClient(ctx context.Context, projectID, databaseID, credentialsFile, url string) (*firestore.Client, error)
- type FirestoreStorage
- func (f *FirestoreStorage[T]) Get(ctx context.Context, key string) (T, error)
- func (f *FirestoreStorage[T]) Remove(ctx context.Context, key string) error
- func (f *FirestoreStorage[T]) Set(ctx context.Context, key string, item T) error
- func (f *FirestoreStorage[T]) SetWithTTL(ctx context.Context, key string, item T, expiration time.Duration) error
- type Notifier
- 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]) GetWithTTL(ctx context.Context, key string) (T, time.Duration, error)
- func (s *RedisStorage[T]) Ping(ctx context.Context) 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")
var ErrEmptyQueue = errors.New("empty queue")
var ErrNotFound = errors.New("not found")
ErrNotFound is returned by Storage implementations when a key does not exist or has expired.
Functions ¶
func NewFirestoreClient ¶
func NewFirestoreClient(ctx context.Context, projectID, databaseID, credentialsFile, url string) (*firestore.Client, error)
NewFirestoreClient creates a new Firestore client for the given project.
If credentialsFile is empty, Application Default Credentials are used. If databaseID is empty, the default database is used.
Types ¶
type FirestoreStorage ¶
type FirestoreStorage[T any] struct { // contains filtered or unexported fields }
FirestoreStorage is a Storage backed by Firestore.
func NewFirestoreStorage ¶
func NewFirestoreStorage[T any](client *firestore.Client, collection string) *FirestoreStorage[T]
NewFirestoreStorage creates a new FirestoreStorage[T] backed by the given Firestore collection.
func (*FirestoreStorage[T]) Get ¶
func (f *FirestoreStorage[T]) Get(ctx context.Context, key string) (T, error)
func (*FirestoreStorage[T]) Remove ¶
func (f *FirestoreStorage[T]) Remove(ctx context.Context, key string) error
func (*FirestoreStorage[T]) Set ¶
func (f *FirestoreStorage[T]) Set(ctx context.Context, key string, item T) error
func (*FirestoreStorage[T]) SetWithTTL ¶
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 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 storage's entries from database.
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]) GetWithTTL ¶
GetWithTTL retrieves the value and its remaining expiration duration 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.