redis

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: Apache-2.0, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultExpire = time.Hour

DefaultExpire is the expire time we set on Redis when Set/SetExpiration are called with expire=true

Variables

View Source
var ErrDecodingMulticodec = errors.New("error parsing multicodec")

Functions

This section is empty.

Types

type BatchingValueSetStore added in v1.8.0

type BatchingValueSetStore[K, V any] struct {
	// contains filtered or unexported fields
}

func NewBatchingValueSetStore added in v1.8.0

func NewBatchingValueSetStore[K, V any](
	fromRedis func(string) (V, error),
	toRedis func(V) (string, error),
	keyString func(K) string,
	client PipelineClient,
	opts ...Option,
) *BatchingValueSetStore[K, V]

NewBatchingValueSetStore creates a new value-set store (a store whose values are sets) that allows batching.

func (*BatchingValueSetStore[K, V]) Add added in v1.8.0

func (bvs *BatchingValueSetStore[K, V]) Add(ctx context.Context, key K, values ...V) (uint64, error)

func (*BatchingValueSetStore[K, V]) Batch added in v1.8.0

func (bvs *BatchingValueSetStore[K, V]) Batch() types.ValueSetCacheBatcher[K, V]

func (*BatchingValueSetStore[K, V]) Members added in v1.8.0

func (bvs *BatchingValueSetStore[K, V]) Members(ctx context.Context, key K) ([]V, error)

func (*BatchingValueSetStore[K, V]) SetExpirable added in v1.8.0

func (bvs *BatchingValueSetStore[K, V]) SetExpirable(ctx context.Context, key K, expires bool) error

type Client

type Client interface {
	Get(context.Context, string) *redis.StringCmd
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
	SAdd(ctx context.Context, key string, members ...interface{}) *redis.IntCmd
	SMembers(ctx context.Context, key string) *redis.StringSliceCmd
	Expire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd
	Persist(ctx context.Context, key string) *redis.BoolCmd
}

Client is a subset of functions from the golang redis client that we need to implement our cache

type ContentClaimsStore

type ContentClaimsStore = Store[cid.Cid, delegation.Delegation]

ContentClaimsStore is a RedisStore for storing content claims that implements types.ContentClaimsStore

func NewContentClaimsStore

func NewContentClaimsStore(client Client, opts ...Option) *ContentClaimsStore

NewContentClaimsStore returns a new instance of a Content Claims Store using the given redis client

type NoProviderStore added in v1.6.8

type NoProviderStore = Store[multihash.Multihash, multicodec.Code]

NoProviderStore is a RedisStore for storing IPNI data that implements types.ProviderStore

func NewNoProviderStore added in v1.6.8

func NewNoProviderStore(client Client, opts ...Option) *NoProviderStore

NewNoProviderStore returns a new instance of an IPNI store using the given redis client

type Option added in v1.5.0

type Option func(*config)

func ExpirationTime added in v1.5.0

func ExpirationTime(expirationTime time.Duration) Option

type PipelineBatcher added in v1.8.0

type PipelineBatcher[K, V any] struct {
	// contains filtered or unexported fields
}

func NewPipelineBatcher added in v1.8.0

func NewPipelineBatcher[K, V any](
	pipeline Pipeliner,
	toRedis func(V) (string, error),
	keyString func(K) string,
	opts ...Option,
) *PipelineBatcher[K, V]

func (*PipelineBatcher[K, V]) Add added in v1.8.0

func (pb *PipelineBatcher[K, V]) Add(ctx context.Context, key K, values ...V) error

func (*PipelineBatcher[K, V]) Commit added in v1.8.0

func (pb *PipelineBatcher[K, V]) Commit(ctx context.Context) error

func (*PipelineBatcher[K, V]) SetExpirable added in v1.8.0

func (pb *PipelineBatcher[K, V]) SetExpirable(ctx context.Context, key K, expires bool) error

type PipelineClient added in v1.8.0

type PipelineClient interface {
	Client
	Pipelineable
}

PipelineClient is a client that also supports pipelining.

func NewClientAdapter added in v1.8.0

func NewClientAdapter(client *redis.Client) PipelineClient

NewClientAdapter converts a redis.Client into a PipelineClient.

func NewClusterClientAdapter added in v1.8.0

func NewClusterClientAdapter(client *redis.ClusterClient) PipelineClient

NewClientAdapter converts a redis.ClusterClient into a PipelineClient.

type Pipelineable added in v1.8.0

type Pipelineable interface {
	Pipeline() Pipeliner
}

Pipelineable allows pipelines to be created for batching of write commands.

type Pipeliner added in v1.8.0

type Pipeliner interface {
	SAdd(ctx context.Context, key string, members ...any) *redis.IntCmd
	Expire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd
	Persist(ctx context.Context, key string) *redis.BoolCmd
	Exec(ctx context.Context) ([]redis.Cmder, error)
}

Pipeliner is a subset of functions from redis.Pipeliner that we need to implement pipelining for our cache.

type ProviderStore

ProviderStore is a RedisStore for storing IPNI data that implements types.ProviderStore

func NewProviderStore

func NewProviderStore(client PipelineClient, opts ...Option) *ProviderStore

NewProviderStore returns a new instance of an IPNI store using the given redis client

type ShardedDagIndexStore

type ShardedDagIndexStore = Store[types.EncodedContextID, blobindex.ShardedDagIndexView]

ShardedDagIndexStore is a RedisStore for storing sharded dag indexes that implements types.ShardedDagIndexStore

func NewShardedDagIndexStore

func NewShardedDagIndexStore(client Client, opts ...Option) *ShardedDagIndexStore

NewShardedDagIndexStore returns a new instance of a ShardedDagIndex store using the given redis client

type Store

type Store[Key, Value any] struct {
	// contains filtered or unexported fields
}

Store wraps the go redis client to implement our general purpose cache interface, using the providedserialization/deserialization functions

func NewStore

func NewStore[Key, Value any](
	fromRedis func(string) (Value, error),
	toRedis func(Value) (string, error),
	keyString func(Key) string,
	client Client,
	opts ...Option) *Store[Key, Value]

NewStore returns a new instance of a redis store with the provided serialization/deserialization functions

func (*Store[Key, Value]) Add added in v1.2.1

func (rs *Store[Key, Value]) Add(ctx context.Context, key Key, values ...Value) (uint64, error)

Add another value to the set of values for the given key.

func (*Store[Key, Value]) Get

func (rs *Store[Key, Value]) Get(ctx context.Context, key Key) (Value, error)

Get returns deserialized values from redis

func (*Store[Key, Value]) Members added in v1.2.1

func (rs *Store[Key, Value]) Members(ctx context.Context, key Key) ([]Value, error)

Members returns all deserialized set values from redis. If the key does not exist, it returns ErrKeyNotFound.

func (*Store[Key, Value]) Set

func (rs *Store[Key, Value]) Set(ctx context.Context, key Key, value Value, expires bool) error

Set saves a serialized value to redis

func (*Store[Key, Value]) SetExpirable

func (rs *Store[Key, Value]) SetExpirable(ctx context.Context, key Key, expires bool) error

SetExpirable changes the expiration property for a given key

Jump to

Keyboard shortcuts

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