cache

package
v0.53.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2023 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

Variables

This section is empty.

Functions

func Key

func Key(args ...string) string

Key make a key as expected

func NewWriteCloser

func NewWriteCloser(store Store, key string, ttl int) io.WriteCloser

NewWriteCloser returns a write closer

Types

type HealthStore

type HealthStore interface {
	Ping() error
	DBSize() (int64, error)
	Size(key string) (int64, error)
	Keys(pattern string) ([]string, error)
}

type LockStore

type LockStore interface {
	Lock(key string, expiration time.Duration, retryWaitDurationMillisecond int, retryCount int) (bool, error)
	Unlock(key string) error
}

type PubSub

type PubSub interface {
	Unsubscribe(channels ...string) error
	GetMessage(c context.Context) (string, error)
}

PubSub represents a subscriber

type PubSubStore

type PubSubStore interface {
	Publish(ctx context.Context, queueName string, value interface{}) error
	Subscribe(queueName string) (PubSub, error)
}

type QueueStore

type QueueStore interface {
	Enqueue(queueName string, value interface{}) error
	DequeueWithContext(c context.Context, queueName string, waitDuration time.Duration, value interface{}) error
	DequeueJSONRawMessagesWithContext(c context.Context, queueName string, waitDuration time.Duration, maxElements int) ([]json.RawMessage, error)
	QueueLen(queueName string) (int, error)
	RemoveFromQueue(queueName string, memberKey string) error
}

type RedisPubSub

type RedisPubSub struct {
	*redis.PubSub
}

func (*RedisPubSub) GetMessage

func (p *RedisPubSub) GetMessage(ctx context.Context) (string, error)

type RedisStore

type RedisStore struct {
	Client *redis.Client
	// contains filtered or unexported fields
}

RedisStore a redis client and a default ttl

func NewRedisStore

func NewRedisStore(host, password string, dbindex, ttl int) (*RedisStore, error)

NewRedisStore initiate a new redisStore

func (*RedisStore) DBSize

func (s *RedisStore) DBSize() (int64, error)

DBSize: Return the number of keys in the currently-selected database

func (*RedisStore) Delete

func (s *RedisStore) Delete(key string) error

Delete a key in redis

func (*RedisStore) DeleteAll

func (s *RedisStore) DeleteAll(pattern string) error

DeleteAll delete all mathing keys in redis

func (*RedisStore) DequeueJSONRawMessagesWithContext

func (s *RedisStore) DequeueJSONRawMessagesWithContext(ctx context.Context, queueName string, waitDuration time.Duration, maxElements int) ([]json.RawMessage, error)

DequeueListWithContext gets from queue This is blocking while there is nothing in the queue, it can be cancelled with a context.Context

func (*RedisStore) DequeueWithContext

func (s *RedisStore) DequeueWithContext(c context.Context, queueName string, waitDuration time.Duration, value interface{}) error

DequeueWithContext gets from queue This is blocking while there is nothing in the queue, it can be cancelled with a context.Context

func (*RedisStore) Enqueue

func (s *RedisStore) Enqueue(queueName string, value interface{}) error

Enqueue pushes to queue

func (*RedisStore) Eval

func (s *RedisStore) Eval(expr string, args ...string) (string, error)

func (*RedisStore) Exist

func (s *RedisStore) Exist(key string) (bool, error)

Exist test is key exists

func (*RedisStore) Get

func (s *RedisStore) Get(key string, value interface{}) (bool, error)

Get a key from redis

func (*RedisStore) Keys

func (s *RedisStore) Keys(pattern string) ([]string, error)

func (*RedisStore) Lock

func (s *RedisStore) Lock(key string, expiration time.Duration, retrywdMillisecond int, retryCount int) (bool, error)

func (*RedisStore) Ping

func (s *RedisStore) Ping() error

func (*RedisStore) Publish

func (s *RedisStore) Publish(ctx context.Context, channel string, value interface{}) error

Publish a msg in a channel

func (*RedisStore) QueueLen

func (s *RedisStore) QueueLen(queueName string) (int, error)

QueueLen returns the length of a queue

func (*RedisStore) RemoveFromQueue

func (s *RedisStore) RemoveFromQueue(rootKey string, memberKey string) error

RemoveFromQueue removes a member from a list

func (*RedisStore) ScoredSetAdd

func (s *RedisStore) ScoredSetAdd(_ context.Context, key string, value interface{}, score float64) error

func (*RedisStore) ScoredSetAppend

func (s *RedisStore) ScoredSetAppend(ctx context.Context, key string, value interface{}) error

func (*RedisStore) ScoredSetGetScore

func (s *RedisStore) ScoredSetGetScore(key string, member interface{}) (float64, error)

func (*RedisStore) ScoredSetRange

func (s *RedisStore) ScoredSetRange(_ context.Context, key string, from, to int64, dest interface{}) error

func (*RedisStore) ScoredSetRem

func (s *RedisStore) ScoredSetRem(_ context.Context, key string, members ...string) error

func (*RedisStore) ScoredSetRevRange

func (s *RedisStore) ScoredSetRevRange(_ context.Context, key string, offset int64, limit int64, dest interface{}) error

func (*RedisStore) ScoredSetScan

func (s *RedisStore) ScoredSetScan(_ context.Context, key string, from, to float64, dest interface{}) error

func (*RedisStore) ScoredSetScanMaxScore

func (s *RedisStore) ScoredSetScanMaxScore(_ context.Context, key string) (*SetValueWithScore, error)

func (*RedisStore) ScoredSetScanWithScores

func (s *RedisStore) ScoredSetScanWithScores(_ context.Context, key string, from, to float64) ([]SetValueWithScore, error)

func (*RedisStore) Set

func (s *RedisStore) Set(key string, value interface{}) error

Set a value in redis

func (*RedisStore) SetAdd

func (s *RedisStore) SetAdd(rootKey string, memberKey string, member interface{}) error

SetAdd add a member (identified by a key) in the cached set

func (*RedisStore) SetCard

func (s *RedisStore) SetCard(key string) (int, error)

SetCard returns the cardinality of a ZSet

func (*RedisStore) SetRemove

func (s *RedisStore) SetRemove(rootKey string, memberKey string, _ interface{}) error

SetRemove removes a member from a set

func (*RedisStore) SetScan

func (s *RedisStore) SetScan(ctx context.Context, key string, members ...interface{}) error

SetScan scans a ZSet

func (*RedisStore) SetSearch

func (s *RedisStore) SetSearch(key, pattern string) ([]string, error)

func (*RedisStore) SetWithDuration

func (s *RedisStore) SetWithDuration(key string, value interface{}, duration time.Duration) error

SetWithDuration a value in local store (0 for eternity)

func (*RedisStore) SetWithTTL

func (s *RedisStore) SetWithTTL(key string, value interface{}, ttl int) error

SetWithTTL a value in local store (0 for eternity)

func (*RedisStore) Size

func (s *RedisStore) Size(key string) (int64, error)

func (*RedisStore) Subscribe

func (s *RedisStore) Subscribe(channel string) (PubSub, error)

Subscribe to a channel

func (*RedisStore) Unlock

func (s *RedisStore) Unlock(key string) error

Unlock deletes a key from cache

func (*RedisStore) UpdateTTL

func (s *RedisStore) UpdateTTL(key string, ttl int) error

UpdateTTL update the ttl linked to the key

type ScoredSetStore

type ScoredSetStore interface {
	Delete(key string) error
	ScoredSetAdd(ctx context.Context, key string, value interface{}, score float64) error
	ScoredSetAppend(ctx context.Context, key string, value interface{}) error
	ScoredSetScan(ctx context.Context, key string, from, to float64, dest interface{}) error
	ScoredSetScanWithScores(ctx context.Context, key string, from, to float64) ([]SetValueWithScore, error)
	ScoredSetScanMaxScore(ctx context.Context, key string) (*SetValueWithScore, error)
	ScoredSetRange(ctx context.Context, key string, from, to int64, dest interface{}) error
	ScoredSetRevRange(_ context.Context, key string, offset int64, limit int64, dest interface{}) error
	ScoredSetRem(ctx context.Context, key string, members ...string) error
	ScoredSetGetScore(key string, member interface{}) (float64, error)
	SetCard(key string) (int, error)
	Eval(expr string, args ...string) (string, error)
	HealthStore
}

type SetStore

type SetStore interface {
	SetAdd(rootKey string, memberKey string, member interface{}) error
	SetRemove(rootKey string, memberKey string, member interface{}) error
	SetCard(key string) (int, error)
	SetScan(ctx context.Context, key string, members ...interface{}) error
	SetSearch(key, pattern string) ([]string, error)
}

type SetValueWithScore

type SetValueWithScore struct {
	Score float64
	Value json.RawMessage
}

type Store

type Store interface {
	Get(key string, value interface{}) (bool, error)
	Set(key string, value interface{}) error
	SetWithTTL(key string, value interface{}, ttl int) error
	SetWithDuration(key string, value interface{}, duration time.Duration) error
	UpdateTTL(key string, ttl int) error
	Delete(key string) error
	DeleteAll(key string) error
	Exist(key string) (bool, error)
	Eval(expr string, args ...string) (string, error)
	HealthStore
	LockStore
	QueueStore
	PubSubStore
	ScoredSetStore
	SetStore
}

Store is an interface

func New

func New(redisHost, redisPassword string, dbindex, TTL int) (Store, error)

New init a cache

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL