store

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Set              string = "SET"
	Del              string = "DEL"
	Get              string = "GET"
	Rename           string = "RENAME"
	ZAdd             string = "ZADD"
	ZRange           string = "ZRANGE"
	Replace          string = "REPLACE"
	Smembers         string = "SMEMBERS"
	JSONGet          string = "JSON.GET"
	PFADD            string = "PFADD"
	PFCOUNT          string = "PFCOUNT"
	PFMERGE          string = "PFMERGE"
	KEYSPERSHARD     string = "KEYSPERSHARD"
	Evict            string = "EVICT"
	SingleShardSize  string = "SINGLEDBSIZE"
	SingleShardTouch string = "SINGLETOUCH"
	SingleShardKeys  string = "SINGLEKEYS"
	FlushDB          string = "FLUSHDB"
)
View Source
const (
	NX string = "NX"
	XX string = "XX"
	GT string = "GT"
	LT string = "LT"
)
View Source
const (
	FileMode int = 0644
)

Variables

This section is empty.

Functions

func DelExpiry

func DelExpiry(obj *object.Obj, store *Store)

func DeleteExpiredKeys

func DeleteExpiredKeys(store *Store)

DeleteExpiredKeys deletes all the expired keys - the active way

func EvaluateAndSetExpiry

func EvaluateAndSetExpiry(subCommands []string, newExpiryAbsMillis int64, key string,
	store *Store) (shouldSetExpiry bool, err error)

NX: Set the expiration only if the key does not already have an expiration time. XX: Set the expiration only if the key already has an expiration time. GT: Set the expiration only if the new expiration time is greater than the current one. LT: Set the expiration only if the new expiration time is less than the current one. Returns Boolean True and error nil if expiry was set on the key successfully. Returns Boolean False and error nil if conditions didn't met. Returns Boolean False and error not-nil if invalid combination of subCommands or if subCommand is invalid

func GetExpiry

func GetExpiry(obj *object.Obj, store *Store) (int64, bool)

func GetIdleTime

func GetIdleTime(lastAccessedAt int64) int64

func NewExpireMap

func NewExpireMap() common.ITable[*object.Obj, int64]

func NewExpireRegMap

func NewExpireRegMap() common.ITable[*object.Obj, int64]

func NewStoreMap

func NewStoreMap() common.ITable[string, *object.Obj]

func NewStoreRegMap

func NewStoreRegMap() common.ITable[string, *object.Obj]

Types

type AOF

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

func NewAOF

func NewAOF(path string) (*AOF, error)

func (*AOF) Close

func (a *AOF) Close() error

func (*AOF) Load

func (a *AOF) Load() ([]string, error)

func (*AOF) Write

func (a *AOF) Write(operation string) error

type AccessType

type AccessType int

AccessType represents different types of access to a key

const (
	AccessGet AccessType = iota
	AccessSet
	AccessDel
)

type BaseEvictionStrategy

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

BaseEvictionStrategy provides common functionality for all eviction strategies

func (*BaseEvictionStrategy) AfterEviction

func (b *BaseEvictionStrategy) AfterEviction(result EvictionResult)

func (*BaseEvictionStrategy) GetStats

func (b *BaseEvictionStrategy) GetStats() EvictionStats

type CmdWatchEvent

type CmdWatchEvent struct {
	Cmd         string
	AffectedKey string
}

type DelOption

type DelOption func(*DelOptions)

func WithDelCmd

func WithDelCmd(cmd string) DelOption

type DelOptions

type DelOptions struct {
	DelCmd string
}

type EvictionResult

type EvictionResult struct {
	Victims map[string]*object.Obj // Keys and objects that were selected for eviction
	Count   int64                  // Number of items selected for eviction
}

EvictionResult represents the outcome of an eviction operation

type EvictionStats

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

EvictionStats tracks common statistics for all eviction strategies

type EvictionStrategy

type EvictionStrategy interface {
	// ShouldEvict checks if eviction should be triggered based on the current store state
	// Returns the number of items that should be evicted, or 0 if no eviction is needed
	ShouldEvict(store *Store) int

	// EvictVictims evicts items from the store based on the eviction strategy
	EvictVictims(store *Store, toEvict int)

	// OnAccess is called when an item is accessed (get/set)
	// This allows strategies to update access patterns/statistics
	OnAccess(key string, obj *object.Obj, accessType AccessType)
}

EvictionStrategy defines the interface for different eviction strategies

func NewDefaultEviction

func NewDefaultEviction() EvictionStrategy

type PrimitiveEvictionStrategy

type PrimitiveEvictionStrategy struct {
	BaseEvictionStrategy
	// contains filtered or unexported fields
}

PrimitiveEvictionStrategy implements batch eviction of least recently used keys

func NewPrimitiveEvictionStrategy

func NewPrimitiveEvictionStrategy(maxKeys int) *PrimitiveEvictionStrategy

func (*PrimitiveEvictionStrategy) EvictVictims

func (e *PrimitiveEvictionStrategy) EvictVictims(store *Store, toEvict int)

EvictVictims deletes keys with the lowest LastAccessedAt values from the store.

func (*PrimitiveEvictionStrategy) OnAccess

func (e *PrimitiveEvictionStrategy) OnAccess(key string, obj *object.Obj, accessType AccessType)

func (*PrimitiveEvictionStrategy) ShouldEvict

func (e *PrimitiveEvictionStrategy) ShouldEvict(store *Store) int

type PutOption

type PutOption func(*PutOptions)

func WithKeepTTL

func WithKeepTTL(value bool) PutOption

func WithPutCmd

func WithPutCmd(cmd string) PutOption

type PutOptions

type PutOptions struct {
	KeepTTL bool
	PutCmd  string
}

type QueryWatchEvent

type QueryWatchEvent struct {
	Key       string
	Operation string
	Value     object.Obj
}

QueryWatchEvent represents a change in a watched key.

type Store

type Store struct {
	ShardID int
	// contains filtered or unexported fields
}

func NewStore

func NewStore(cmdWatchChan chan CmdWatchEvent, evictionStrategy EvictionStrategy, shardID int) *Store

func Reset

func Reset(store *Store) *Store

func (*Store) Del

func (store *Store) Del(k string, opts ...DelOption) bool

func (*Store) DelByPtr

func (store *Store) DelByPtr(ptr string, opts ...DelOption) bool

func (*Store) Get

func (store *Store) Get(k string) *object.Obj

func (*Store) GetAll

func (store *Store) GetAll(keys []string) []*object.Obj

func (*Store) GetDBSize

func (store *Store) GetDBSize() uint64

GetDBSize returns number of keys present in the database

func (*Store) GetDel

func (store *Store) GetDel(k string, opts ...DelOption) *object.Obj

func (*Store) GetKeyCount

func (store *Store) GetKeyCount() int

func (*Store) GetNoTouch

func (store *Store) GetNoTouch(k string) *object.Obj

func (*Store) GetStore

func (store *Store) GetStore() common.ITable[string, *object.Obj]

func (*Store) IncrementKeyCount

func (store *Store) IncrementKeyCount()

func (*Store) Keys

func (store *Store) Keys(p string) ([]string, error)

func (*Store) NewObj

func (store *Store) NewObj(value interface{}, expDurationMs int64, oType object.ObjectType) *object.Obj

func (*Store) Put

func (store *Store) Put(k string, obj *object.Obj, opts ...PutOption)

func (*Store) PutAll

func (store *Store) PutAll(data map[string]*object.Obj)

func (*Store) Rename

func (store *Store) Rename(sourceKey, destKey string) bool

Rename function to implement RENAME functionality using existing helpers

func (*Store) ResetStore

func (store *Store) ResetStore()

func (*Store) SetExpiry

func (store *Store) SetExpiry(obj *object.Obj, expDurationMs int64)

SetExpiry sets the expiry time for an object. This method is not thread-safe. It should be called within a lock.

func (*Store) SetUnixTimeExpiry

func (store *Store) SetUnixTimeExpiry(obj *object.Obj, exUnixTimeMillis int64)

SetUnixTimeExpiry sets the expiry time for an object. This method is not thread-safe. It should be called within a lock.

Jump to

Keyboard shortcuts

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