cache

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchGetCache

func BatchGetCache[T any, K comparable](
	ctx context.Context,
	rcClient *rockscache.Client,
	expire time.Duration,
	keys []K,
	keyFn func(key K) string,
	fns func(ctx context.Context, key K) (T, error),
) ([]T, error)

func GetCache

func GetCache[T any](ctx context.Context, rcClient *rockscache.Client, key string, expire time.Duration, fn func(ctx context.Context) (T, error)) (T, error)

func GetRocksCacheOptions

func GetRocksCacheOptions() rockscache.Options

GetRocksCacheOptions returns the default configuration options for RocksCache.

func ProcessKeysBySlot

func ProcessKeysBySlot(
	ctx context.Context,
	redisClient redis.UniversalClient,
	keys []string,
	processFunc func(ctx context.Context, slot int64, keys []string) error,
	opts ...Option,
) error

ProcessKeysBySlot groups keys by their Redis cluster hash slots and processes them using the provided function.

Types

type BatchDeleter

type BatchDeleter interface {
	//ChainExecDel method is used for chain calls and must call Clone to prevent memory pollution.
	ChainExecDel(ctx context.Context) error
	//ExecDelWithKeys method directly takes keys for deletion.
	ExecDelWithKeys(ctx context.Context, keys []string) error
	//Clone method creates a copy of the BatchDeleter to avoid modifying the original object.
	Clone() BatchDeleter
	//AddKeys method adds keys to be deleted.
	AddKeys(keys ...string)
}

type BatchDeleterRedis

type BatchDeleterRedis struct {
	// contains filtered or unexported fields
}

BatchDeleterRedis is a concrete implementation of the BatchDeleter interface based on Redis and RocksCache.

func NewBatchDeleterRedis

func NewBatchDeleterRedis(redisClient redis.UniversalClient, options rockscache.Options) *BatchDeleterRedis

NewBatchDeleterRedis creates a new BatchDeleterRedis instance.

func (*BatchDeleterRedis) AddKeys

func (c *BatchDeleterRedis) AddKeys(keys ...string)

AddKeys adds keys to be deleted.

func (*BatchDeleterRedis) ChainExecDel

func (c *BatchDeleterRedis) ChainExecDel(ctx context.Context) error

ChainExecDel is used for chain calls for batch deletion. It must call Clone to prevent memory pollution.

func (*BatchDeleterRedis) Clone

func (c *BatchDeleterRedis) Clone() BatchDeleter

Clone creates a copy of BatchDeleterRedis for chain calls to prevent memory pollution.

func (*BatchDeleterRedis) ExecDelWithKeys

func (c *BatchDeleterRedis) ExecDelWithKeys(ctx context.Context, keys []string) error

ExecDelWithKeys directly takes keys for batch deletion and publishes deletion information.

type Option

type Option func(c *RedisShardManagerConfig)

Option is a function type for configuring Config

func WithBatchSize

func WithBatchSize(size int) Option

WithBatchSize sets the number of keys to process per batch

func WithConcurrentLimit

func WithConcurrentLimit(limit int) Option

WithConcurrentLimit sets the concurrency limit

func WithContinueOnError

func WithContinueOnError(continueOnError bool) Option

WithContinueOnError sets whether to continue processing on error

type RedisShardManagerConfig

type RedisShardManagerConfig struct {
	// contains filtered or unexported fields
}

type ShardManager

type ShardManager struct {
	// contains filtered or unexported fields
}

ShardManager is a class for sharding and processing keys

func NewRedisShardManager

func NewRedisShardManager(redisClient redis.UniversalClient, opts ...Option) *ShardManager

NewRedisShardManager creates a new RedisShardManager instance

func (*ShardManager) ProcessKeysBySlot

func (rsm *ShardManager) ProcessKeysBySlot(
	ctx context.Context,
	keys []string,
	processFunc func(ctx context.Context, slot int64, keys []string) error,
) error

ProcessKeysBySlot groups keys by their Redis cluster hash slots and processes them using the provided function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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