Documentation
¶
Index ¶
- Constants
- type CacheItem
- type CombinedCache
- type CombinedConfig
- type CustomZ
- type LocalCache
- type LocalConfig
- type MockZCache
- func (m *MockZCache) Client() *redis.Client
- func (m *MockZCache) Decr(ctx context.Context, key string) (int64, error)
- func (m *MockZCache) DecrBy(ctx context.Context, key string, value int64) (int64, error)
- func (m *MockZCache) Delete(ctx context.Context, key string) error
- func (m *MockZCache) DeleteMulti(ctx context.Context, keys ...string) error
- func (m *MockZCache) Exists(ctx context.Context, keys ...string) (int64, error)
- func (m *MockZCache) Expire(ctx context.Context, key string, ttl time.Duration) (bool, error)
- func (m *MockZCache) FlushAll(ctx context.Context) error
- func (m *MockZCache) Get(ctx context.Context, key string, data interface{}) error
- func (m *MockZCache) GetStats() ZCacheStats
- func (m *MockZCache) HExists(ctx context.Context, key, field string) (bool, error)
- func (m *MockZCache) HGet(ctx context.Context, key, field string) (string, error)
- func (m *MockZCache) HGetAll(ctx context.Context, key string) (map[string]string, error)
- func (m *MockZCache) HIncrBy(ctx context.Context, key, field string, incr int64) (int64, error)
- func (m *MockZCache) HSet(ctx context.Context, key string, values ...interface{}) (int64, error)
- func (m *MockZCache) HSetNX(ctx context.Context, key, field string, value interface{}) (bool, error)
- func (m *MockZCache) Incr(ctx context.Context, key string) (int64, error)
- func (m *MockZCache) IncrBy(ctx context.Context, key string, value int64) (int64, error)
- func (m *MockZCache) IsNotFoundError(err error) bool
- func (m *MockZCache) Keys(ctx context.Context, pattern string) ([]string, error)
- func (m *MockZCache) LPush(ctx context.Context, key string, values ...interface{}) (int64, error)
- func (m *MockZCache) NewMutex(name string, expiry time.Duration) ZMutex
- func (m *MockZCache) Pipeline() RedisPipeline
- func (m *MockZCache) RPush(ctx context.Context, key string, values ...interface{}) (int64, error)
- func (m *MockZCache) SAdd(ctx context.Context, key string, members ...interface{}) (int64, error)
- func (m *MockZCache) SMembers(ctx context.Context, key string) ([]string, error)
- func (m *MockZCache) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (m *MockZCache) SetNX(ctx context.Context, key string, value interface{}, ttl time.Duration) (bool, error)
- func (m *MockZCache) SetupAndMonitorMetrics(appName string, metricsServer metrics.TaskMetrics, ...) []error
- func (m *MockZCache) TTL(ctx context.Context, key string) (time.Duration, error)
- func (m *MockZCache) TxPipeline() RedisPipeline
- func (m *MockZCache) ZIncrBy(ctx context.Context, key string, member string, increment float64) (float64, error)
- func (m *MockZCache) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) ([]CustomZ, error)
- type MockZMutex
- type RedisPipeline
- type RedisStats
- type RemoteCache
- type RemoteConfig
- type StatsMetrics
- type ZCache
- type ZCacheStats
- type ZMutex
Constants ¶
View Source
const ( // Default Ristretto cache config DefaultNumCounters = int64(1e7) // 10M keys DefaultMaxCostMB = int64(1024) // 1GB DefaultBufferItems = int64(64) )
View Source
const KeySplitter = "/"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CombinedCache ¶ added in v0.11.0
type CombinedCache interface {
ZCache
}
func NewCombinedCache ¶ added in v0.11.0
func NewCombinedCache(combinedConfig *CombinedConfig) (CombinedCache, error)
type CombinedConfig ¶ added in v0.11.0
type CombinedConfig struct {
Local *LocalConfig
Remote *RemoteConfig
GlobalLogger *logger.Logger
GlobalPrefix string
GlobalMetricServer metrics.TaskMetrics
GlobalStatsMetrics StatsMetrics
IsRemoteBestEffort bool
}
type LocalCache ¶ added in v0.10.1
type LocalCache interface {
ZCache
}
func NewLocalCache ¶ added in v0.10.1
func NewLocalCache(config *LocalConfig) (LocalCache, error)
type LocalConfig ¶ added in v0.10.1
type LocalConfig struct {
Prefix string
Logger *logger.Logger
MetricServer metrics.TaskMetrics
StatsMetrics StatsMetrics
// Add Ristretto cache configuration
NumCounters int64 `json:"num_counters"` // default: 1e7
MaxCostMB int64 `json:"max_cost_mb"` // in MB, default: 1024 (1GB)
BufferItems int64 `json:"buffer_items"` // default: 64
}
func (*LocalConfig) ToRistrettoConfig ¶ added in v0.21.0
func (c *LocalConfig) ToRistrettoConfig() *ristretto.Config
type MockZCache ¶
func (*MockZCache) Client ¶ added in v0.29.0
func (m *MockZCache) Client() *redis.Client
func (*MockZCache) DeleteMulti ¶ added in v0.29.0
func (m *MockZCache) DeleteMulti(ctx context.Context, keys ...string) error
func (*MockZCache) Get ¶
func (m *MockZCache) Get(ctx context.Context, key string, data interface{}) error
func (*MockZCache) GetStats ¶ added in v0.14.2
func (m *MockZCache) GetStats() ZCacheStats
func (*MockZCache) IsNotFoundError ¶ added in v0.14.2
func (m *MockZCache) IsNotFoundError(err error) bool
func (*MockZCache) NewMutex ¶ added in v0.29.0
func (m *MockZCache) NewMutex(name string, expiry time.Duration) ZMutex
func (*MockZCache) Pipeline ¶ added in v0.29.0
func (m *MockZCache) Pipeline() RedisPipeline
func (*MockZCache) SetupAndMonitorMetrics ¶ added in v0.14.2
func (m *MockZCache) SetupAndMonitorMetrics(appName string, metricsServer metrics.TaskMetrics, updateInterval time.Duration) []error
func (*MockZCache) TxPipeline ¶ added in v0.29.0
func (m *MockZCache) TxPipeline() RedisPipeline
func (*MockZCache) ZRevRangeWithScores ¶ added in v0.17.0
type MockZMutex ¶
func (*MockZMutex) Lock ¶
func (m *MockZMutex) Lock() error
func (*MockZMutex) Name ¶
func (m *MockZMutex) Name() string
func (*MockZMutex) Unlock ¶
func (m *MockZMutex) Unlock() (bool, error)
type RedisPipeline ¶ added in v0.29.0
type RedisPipeline interface {
IncrBy(ctx context.Context, key string, value int64) *redis.IntCmd
HIncrBy(ctx context.Context, key, field string, incr int64) *redis.IntCmd
HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd
HSetNX(ctx context.Context, key, field string, value interface{}) *redis.BoolCmd
HExists(ctx context.Context, key, field string) *redis.BoolCmd
HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
Expire(ctx context.Context, key string, expiration time.Duration) *redis.BoolCmd
Del(ctx context.Context, keys ...string) *redis.IntCmd
Exec(ctx context.Context) ([]redis.Cmder, error)
}
RedisPipeline provides pipelined execution of Redis commands
type RedisStats ¶ added in v0.11.0
type RemoteCache ¶ added in v0.10.1
type RemoteCache interface {
ZCache
SetNX(ctx context.Context, key string, value interface{}, ttl time.Duration) (bool, error)
Incr(ctx context.Context, key string) (int64, error)
Decr(ctx context.Context, key string) (int64, error)
LPush(ctx context.Context, key string, values ...interface{}) (int64, error)
RPush(ctx context.Context, key string, values ...interface{}) (int64, error)
SMembers(ctx context.Context, key string) ([]string, error)
SAdd(ctx context.Context, key string, members ...interface{}) (int64, error)
HSet(ctx context.Context, key string, values ...interface{}) (int64, error)
HGet(ctx context.Context, key, field string) (string, error)
ZIncrBy(ctx context.Context, key string, member string, increment float64) (float64, error)
ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) ([]CustomZ, error)
FlushAll(ctx context.Context) error
Exists(ctx context.Context, keys ...string) (int64, error)
Expire(ctx context.Context, key string, ttl time.Duration) (bool, error)
TTL(ctx context.Context, key string) (time.Duration, error)
// Extended Redis operations
IncrBy(ctx context.Context, key string, value int64) (int64, error)
DecrBy(ctx context.Context, key string, value int64) (int64, error)
HIncrBy(ctx context.Context, key, field string, incr int64) (int64, error)
HSetNX(ctx context.Context, key, field string, value interface{}) (bool, error)
HExists(ctx context.Context, key, field string) (bool, error)
HGetAll(ctx context.Context, key string) (map[string]string, error)
Keys(ctx context.Context, pattern string) ([]string, error)
DeleteMulti(ctx context.Context, keys ...string) error
// Pipeline support
Pipeline() RedisPipeline
TxPipeline() RedisPipeline
// Distributed mutex
NewMutex(name string, expiry time.Duration) ZMutex
// Underlying client access (use with caution - prefer interface methods)
Client() *redis.Client
}
func NewRemoteCache ¶ added in v0.10.1
func NewRemoteCache(config *RemoteConfig) (RemoteCache, error)
type RemoteConfig ¶ added in v0.10.1
type RemoteConfig struct {
Network string
Addr string
Password string
DB int
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
PoolSize int
MinIdleConns int
MaxConnAge time.Duration
PoolTimeout time.Duration
IdleTimeout time.Duration
IdleCheckFrequency time.Duration
Prefix string
Logger *logger.Logger
MetricServer metrics.TaskMetrics
StatsMetrics StatsMetrics
// TLS Configuration
TLSEnabled bool // Enable TLS connection
TLSCertPath string // Path to client TLS certificate (optional, for mTLS)
TLSKeyPath string // Path to client TLS key (optional, for mTLS)
TLSCAPath string // Path to CA certificate (optional)
InsecureSkipVerify bool // Skip TLS verification (dev only)
}
func (*RemoteConfig) GetHost ¶ added in v0.29.0
func (c *RemoteConfig) GetHost() string
GetHost returns the host portion of Addr. Properly handles IPv6 addresses (e.g., "[::1]:6379").
func (*RemoteConfig) GetPort ¶ added in v0.29.0
func (c *RemoteConfig) GetPort() int
GetPort returns the port portion of Addr, or 0 if not set or invalid. Properly handles IPv6 addresses (e.g., "[::1]:6379").
func (*RemoteConfig) SetAddr ¶ added in v0.29.0
func (c *RemoteConfig) SetAddr(host string, port int)
SetAddr sets Addr from separate host and port values. Properly handles IPv6 addresses by using net.JoinHostPort.
func (*RemoteConfig) ToRedisConfig ¶ added in v0.10.1
func (c *RemoteConfig) ToRedisConfig() (*redis.Options, error)
type StatsMetrics ¶ added in v0.17.1
type ZCacheStats ¶ added in v0.11.0
type ZCacheStats struct {
Local *ristretto.Metrics
Remote *RedisStats
}
Click to show internal directories.
Click to hide internal directories.