memory

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyExists = fmt.Errorf("item already exists")
	ErrCacheMiss = fmt.Errorf("item not found")
)

Functions

This section is empty.

Types

type Cache

type Cache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Cache

Return a new cache with a given default expiration duration and cleanup interval. If the expiration duration is less than 1, the items in the cache never expire (by default), and must be deleted manually. If the cleanup interval is less than one, expired items are not deleted from the cache before their next lookup or before calling DeleteExpired.

func (*Cache) BRPopLPush added in v0.3.1

func (c *Cache) BRPopLPush(source string, destination string, timeout time.Duration) string

func (*Cache) Decrement

func (c *Cache) Decrement(k string, n int64) (int64, error)

Decrement an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or int64 by n. Returns an error if the item's value is not an integer, if it was not found, or if it is not possible to decrement it by n. Stops at 0 on underflow.

func (*Cache) Delete

func (c *Cache) Delete(k ...string) int64

Delete an item from the cache. Does nothing if the key is not in the cache.

func (*Cache) DeleteExpired

func (c *Cache) DeleteExpired()

Delete all expired items from the cache.

func (*Cache) Exists added in v0.2.15

func (c *Cache) Exists(s ...string) int64

func (*Cache) Flush

func (c *Cache) Flush()

Delete all items from the cache.

func (*Cache) Get

func (c *Cache) Get(k string) interface{}

Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.

func (*Cache) GetLock

func (c *Cache) GetLock(s string, duration time.Duration, duration2 time.Duration) (string, error)

func (*Cache) GetString

func (c *Cache) GetString(k string) (string, error)

Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.

func (*Cache) HashAll added in v0.2.19

func (c *Cache) HashAll(key string) map[string]string

func (*Cache) HashDel added in v0.2.19

func (c *Cache) HashDel(key string, values ...string) int64

func (*Cache) HashExist added in v0.2.19

func (c *Cache) HashExist(key, values string) bool

func (*Cache) HashGet added in v0.2.19

func (c *Cache) HashGet(key, value string) string

func (*Cache) HashGets added in v0.2.19

func (c *Cache) HashGets(key string, value ...string) []interface{}

func (*Cache) HashKeys added in v0.2.19

func (c *Cache) HashKeys(key string) []string

func (*Cache) HashLen added in v0.2.19

func (c *Cache) HashLen(key string) int64

func (*Cache) HashSet added in v0.2.19

func (c *Cache) HashSet(key string, values ...interface{}) int64

func (*Cache) Increment

func (c *Cache) Increment(k string, n int64) (int64, error)

Increment an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or int64 by n. Returns an error if the item's value is not an integer, if it was not found, or if it is not possible to increment it by n. Wraps around on overlow.

func (*Cache) IncrementFloat

func (c *Cache) IncrementFloat(k string, n float64) (float64, error)

Increment an item of type float32 or float64 by n. Returns an error if the item's value is not floating point, if it was not found, or if it is not possible to increment it by n. Pass a negative number to decrement the value.

func (*Cache) IsExist

func (c *Cache) IsExist(k string) bool

func (*Cache) LPush

func (c *Cache) LPush(s string, values ...interface{}) int64

func (*Cache) LRange added in v0.3.1

func (c *Cache) LRange(key string, start int64, stop int64) []string

func (*Cache) LRem added in v0.3.1

func (c *Cache) LRem(key string, count int64, value interface{}) int64

func (*Cache) Load

func (c *Cache) Load(r io.Reader) error

Add (Gob-serialized) cache items from an io.Reader, excluding any items with keys that already exist in the current cache.

func (*Cache) LoadFile

func (c *Cache) LoadFile(fname string) error

Load and add cache items from the given filename, excluding any items with keys that already exist in the current cache.

func (*Cache) Pipeline added in v0.2.15

func (c *Cache) Pipeline() redis.Pipeliner

func (*Cache) RPop

func (c *Cache) RPop(s string) string

func (*Cache) RPopLPush added in v0.3.1

func (c *Cache) RPopLPush(source string, destination string) string

func (*Cache) ReleaseLock

func (c *Cache) ReleaseLock(s string, s2 string) bool

func (*Cache) Save

func (c *Cache) Save(w io.Writer) (err error)

Write the cache's items (using Gob) to an io.Writer.

func (*Cache) SaveFile

func (c *Cache) SaveFile(fname string) error

Save the cache's items to the given filename, creating the file if it doesn't exist, and overwriting it if it does.

func (*Cache) Scan added in v0.3.1

func (c *Cache) Scan(cursor uint64, match string, count int64) ([]string, uint64)

func (*Cache) Set

func (c *Cache) Set(key string, value interface{}, timeout time.Duration) error

Add an item to the cache, replacing any existing item. If the duration is 0, the cache's default expiration time is used. If it is -1, the item never expires.

func (*Cache) SetEX added in v0.3.1

func (c *Cache) SetEX(key string, val interface{}, timeout time.Duration) error

func (*Cache) SetNX added in v0.3.1

func (c *Cache) SetNX(key string, value interface{}, expiration time.Duration) bool

func (*Cache) WithContext

func (c *Cache) WithContext(ctx context.Context) icache.ICache

func (*Cache) WithDB

func (c *Cache) WithDB(db int) icache.ICache

func (*Cache) XAck added in v0.2.15

func (c *Cache) XAck(key string, group string, ids ...string) int64

func (*Cache) XAdd

func (c *Cache) XAdd(key, msgId string, trim bool, maxLength int64, value interface{}) string

func (*Cache) XAddKey added in v0.2.18

func (c *Cache) XAddKey(key, msgId string, trim bool, maxLength int64, vKey string, value interface{}) string

func (*Cache) XClaim added in v0.2.15

func (c *Cache) XClaim(key string, group string, consumer string, id string, msIdle int64) []redis.XMessage

func (*Cache) XDel

func (c *Cache) XDel(key string, id ...string) int64

func (*Cache) XGroupCreateMkStream added in v0.2.15

func (c *Cache) XGroupCreateMkStream(key string, group string, start string) string

func (*Cache) XGroupDelConsumer added in v0.2.15

func (c *Cache) XGroupDelConsumer(key string, group string, consumer string) int64

func (*Cache) XGroupDestroy added in v0.2.15

func (c *Cache) XGroupDestroy(key string, group string) int64

func (*Cache) XGroupSetID added in v0.2.15

func (c *Cache) XGroupSetID(key string, group string, start string) string

func (*Cache) XInfoConsumers added in v0.2.15

func (c *Cache) XInfoConsumers(key string, group string) []redis.XInfoConsumer

func (*Cache) XInfoGroups added in v0.2.15

func (c *Cache) XInfoGroups(s string) []redis.XInfoGroup

func (*Cache) XInfoStream added in v0.2.15

func (c *Cache) XInfoStream(key string) *redis.XInfoStream

func (*Cache) XLen added in v0.2.15

func (c *Cache) XLen(s string) int64

func (*Cache) XPending added in v0.2.15

func (c *Cache) XPending(key string, group string) *redis.XPending

func (*Cache) XPendingExt added in v0.2.15

func (c *Cache) XPendingExt(key string, group string, startId string, endId string, count int64, consumer ...string) []redis.XPendingExt

func (*Cache) XRange added in v0.2.15

func (c *Cache) XRange(key string, start string, stop string) []redis.XMessage

func (*Cache) XRangeN added in v0.2.15

func (c *Cache) XRangeN(key string, start string, stop string, count int64) []redis.XMessage

func (*Cache) XRead

func (c *Cache) XRead(key string, startId string, count int64, block int64) []redis.XMessage

func (*Cache) XReadGroup added in v0.2.15

func (c *Cache) XReadGroup(key string, group string, consumer string, count int64, block int64, id ...string) []redis.XMessage

func (*Cache) XTrimMaxLen added in v0.2.15

func (c *Cache) XTrimMaxLen(key string, maxLen int64) int64

func (*Cache) ZAdd added in v0.2.12

func (c *Cache) ZAdd(s string, f float64, i ...interface{}) int64

func (*Cache) ZRangeByScore added in v0.2.12

func (c *Cache) ZRangeByScore(s string, i int64, i2 int64, i3 int64, i4 int64) []string

func (*Cache) ZRem added in v0.2.12

func (c *Cache) ZRem(s string, i ...interface{}) int64

type Option

type Option func(p *config)

func WithAttributes

func WithAttributes(attrs ...string) Option

WithAttributes specifies additional attributes to be added to the span.

func WithCleanupInterval

func WithCleanupInterval(cleanupInterval time.Duration) Option

func WithDefaultExpiration

func WithDefaultExpiration(defaultExpiration time.Duration) Option

func WithLogger

func WithLogger(logger glog.ILogger) Option

WithLogger prevents logger.

func WithTracer

func WithTracer(tracerServer *tracer.Server) Option

WithTracer specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.

type ShardedCache

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

func (*ShardedCache) Decrement

func (sc *ShardedCache) Decrement(key string, val int64) (int64, error)

func (*ShardedCache) Delete

func (sc *ShardedCache) Delete(key string) (int64, error)

func (*ShardedCache) DeleteExpired

func (sc *ShardedCache) DeleteExpired()

func (*ShardedCache) Flush

func (sc *ShardedCache) Flush()

func (*ShardedCache) Get

func (sc *ShardedCache) Get(key string) interface{}

func (*ShardedCache) GetString

func (sc *ShardedCache) GetString(key string) (string, error)

func (*ShardedCache) Increment

func (sc *ShardedCache) Increment(key string, val int64) (int64, error)

func (*ShardedCache) IncrementFloat

func (sc *ShardedCache) IncrementFloat(key string, val float64) (float64, error)

func (*ShardedCache) IsExist

func (sc *ShardedCache) IsExist(key string) bool

func (*ShardedCache) Set

func (sc *ShardedCache) Set(key string, val interface{}, timeout time.Duration) error

func (*ShardedCache) WithContext

func (sc *ShardedCache) WithContext(ctx context.Context) icache.ICache

func (*ShardedCache) WithDB

func (sc *ShardedCache) WithDB(db int) icache.ICache

Jump to

Keyboard shortcuts

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