redistool

package
v15.6.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_internal_tool_redistool_redistool_proto protoreflect.FileDescriptor

Functions

func PrefixedInt64Key

func PrefixedInt64Key(prefix string, key int64) string

Types

type ErrCacher added in v15.5.0

type ErrCacher struct {
	Log           *zap.Logger
	Client        redis.UniversalClient
	ErrMarshaler  ErrMarshaler
	KeyToRedisKey KeyToRedisKey
}

func (*ErrCacher) CacheError added in v15.5.0

func (c *ErrCacher) CacheError(ctx context.Context, key interface{}, err error, errTtl time.Duration)

func (*ErrCacher) GetError added in v15.5.0

func (c *ErrCacher) GetError(ctx context.Context, key interface{}) error

type ErrMarshaler added in v15.5.0

type ErrMarshaler interface {
	// Marshal turns error into []byte.
	Marshal(error) ([]byte, error)
	// Unmarshal turns []byte into error.
	Unmarshal([]byte) (error, error)
}

type ExpiringHash

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

func NewExpiringHash

func NewExpiringHash(client redis.UniversalClient, keyToRedisKey KeyToRedisKey, ttl time.Duration) *ExpiringHash

func (*ExpiringHash) Forget added in v15.3.0

func (h *ExpiringHash) Forget(key interface{}, hashKey int64)

func (*ExpiringHash) GC

func (h *ExpiringHash) GC() func(context.Context) (int, error)

func (*ExpiringHash) Len added in v15.2.0

func (h *ExpiringHash) Len(ctx context.Context, key interface{}) (size int64, retErr error)

func (*ExpiringHash) Refresh

func (h *ExpiringHash) Refresh(nextRefresh time.Time) IOFunc

func (*ExpiringHash) Scan

func (h *ExpiringHash) Scan(ctx context.Context, key interface{}, cb ScanCallback) (keysDeleted int, retErr error)

func (*ExpiringHash) Set

func (h *ExpiringHash) Set(key interface{}, hashKey int64, value []byte) IOFunc

func (*ExpiringHash) Unset

func (h *ExpiringHash) Unset(key interface{}, hashKey int64) IOFunc

type ExpiringHashInterface

type ExpiringHashInterface interface {
	Set(key interface{}, hashKey int64, value []byte) IOFunc
	Unset(key interface{}, hashKey int64) IOFunc
	// Forget only removes the item from the in-memory map.
	Forget(key interface{}, hashKey int64)
	Scan(ctx context.Context, key interface{}, cb ScanCallback) (int, error)
	Len(ctx context.Context, key interface{}) (int64, error)
	// GC returns a function that iterates all relevant stored data and deletes expired entries.
	// The returned function can be called concurrently as it does not interfere with the hash's operation.
	// The function returns number of deleted Redis (hash) keys, including when an error occurs.
	// It only inspects/GCs hashes where it has entries. Other concurrent clients GC same and/or other corresponding hashes.
	// Hashes that don't have a corresponding client (e.g. because it crashed) will expire because of TTL on the hash key.
	GC() func(context.Context) (int, error)
	Refresh(nextRefresh time.Time) IOFunc
}

ExpiringHashInterface represents a two-level hash: key any -> hashKey int64 -> value []byte. key identifies the hash; hashKey identifies the key in the hash; value is the value for the hashKey. It is not safe for concurrent use directly, but it allows to perform I/O with backing store concurrently by returning functions for doing that.

type ExpiringValue

type ExpiringValue struct {
	ExpiresAt int64  `protobuf:"varint,1,opt,name=expires_at,json=expiresAt,proto3" json:"expires_at,omitempty"`
	Value     []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*ExpiringValue) Descriptor deprecated

func (*ExpiringValue) Descriptor() ([]byte, []int)

Deprecated: Use ExpiringValue.ProtoReflect.Descriptor instead.

func (*ExpiringValue) GetExpiresAt

func (x *ExpiringValue) GetExpiresAt() int64

func (*ExpiringValue) GetValue

func (x *ExpiringValue) GetValue() []byte

func (*ExpiringValue) ProtoMessage

func (*ExpiringValue) ProtoMessage()

func (*ExpiringValue) ProtoReflect

func (x *ExpiringValue) ProtoReflect() protoreflect.Message

func (*ExpiringValue) Reset

func (x *ExpiringValue) Reset()

func (*ExpiringValue) String

func (x *ExpiringValue) String() string

type ExpiringValueTimestamp added in v15.4.0

type ExpiringValueTimestamp struct {
	ExpiresAt int64 `protobuf:"varint,1,opt,name=expires_at,json=expiresAt,proto3" json:"expires_at,omitempty"`
	// contains filtered or unexported fields
}

func (*ExpiringValueTimestamp) Descriptor deprecated added in v15.4.0

func (*ExpiringValueTimestamp) Descriptor() ([]byte, []int)

Deprecated: Use ExpiringValueTimestamp.ProtoReflect.Descriptor instead.

func (*ExpiringValueTimestamp) GetExpiresAt added in v15.4.0

func (x *ExpiringValueTimestamp) GetExpiresAt() int64

func (*ExpiringValueTimestamp) ProtoMessage added in v15.4.0

func (*ExpiringValueTimestamp) ProtoMessage()

func (*ExpiringValueTimestamp) ProtoReflect added in v15.4.0

func (x *ExpiringValueTimestamp) ProtoReflect() protoreflect.Message

func (*ExpiringValueTimestamp) Reset added in v15.4.0

func (x *ExpiringValueTimestamp) Reset()

func (*ExpiringValueTimestamp) String added in v15.4.0

func (x *ExpiringValueTimestamp) String() string

type IOFunc added in v15.4.0

type IOFunc func(ctx context.Context) error

IOFunc is a function that should be called to perform the I/O of the requested operation. It is safe to call concurrently as it does not interfere with the hash's operation.

type KeyToRedisKey

type KeyToRedisKey func(key interface{}) string

KeyToRedisKey is used to convert key1 in HSET key1 key2 value.

type RpcApi

type RpcApi interface {
	Log() *zap.Logger
	HandleProcessingError(msg string, err error)
	RequestKey() []byte
}

type ScanCallback

type ScanCallback func(value []byte, err error) (bool, error)

type TokenLimiter

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

TokenLimiter is a redis-based rate limiter implementing the algorithm in https://redislabs.com/redis-best-practices/basic-rate-limiting/

func NewTokenLimiter

func NewTokenLimiter(redisClient redis.UniversalClient, keyPrefix string,
	limitPerMinute uint64, getApi func(context.Context) RpcApi) *TokenLimiter

NewTokenLimiter returns a new TokenLimiter

func (*TokenLimiter) Allow

func (l *TokenLimiter) Allow(ctx context.Context) bool

Allow consumes one limitable event from the token in the context

Jump to

Keyboard shortcuts

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