redis

package
v0.0.0-...-476b611 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotificationLockCache             = CacheConfig{/* contains filtered or unexported fields */}
	EmailRateLimitersCache            = CacheConfig{/* contains filtered or unexported fields */}
	PushNotificationRateLimitersCache = CacheConfig{/* contains filtered or unexported fields */}
	OneTimeLoginCache                 = CacheConfig{/* contains filtered or unexported fields */}
	AuthTokenForceRefreshCache        = CacheConfig{/* contains filtered or unexported fields */}
	CommunitiesCache                  = CacheConfig{/* contains filtered or unexported fields */}
	IndexerServerThrottleCache        = CacheConfig{/* contains filtered or unexported fields */}
	RefreshNFTsThrottleCache          = CacheConfig{/* contains filtered or unexported fields */}
	TokenProcessingThrottleCache      = CacheConfig{/* contains filtered or unexported fields */}
	TokenProcessingMetadataCache      = CacheConfig{/* contains filtered or unexported fields */}
	EmailThrottleCache                = CacheConfig{/* contains filtered or unexported fields */}
	GraphQLAPQCache                   = CacheConfig{/* contains filtered or unexported fields */}
	FeedCache                         = CacheConfig{/* contains filtered or unexported fields */}
	SocialCache                       = CacheConfig{/* contains filtered or unexported fields */}
	SearchCache                       = CacheConfig{/* contains filtered or unexported fields */}
	UserPrefCache                     = CacheConfig{/* contains filtered or unexported fields */}
	TokenManageCache                  = CacheConfig{/* contains filtered or unexported fields */}
	WalletsBloomFilterCache           = CacheConfig{/* contains filtered or unexported fields */}
	MintCache                         = CacheConfig{/* contains filtered or unexported fields */}
)

Functions

func NewLockClient

func NewLockClient(cache *Cache) *redislock.Client

Types

type Cache

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

Cache represents an abstraction over a redis client

func NewCache

func NewCache(config CacheConfig) *Cache

NewCache creates a new redis cache

func (*Cache) Client

func (c *Cache) Client() *redis.Client

func (*Cache) Close

func (c *Cache) Close() error

Close closes the underlying redis client

func (*Cache) Delete

func (c *Cache) Delete(pCtx context.Context, key string) error

func (*Cache) Get

func (c *Cache) Get(pCtx context.Context, key string) ([]byte, error)

Get gets a value from the redis cache

func (*Cache) GetTime

func (c *Cache) GetTime(ctx context.Context, key string) (time.Time, error)

func (*Cache) MSetWithTTL

func (c *Cache) MSetWithTTL(ctx context.Context, keyValues map[string]any, expiration time.Duration) error

MSetWithTTL sets multiple keys in the redis cache via pipelining.

func (*Cache) Prefix

func (c *Cache) Prefix() string

func (*Cache) Scripter

func (c *Cache) Scripter() redis.Scripter

Scripter returns an implementation of the redis.Scripter interface using this Cache

func (*Cache) Set

func (c *Cache) Set(pCtx context.Context, key string, value []byte, expiration time.Duration) error

Set sets a value in the redis cache

func (*Cache) SetNX

func (c *Cache) SetNX(pCtx context.Context, key string, value []byte, expiration time.Duration) (bool, error)

SetNX sets a value in the redis cache if it doesn't already exist. Returns true if the key did not already exist and was set, false if the key did exist and therefore was not set.

func (*Cache) SetTime

func (c *Cache) SetTime(ctx context.Context, key string, value time.Time, expiration time.Duration, onlyIfLater bool) error

SetTime sets a time in the redis cache. If onlyIfLater is true, the value will only be set if the key doesn't exist, or if the existing key's value is an earlier time than the one being set.

type CacheConfig

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

type ErrKeyNotFound

type ErrKeyNotFound struct {
	Key string
}

func (ErrKeyNotFound) Error

func (e ErrKeyNotFound) Error() string

type LazyCache

type LazyCache struct {
	Cache    *Cache
	CalcFunc func(context.Context) ([]byte, error)
	Key      string
	TTL      time.Duration
}

LazyCache implements a lazy loading cache that stores data only when it is requested

func (LazyCache) Load

func (l LazyCache) Load(ctx context.Context) ([]byte, error)

Load queries the cache for the given key, and if it is current returns the data. It's possible for Load to return stale data, however the staleness of data can be limited by configuring a shorter TTL. The tradeoff being that a shorter TTL results in more cache misses which can have a noticeable delay in getting data.

Jump to

Keyboard shortcuts

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