backend

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MPL-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package backend provides interfaces and types for implementing cache backends. It defines the contract that all cache backends must follow, including operations for storing, retrieving, and managing cached items. The package supports generic backend implementations with type constraints to ensure type safety.

The main interface IBackend provides methods for:

  • Getting and setting cache items
  • Managing cache capacity and item count
  • Removing items and clearing the cache
  • Listing items with optional filters

Backend implementations must satisfy the IBackendConstrain type constraint, which currently supports InMemory and Redis backend types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOptions

func ApplyOptions[T IBackendConstrain](backend *T, options ...Option[T])

ApplyOptions applies the given options to the given backend.

Types

type ConsistencyLevel added in v0.2.0

type ConsistencyLevel int

ConsistencyLevel defines read/write consistency semantics.

const (
	// ConsistencyOne returns after a single owner success (fast, may be stale).
	ConsistencyOne ConsistencyLevel = iota
	// ConsistencyQuorum waits for majority (floor(n/2)+1).
	ConsistencyQuorum
	// ConsistencyAll waits for all owners.
	ConsistencyAll
)

type DistHTTPTransport added in v0.2.0

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

DistHTTPTransport implements DistTransport over HTTP JSON.

func NewDistHTTPTransport added in v0.2.0

func NewDistHTTPTransport(timeout time.Duration, resolver func(string) (string, bool)) *DistHTTPTransport

NewDistHTTPTransport constructs a DistHTTPTransport with the given timeout and nodeID->baseURL resolver. Timeout <=0 defaults to 2s.

func (*DistHTTPTransport) FetchMerkle added in v0.2.0

func (t *DistHTTPTransport) FetchMerkle(ctx context.Context, nodeID string) (*MerkleTree, error)

FetchMerkle retrieves a Merkle tree snapshot from a remote node.

func (*DistHTTPTransport) ForwardGet added in v0.2.0

func (t *DistHTTPTransport) ForwardGet(ctx context.Context, nodeID, key string) (*cache.Item, bool, error)

ForwardGet fetches a single item from a remote node.

func (*DistHTTPTransport) ForwardRemove added in v0.2.0

func (t *DistHTTPTransport) ForwardRemove(ctx context.Context, nodeID, key string, replicate bool) error

ForwardRemove propagates a delete operation to a remote node.

func (*DistHTTPTransport) ForwardSet added in v0.2.0

func (t *DistHTTPTransport) ForwardSet(ctx context.Context, nodeID string, item *cache.Item, replicate bool) error

ForwardSet sends a Set/Replicate request to a remote node.

func (*DistHTTPTransport) Health added in v0.2.0

func (t *DistHTTPTransport) Health(ctx context.Context, nodeID string) error

Health performs a health probe against a remote node.

func (*DistHTTPTransport) ListKeys added in v0.2.0

func (t *DistHTTPTransport) ListKeys(ctx context.Context, nodeID string) ([]string, error)

ListKeys returns all keys from a remote node (expensive; used for tests / anti-entropy fallback).

type DistMemory added in v0.2.0

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

DistMemory is a sharded in-process distributed-like backend. It simulates distribution by consistent hashing across a fixed set of in-memory shards. It is intended for single-process multi-shard experimentation; NOT cross-process.

func (*DistMemory) BuildMerkleTree added in v0.2.0

func (dm *DistMemory) BuildMerkleTree() *MerkleTree

BuildMerkleTree constructs a Merkle tree snapshot of local data (best-effort, locks each shard briefly).

func (*DistMemory) Capacity added in v0.2.0

func (dm *DistMemory) Capacity() int

Capacity returns logical capacity.

func (*DistMemory) Clear added in v0.2.0

func (dm *DistMemory) Clear(ctx context.Context) error

Clear wipes all shards.

func (*DistMemory) Count added in v0.2.0

func (dm *DistMemory) Count(_ context.Context) int

Count returns total items across shards.

func (*DistMemory) DebugDropLocal added in v0.2.0

func (dm *DistMemory) DebugDropLocal(key string)

DebugDropLocal removes a key only from the local shard (for tests / read-repair validation).

func (*DistMemory) DebugInject added in v0.2.0

func (dm *DistMemory) DebugInject(it *cache.Item)

DebugInject stores an item directly into the local shard (no replication / ownership checks) for tests.

func (*DistMemory) DebugOwners added in v0.2.0

func (dm *DistMemory) DebugOwners(key string) []cluster.NodeID

DebugOwners returns current owners slice for a key (for tests).

func (*DistMemory) DistMembershipSnapshot added in v0.2.1

func (dm *DistMemory) DistMembershipSnapshot() map[string]any

DistMembershipSnapshot returns lightweight membership view (states & version).

func (*DistMemory) Get added in v0.2.0

func (dm *DistMemory) Get(ctx context.Context, key string) (*cache.Item, bool)

Get fetches item.

func (*DistMemory) LatencyHistograms added in v0.2.1

func (dm *DistMemory) LatencyHistograms() map[string][]uint64

LatencyHistograms returns a snapshot of latency bucket counts per operation (ns buckets; last bucket +Inf).

func (*DistMemory) List added in v0.2.0

func (dm *DistMemory) List(_ context.Context, _ ...IFilter) ([]*cache.Item, error)

List aggregates items (no ordering, then filters applied per interface contract not yet integrated; kept simple).

func (*DistMemory) LocalContains added in v0.2.0

func (dm *DistMemory) LocalContains(key string) bool

LocalContains returns true if key exists in local shard (ignores ownership).

func (*DistMemory) LocalNodeAddr added in v0.2.0

func (dm *DistMemory) LocalNodeAddr() string

LocalNodeAddr returns the configured node address (host:port) used by HTTP server.

func (*DistMemory) LocalNodeID added in v0.2.0

func (dm *DistMemory) LocalNodeID() cluster.NodeID

LocalNodeID returns this instance's node ID (testing helper).

func (*DistMemory) Membership added in v0.2.0

func (dm *DistMemory) Membership() *cluster.Membership

Membership returns current membership reference (read-only usage).

func (*DistMemory) Metrics added in v0.2.0

func (dm *DistMemory) Metrics() DistMetrics

Metrics returns a snapshot of distributed metrics.

func (*DistMemory) Remove added in v0.2.0

func (dm *DistMemory) Remove(ctx context.Context, keys ...string) error

Remove deletes keys.

func (*DistMemory) Ring added in v0.2.0

func (dm *DistMemory) Ring() *cluster.Ring

Ring returns the ring reference.

func (*DistMemory) Set added in v0.2.0

func (dm *DistMemory) Set(ctx context.Context, item *cache.Item) error

Set stores item.

func (*DistMemory) SetCapacity added in v0.2.0

func (dm *DistMemory) SetCapacity(capacity int)

SetCapacity sets logical capacity.

func (*DistMemory) SetLocalNode added in v0.2.0

func (dm *DistMemory) SetLocalNode(node *cluster.Node)

SetLocalNode manually sets the local node (testing helper before starting HTTP).

func (*DistMemory) SetTransport added in v0.2.0

func (dm *DistMemory) SetTransport(t DistTransport)

SetTransport sets the transport post-construction (testing helper).

func (*DistMemory) Stop added in v0.2.0

func (dm *DistMemory) Stop(ctx context.Context) error

Stop stops heartbeat loop if running.

func (*DistMemory) SyncWith added in v0.2.0

func (dm *DistMemory) SyncWith(ctx context.Context, nodeID string) error

SyncWith performs Merkle anti-entropy against a remote node (pull newer versions for differing chunks).

type DistMemoryOption added in v0.2.0

type DistMemoryOption func(*DistMemory)

DistMemoryOption configures DistMemory backend.

func WithDistCapacity added in v0.2.0

func WithDistCapacity(capacity int) DistMemoryOption

WithDistCapacity sets logical capacity (not strictly enforced yet).

func WithDistGossipInterval added in v0.2.0

func WithDistGossipInterval(d time.Duration) DistMemoryOption

WithDistGossipInterval enables simple membership gossip at provided interval.

func WithDistHeartbeat added in v0.2.0

func WithDistHeartbeat(interval, suspectAfter, deadAfter time.Duration) DistMemoryOption

WithDistHeartbeat configures heartbeat interval and suspect/dead thresholds. If interval <= 0 heartbeat is disabled.

func WithDistHeartbeatSample added in v0.2.1

func WithDistHeartbeatSample(k int) DistMemoryOption

WithDistHeartbeatSample sets how many random peers to probe per heartbeat tick (0=all).

func WithDistHintMaxBytes added in v0.2.1

func WithDistHintMaxBytes(b int64) DistMemoryOption

WithDistHintMaxBytes sets an approximate byte cap for all queued hints.

func WithDistHintMaxPerNode added in v0.2.0

func WithDistHintMaxPerNode(n int) DistMemoryOption

WithDistHintMaxPerNode caps number of queued hints per target node.

func WithDistHintMaxTotal added in v0.2.1

func WithDistHintMaxTotal(n int) DistMemoryOption

WithDistHintMaxTotal sets a global cap on total queued hints across all nodes.

func WithDistHintReplayInterval added in v0.2.0

func WithDistHintReplayInterval(d time.Duration) DistMemoryOption

WithDistHintReplayInterval sets how often to attempt replay of hints.

func WithDistHintTTL added in v0.2.0

func WithDistHintTTL(d time.Duration) DistMemoryOption

WithDistHintTTL sets TTL for hinted handoff entries.

func WithDistListKeysCap added in v0.2.0

func WithDistListKeysCap(n int) DistMemoryOption

WithDistListKeysCap caps number of keys fetched via fallback ListKeys (0 = unlimited).

func WithDistMembership added in v0.2.0

func WithDistMembership(m *cluster.Membership, node *cluster.Node) DistMemoryOption

WithDistMembership injects an existing membership and (optionally) a local node for multi-node tests. If node is nil a new one will be created.

func WithDistMerkleAutoSync added in v0.2.0

func WithDistMerkleAutoSync(interval time.Duration) DistMemoryOption

WithDistMerkleAutoSync enables periodic anti-entropy sync attempts. If interval <= 0 disables.

func WithDistMerkleAutoSyncPeers added in v0.2.0

func WithDistMerkleAutoSyncPeers(n int) DistMemoryOption

WithDistMerkleAutoSyncPeers limits number of peers synced per interval (0 or <0 = all).

func WithDistMerkleChunkSize added in v0.2.0

func WithDistMerkleChunkSize(n int) DistMemoryOption

WithDistMerkleChunkSize sets the number of keys per leaf hash chunk (default 128 if 0).

func WithDistNode added in v0.2.0

func WithDistNode(id, address string) DistMemoryOption

WithDistNode identity (id optional; derived from address if empty). Address used for future RPC.

func WithDistParallelReads added in v0.2.0

func WithDistParallelReads(enable bool) DistMemoryOption

WithDistParallelReads enables parallel quorum/all read fan-out.

func WithDistReadConsistency added in v0.2.0

func WithDistReadConsistency(l ConsistencyLevel) DistMemoryOption

WithDistReadConsistency sets read consistency (default ONE).

func WithDistRebalanceBatchSize added in v0.2.1

func WithDistRebalanceBatchSize(n int) DistMemoryOption

WithDistRebalanceBatchSize sets max keys per transfer batch.

func WithDistRebalanceInterval added in v0.2.1

func WithDistRebalanceInterval(d time.Duration) DistMemoryOption

WithDistRebalanceInterval enables periodic ownership rebalancing checks (<=0 disables).

func WithDistRebalanceMaxConcurrent added in v0.2.1

func WithDistRebalanceMaxConcurrent(n int) DistMemoryOption

WithDistRebalanceMaxConcurrent limits concurrent batch transfers.

func WithDistReplication added in v0.2.0

func WithDistReplication(n int) DistMemoryOption

WithDistReplication sets ring replication factor (owners per key).

func WithDistSeeds added in v0.2.0

func WithDistSeeds(addresses []string) DistMemoryOption

WithDistSeeds configures static seed node addresses.

func WithDistShardCount added in v0.2.0

func WithDistShardCount(n int) DistMemoryOption

WithDistShardCount sets number of shards (min 1).

func WithDistTombstoneSweep added in v0.2.0

func WithDistTombstoneSweep(interval time.Duration) DistMemoryOption

WithDistTombstoneSweep sets sweep interval for tombstone compaction (<=0 disables automatic sweeps).

func WithDistTombstoneTTL added in v0.2.0

func WithDistTombstoneTTL(d time.Duration) DistMemoryOption

WithDistTombstoneTTL configures how long tombstones are retained before subject to compaction (<=0 keeps indefinitely).

func WithDistTransport added in v0.2.0

func WithDistTransport(t DistTransport) DistMemoryOption

WithDistTransport sets a transport used for forwarding / replication.

func WithDistVirtualNodes added in v0.2.0

func WithDistVirtualNodes(n int) DistMemoryOption

WithDistVirtualNodes sets number of virtual nodes per physical node for consistent hash ring.

func WithDistWriteConsistency added in v0.2.0

func WithDistWriteConsistency(l ConsistencyLevel) DistMemoryOption

WithDistWriteConsistency sets write consistency (default QUORUM).

type DistMetrics added in v0.2.0

type DistMetrics struct {
	ForwardGet          int64
	ForwardSet          int64
	ForwardRemove       int64
	ReplicaFanoutSet    int64
	ReplicaFanoutRemove int64
	ReadRepair          int64
	ReplicaGetMiss      int64
	HeartbeatSuccess    int64
	HeartbeatFailure    int64
	NodesSuspect        int64
	NodesDead           int64
	NodesRemoved        int64
	VersionConflicts    int64
	VersionTieBreaks    int64
	ReadPrimaryPromote  int64
	HintedQueued        int64
	HintedReplayed      int64
	HintedExpired       int64
	HintedDropped       int64
	HintedGlobalDropped int64
	HintedBytes         int64
	MerkleSyncs         int64
	MerkleKeysPulled    int64
	MerkleBuildNanos    int64
	MerkleDiffNanos     int64
	MerkleFetchNanos    int64
	AutoSyncLoops       int64
	LastAutoSyncNanos   int64
	LastAutoSyncError   string
	TombstonesActive    int64
	TombstonesPurged    int64
	WriteQuorumFailures int64
	WriteAcks           int64
	WriteAttempts       int64
	RebalancedKeys      int64
	RebalanceBatches    int64
	RebalanceThrottle   int64
	RebalanceLastNanos  int64
	MembershipVersion   uint64 // current membership version (incremented on changes)
	MembersAlive        int64  // current alive members
	MembersSuspect      int64  // current suspect members
	MembersDead         int64  // current dead members
}

DistMetrics snapshot.

type DistTransport added in v0.2.0

type DistTransport interface {
	ForwardSet(ctx context.Context, nodeID string, item *cache.Item, replicate bool) error
	ForwardGet(ctx context.Context, nodeID string, key string) (*cache.Item, bool, error)
	ForwardRemove(ctx context.Context, nodeID string, key string, replicate bool) error
	Health(ctx context.Context, nodeID string) error
	FetchMerkle(ctx context.Context, nodeID string) (*MerkleTree, error)
}

DistTransport defines forwarding operations needed by DistMemory.

type IBackend

type IBackend[T IBackendConstrain] interface {
	// Get retrieves the item with the given key from the cache.
	// If the key is not found in the cache, it returns nil.
	Get(ctx context.Context, key string) (item *cache.Item, ok bool)
	// Set adds a new item to the cache.
	Set(ctx context.Context, item *cache.Item) error
	// Capacity returns the maximum number of items that can be stored in the cache.
	Capacity() int
	// SetCapacity sets the maximum number of items that can be stored in the cache.
	SetCapacity(capacity int)
	// Count returns the number of items currently stored in the cache.
	Count(ctx context.Context) int
	// Remove deletes the item with the given key from the cache.
	Remove(ctx context.Context, keys ...string) error
	// List the items in the cache that meet the specified criteria.
	List(ctx context.Context, filters ...IFilter) (items []*cache.Item, err error)
	// Clear removes all items from the cache.
	Clear(ctx context.Context) error
}

IBackend defines the contract that all cache backends must implement. It provides a generic interface for cache operations with type safety through the IBackendConstrain type parameter.

Type parameter T must satisfy IBackendConstrain, limiting implementations to supported backend types like InMemory and Redis.

All methods accept a context.Context parameter for cancellation and timeout control, enabling graceful handling of long-running operations.

func NewDistMemory added in v0.2.0

func NewDistMemory(ctx context.Context, opts ...DistMemoryOption) (IBackend[DistMemory], error)

NewDistMemory creates a new DistMemory backend.

func NewDistMemoryWithConfig added in v0.2.1

func NewDistMemoryWithConfig(ctx context.Context, cfg any, opts ...DistMemoryOption) (IBackend[DistMemory], error)

NewDistMemoryWithConfig builds a DistMemory from an external dist.Config shape without introducing a direct import here. Accepts a generic 'cfg' to avoid adding a dependency layer; expects exported fields matching internal/dist Config.

func NewInMemory

func NewInMemory(opts ...Option[InMemory]) (IBackend[InMemory], error)

NewInMemory creates a new in-memory cache with the given options.

func NewRedis

func NewRedis(redisOptions ...Option[Redis]) (IBackend[Redis], error)

NewRedis creates a new redis cache with the given options.

func NewRedisCluster added in v0.1.8

func NewRedisCluster(redisOptions ...Option[RedisCluster]) (IBackend[RedisCluster], error)

NewRedisCluster creates a new Redis Cluster backend with the given options.

type IBackendConstrain

type IBackendConstrain interface {
	InMemory | Redis | RedisCluster | DistMemory
}

IBackendConstrain defines the type constraint for cache backend implementations. It restricts the generic type parameter to supported backend types, ensuring type safety and proper implementation at compile time.

type IFilter

type IFilter interface {
	ApplyFilter(backendType string, items []*cache.Item) ([]*cache.Item, error)
}

IFilter is a backend agnostic interface for a filter that can be applied to a list of items.

func WithFilterFunc

func WithFilterFunc(fn func(item *cache.Item) bool) IFilter

WithFilterFunc returns a filter that filters the items by a given field's value.

func WithSortBy

func WithSortBy(field string) IFilter

WithSortBy returns a filter that sorts the items by a given field.

type InMemory

type InMemory struct {
	sync.RWMutex // mutex to protect the cache from concurrent access
	// contains filtered or unexported fields
}

InMemory is a cache backend that stores the items in memory, leveraging a custom `ConcurrentMap`.

func (*InMemory) Capacity

func (cacheBackend *InMemory) Capacity() int

Capacity returns the capacity of the cacheBackend.

func (*InMemory) Clear

func (cacheBackend *InMemory) Clear(ctx context.Context) error

Clear removes all items from the cacheBackend.

func (*InMemory) Count

func (cacheBackend *InMemory) Count(_ context.Context) int

Count returns the number of items in the cache.

func (*InMemory) Get

func (cacheBackend *InMemory) Get(_ context.Context, key string) (*cache.Item, bool)

Get retrieves the item with the given key from the cacheBackend. If the item is not found, it returns nil.

func (*InMemory) List

func (cacheBackend *InMemory) List(_ context.Context, filters ...IFilter) ([]*cache.Item, error)

List returns a list of all items in the cache filtered and ordered by the given options.

func (*InMemory) Remove

func (cacheBackend *InMemory) Remove(ctx context.Context, keys ...string) error

Remove removes items with the given key from the cacheBackend. If an item is not found, it does nothing.

func (*InMemory) Set

func (cacheBackend *InMemory) Set(_ context.Context, item *cache.Item) error

Set adds a Item to the cache.

func (*InMemory) SetCapacity

func (cacheBackend *InMemory) SetCapacity(capacity int)

SetCapacity sets the capacity of the cache.

type InProcessTransport added in v0.2.0

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

InProcessTransport implements DistTransport for multiple DistMemory instances in the same process.

func NewInProcessTransport added in v0.2.0

func NewInProcessTransport() *InProcessTransport

NewInProcessTransport creates a new empty transport.

func (*InProcessTransport) FetchMerkle added in v0.2.0

func (t *InProcessTransport) FetchMerkle(_ context.Context, nodeID string) (*MerkleTree, error)

FetchMerkle fetches a remote merkle tree.

func (*InProcessTransport) ForwardGet added in v0.2.0

func (t *InProcessTransport) ForwardGet(_ context.Context, nodeID string, key string) (*cache.Item, bool, error)

ForwardGet forwards a get operation to the specified backend node.

func (*InProcessTransport) ForwardRemove added in v0.2.0

func (t *InProcessTransport) ForwardRemove(ctx context.Context, nodeID string, key string, replicate bool) error

ForwardRemove forwards a remove operation.

func (*InProcessTransport) ForwardSet added in v0.2.0

func (t *InProcessTransport) ForwardSet(ctx context.Context, nodeID string, item *cache.Item, replicate bool) error

ForwardSet forwards a set operation to the specified backend node.

func (*InProcessTransport) Health added in v0.2.0

func (t *InProcessTransport) Health(_ context.Context, nodeID string) error

Health probes a backend.

func (*InProcessTransport) Register added in v0.2.0

func (t *InProcessTransport) Register(b *DistMemory)

Register adds backends; safe to call multiple times.

func (*InProcessTransport) Unregister added in v0.2.0

func (t *InProcessTransport) Unregister(id string)

Unregister removes a backend (simulate failure in tests).

type MerkleTree added in v0.2.0

type MerkleTree struct {
	LeafHashes [][]byte // ordered leaf hashes
	Root       []byte
	ChunkSize  int
}

MerkleTree represents a binary hash tree over key/version pairs.

func (*MerkleTree) DiffLeafRanges added in v0.2.0

func (mt *MerkleTree) DiffLeafRanges(other *MerkleTree) []int

DiffLeafRanges compares two trees and returns indexes of differing leaf chunks.

type Option

type Option[T IBackendConstrain] func(*T)

Option is a function type that can be used to configure the `HyperCache` struct.

func WithCapacity

func WithCapacity[T IBackendConstrain](capacity int) Option[T]

WithCapacity is an option that sets the capacity of the cache.

func WithClusterKeysSetName added in v0.1.8

func WithClusterKeysSetName[T RedisCluster](keysSetName string) Option[RedisCluster]

WithClusterKeysSetName sets the name of the set for cluster backend keys.

func WithClusterSerializer added in v0.1.8

func WithClusterSerializer[T RedisCluster](ser serializer.ISerializer) Option[RedisCluster]

WithClusterSerializer sets the serializer for the cluster backend.

func WithKeysSetName

func WithKeysSetName[T Redis](keysSetName string) Option[Redis]

WithKeysSetName is an option that sets the name of the set that holds the keys of the items in the cache.

func WithRedisClient

func WithRedisClient[T Redis](client *redis.Client) Option[Redis]

WithRedisClient is an option that sets the redis client to use.

func WithRedisClusterClient added in v0.1.8

func WithRedisClusterClient[T RedisCluster](client *redis.ClusterClient) Option[RedisCluster]

WithRedisClusterClient sets the redis cluster client to use.

func WithSerializer

func WithSerializer[T Redis](backendSerializer serializer.ISerializer) Option[Redis]

WithSerializer is an option that sets the serializer to use. The serializer is used to serialize and deserialize the items in the cache.

  • The default serializer is `serializer.MsgpackSerializer`.
  • The `serializer.JSONSerializer` can be used to serialize and deserialize the items in the cache as JSON.
  • The interface `serializer.ISerializer` can be implemented to use a custom serializer.

type Redis

type Redis struct {
	Serializer serializer.ISerializer // Serializer is the serializer used to serialize the items before storing them in the cache
	// contains filtered or unexported fields
}

Redis is a cache backend that stores the items in a redis implementation.

func (*Redis) Capacity

func (cacheBackend *Redis) Capacity() int

Capacity returns the maximum number of items that can be stored in the cache.

func (*Redis) Clear

func (cacheBackend *Redis) Clear(ctx context.Context) error

Clear removes all items from the cache.

func (*Redis) Count

func (cacheBackend *Redis) Count(ctx context.Context) int

Count returns the number of items in the cache.

func (*Redis) Get

func (cacheBackend *Redis) Get(ctx context.Context, key string) (*cache.Item, bool)

Get retrieves the Item with the given key from the cacheBackend. If the item is not found, it returns nil.

func (*Redis) List

func (cacheBackend *Redis) List(ctx context.Context, filters ...IFilter) ([]*cache.Item, error)

List returns a list of all the items in the cacheBackend that match the given filter options.

func (*Redis) Remove

func (cacheBackend *Redis) Remove(ctx context.Context, keys ...string) error

Remove removes an item from the cache with the given key.

func (*Redis) Set

func (cacheBackend *Redis) Set(ctx context.Context, item *cache.Item) error

Set stores the Item in the cacheBackend.

func (*Redis) SetCapacity

func (cacheBackend *Redis) SetCapacity(capacity int)

SetCapacity sets the capacity of the cache.

type RedisCluster added in v0.1.8

type RedisCluster struct {
	Serializer serializer.ISerializer
	// contains filtered or unexported fields
}

RedisCluster is a cache backend that stores items in a Redis Cluster. It mirrors the single-node Redis backend semantics but uses go-redis ClusterClient.

func (*RedisCluster) Capacity added in v0.1.8

func (cacheBackend *RedisCluster) Capacity() int

Capacity returns the capacity of the cluster backend.

func (*RedisCluster) Clear added in v0.1.8

func (cacheBackend *RedisCluster) Clear(ctx context.Context) error

Clear flushes the database.

func (*RedisCluster) Count added in v0.1.8

func (cacheBackend *RedisCluster) Count(ctx context.Context) int

Count returns the number of keys stored.

func (*RedisCluster) Get added in v0.1.8

func (cacheBackend *RedisCluster) Get(ctx context.Context, key string) (*cache.Item, bool)

Get retrieves an item by key.

func (*RedisCluster) List added in v0.1.8

func (cacheBackend *RedisCluster) List(ctx context.Context, filters ...IFilter) ([]*cache.Item, error)

List returns items matching optional filters.

func (*RedisCluster) Remove added in v0.1.8

func (cacheBackend *RedisCluster) Remove(ctx context.Context, keys ...string) error

Remove deletes the specified keys.

func (*RedisCluster) Set added in v0.1.8

func (cacheBackend *RedisCluster) Set(ctx context.Context, item *cache.Item) error

Set stores an item in the cluster.

func (*RedisCluster) SetCapacity added in v0.1.8

func (cacheBackend *RedisCluster) SetCapacity(capacity int)

SetCapacity sets the capacity of the cluster backend.

type SortOrderFilter

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

SortOrderFilter is a filter that sorts the items by a given field.

func WithSortOrderAsc

func WithSortOrderAsc(ascending bool) SortOrderFilter

WithSortOrderAsc returns a filter that determines whether to sort ascending or not.

func (SortOrderFilter) ApplyFilter

func (f SortOrderFilter) ApplyFilter(_ string, items []*cache.Item) ([]*cache.Item, error)

ApplyFilter applies the sort order filter to the given list of items.

Directories

Path Synopsis
Package redis provides configuration options and utilities for Redis backend implementation.
Package redis provides configuration options and utilities for Redis backend implementation.
Package rediscluster provides configuration options and utilities for Redis Cluster backend implementation.
Package rediscluster provides configuration options and utilities for Redis Cluster backend implementation.

Jump to

Keyboard shortcuts

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