Documentation
¶
Index ¶
- Variables
- func MultiErrors(resp []rueidis.RedisResult) []error
- func PrefixedInt64Key(prefix string, key int64) string
- func UnixDialer(addr string, dialer *net.Dialer, tlsConfig *tls.Config) (net.Conn, error)
- type BuilderKV
- type ErrCacher
- type ErrMarshaler
- type ExpiringHash
- type ExpiringHashApi
- type ExpiringValue
- func (*ExpiringValue) Descriptor() ([]byte, []int)deprecated
- func (x *ExpiringValue) GetExpiresAt() int64
- func (x *ExpiringValue) GetValue() []byte
- func (*ExpiringValue) ProtoMessage()
- func (x *ExpiringValue) ProtoReflect() protoreflect.Message
- func (x *ExpiringValue) Reset()
- func (x *ExpiringValue) String() string
- type ExpiringValueTimestamp
- func (*ExpiringValueTimestamp) Descriptor() ([]byte, []int)deprecated
- func (x *ExpiringValueTimestamp) GetExpiresAt() int64
- func (*ExpiringValueTimestamp) ProtoMessage()
- func (x *ExpiringValueTimestamp) ProtoReflect() protoreflect.Message
- func (x *ExpiringValueTimestamp) Reset()
- func (x *ExpiringValueTimestamp) String() string
- type KeyToRedisKey
- type RedisExpiringHash
- func (h *RedisExpiringHash[K1, K2]) Clear(ctx context.Context) (int, error)
- func (h *RedisExpiringHash[K1, K2]) Forget(key K1, hashKey K2)
- func (h *RedisExpiringHash[K1, K2]) GC() func(context.Context) (int, error)
- func (h *RedisExpiringHash[K1, K2]) Len(ctx context.Context, key K1) (size int64, retErr error)
- func (h *RedisExpiringHash[K1, K2]) Refresh(ctx context.Context, nextRefresh time.Time) error
- func (h *RedisExpiringHash[K1, K2]) Scan(ctx context.Context, key K1, cb ScanCallback) (int, error)
- func (h *RedisExpiringHash[K1, K2]) Set(ctx context.Context, key K1, hashKey K2, value []byte) error
- func (h *RedisExpiringHash[K1, K2]) SetEX(ctx context.Context, key K1, hashKey K2, value []byte, expiresAt time.Time) error
- func (h *RedisExpiringHash[K1, K2]) Unset(ctx context.Context, key K1, hashKey K2) error
- type RedisExpiringHashApi
- type RedisSetBuilder
- type RpcApi
- type ScanCallback
- type SetBuilder
- type TokenLimiter
Constants ¶
This section is empty.
Variables ¶
var File_internal_tool_redistool_redistool_proto protoreflect.FileDescriptor
Functions ¶
func MultiErrors ¶ added in v16.3.0
func MultiErrors(resp []rueidis.RedisResult) []error
func PrefixedInt64Key ¶
Types ¶
type BuilderKV ¶ added in v16.5.0
type BuilderKV[K2 any] struct { HashKey K2 // Value is the value to store in Redis. Value *ExpiringValue }
type ErrCacher ¶
type ErrCacher[K any] struct { Log *zap.Logger ErrRep errz.ErrReporter Client rueidis.Client ErrMarshaler ErrMarshaler KeyToRedisKey KeyToRedisKey[K] }
func (*ErrCacher[K]) CacheError ¶
type ErrMarshaler ¶
type ExpiringHash ¶
type ExpiringHash[K1 any, K2 any] interface { // Set sets the key -> hashKey -> value. The mapping is stored in RAM and in the backing store. // Use Refresh to refresh the value in the backing store. Set(ctx context.Context, key K1, hashKey K2, value []byte) error // SetEX sets the key -> hashKey -> value. The value is stored in the backing store only (unlike Set). // Refresh does not refresh this value in the backing store. Use this method to re-set (i.e. refresh) the value // in the backing store. // Safe for concurrent use. SetEX(ctx context.Context, key K1, hashKey K2, value []byte, expiresAt time.Time) error Unset(ctx context.Context, key K1, hashKey K2) error // Forget only removes the item from the in-memory map. Forget(key K1, hashKey K2) // Scan iterates key-value pairs for key. It removes any expired entries it finds. // Safe for concurrent use. Scan(ctx context.Context, key K1, cb ScanCallback) (int, error) // Len returns number of key-value mappings in the hash identified by key. Len(ctx context.Context, key K1) (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 occurred. // 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 only needs to be used if Len() is used. Otherwise expired entries will be found and deleted by Scan(). GC() func(context.Context) (int, error) // Clear clears all data in this hash and deletes it from the backing store. Clear(context.Context) (int, error) // Refresh refreshes data in the backing store to prevent it from expiring. Refresh(ctx context.Context, nextRefresh time.Time) error }
ExpiringHash represents a two-level hash: key K1 -> hashKey K2 -> 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.
type ExpiringHashApi ¶ added in v16.5.0
type ExpiringHashApi[K1 any, K2 any] interface { SetBuilder() SetBuilder[K1, K2] Unset(ctx context.Context, key K1, hashKey K2) error Scan(ctx context.Context, key K1, cb ScanCallback) (int, error) }
ExpiringHashApi represents a low-level API to work with a two-level hash: key K1 -> hashKey K2 -> value []byte. key identifies the hash; hashKey identifies the key in the hash; value is the value for the hashKey.
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 ¶
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
func (*ExpiringValueTimestamp) Descriptor() ([]byte, []int)
Deprecated: Use ExpiringValueTimestamp.ProtoReflect.Descriptor instead.
func (*ExpiringValueTimestamp) GetExpiresAt ¶
func (x *ExpiringValueTimestamp) GetExpiresAt() int64
func (*ExpiringValueTimestamp) ProtoMessage ¶
func (*ExpiringValueTimestamp) ProtoMessage()
func (*ExpiringValueTimestamp) ProtoReflect ¶
func (x *ExpiringValueTimestamp) ProtoReflect() protoreflect.Message
func (*ExpiringValueTimestamp) Reset ¶
func (x *ExpiringValueTimestamp) Reset()
func (*ExpiringValueTimestamp) String ¶
func (x *ExpiringValueTimestamp) String() string
type KeyToRedisKey ¶
KeyToRedisKey is used to convert typed key (key1 or key2) into a string. HSET key1 key2 value.
type RedisExpiringHash ¶ added in v16.5.0
type RedisExpiringHash[K1 comparable, K2 comparable] struct { // contains filtered or unexported fields }
func NewRedisExpiringHash ¶ added in v16.5.0
func NewRedisExpiringHash[K1 comparable, K2 comparable](client rueidis.Client, key1ToRedisKey KeyToRedisKey[K1], key2ToRedisKey KeyToRedisKey[K2], ttl time.Duration) *RedisExpiringHash[K1, K2]
func (*RedisExpiringHash[K1, K2]) Clear ¶ added in v16.5.0
func (h *RedisExpiringHash[K1, K2]) Clear(ctx context.Context) (int, error)
func (*RedisExpiringHash[K1, K2]) Forget ¶ added in v16.5.0
func (h *RedisExpiringHash[K1, K2]) Forget(key K1, hashKey K2)
func (*RedisExpiringHash[K1, K2]) GC ¶ added in v16.5.0
func (h *RedisExpiringHash[K1, K2]) GC() func(context.Context) (int, error)
func (*RedisExpiringHash[K1, K2]) Len ¶ added in v16.5.0
func (h *RedisExpiringHash[K1, K2]) Len(ctx context.Context, key K1) (size int64, retErr error)
func (*RedisExpiringHash[K1, K2]) Scan ¶ added in v16.5.0
func (h *RedisExpiringHash[K1, K2]) Scan(ctx context.Context, key K1, cb ScanCallback) (int, error)
func (*RedisExpiringHash[K1, K2]) Set ¶ added in v16.5.0
func (h *RedisExpiringHash[K1, K2]) Set(ctx context.Context, key K1, hashKey K2, value []byte) error
type RedisExpiringHashApi ¶ added in v16.5.0
type RedisExpiringHashApi[K1 any, K2 any] struct { Client rueidis.Client Key1ToRedisKey KeyToRedisKey[K1] Key2ToRedisKey KeyToRedisKey[K2] }
func (*RedisExpiringHashApi[K1, K2]) Scan ¶ added in v16.5.0
func (h *RedisExpiringHashApi[K1, K2]) Scan(ctx context.Context, key K1, cb ScanCallback) (int, error)
func (*RedisExpiringHashApi[K1, K2]) SetBuilder ¶ added in v16.5.0
func (h *RedisExpiringHashApi[K1, K2]) SetBuilder() SetBuilder[K1, K2]
type RedisSetBuilder ¶ added in v16.5.0
type ScanCallback ¶
type SetBuilder ¶ added in v16.5.0
type SetBuilder[K1 any, K2 any] interface { // Set enqueues a HSET command. Does nothing if no kvs provided. Set(key K1, ttl time.Duration, kvs ...BuilderKV[K2]) // Do executes enqueued commands. Does nothing if no commands have been enqueued. // Builder must not be reused after this method has been called. Do(context.Context) 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 rueidis.Client, keyPrefix string, limitPerMinute uint64, getApi func(context.Context) RpcApi) *TokenLimiter
NewTokenLimiter returns a new TokenLimiter