Documentation
¶
Index ¶
- Constants
- Variables
- type Batch
- type BloomData
- type BloomPayload
- type CMSPayload
- type Capacitor
- func (f *Capacitor) BloomAdd(ctx context.Context, key string, element string) (bool, error)
- func (f *Capacitor) BloomExists(ctx context.Context, key string, element string) (bool, error)
- func (f *Capacitor) CMSIncrement(ctx context.Context, key string, element string, count int64) error
- func (f *Capacitor) CMSQuery(ctx context.Context, key string, element string) (int64, error)
- func (f *Capacitor) Close() error
- func (f *Capacitor) Delete(ctx context.Context, key string) error
- func (f *Capacitor) Exists(ctx context.Context, key string) (bool, error)
- func (f *Capacitor) Get(ctx context.Context, key string) (string, error)
- func (f *Capacitor) GetCount(ctx context.Context, key string) (int64, error)
- func (f *Capacitor) GetMetric(ctx context.Context, key string) (Metric, error)
- func (f *Capacitor) GetMetrics() []Summary
- func (f *Capacitor) GetScan(ctx context.Context, key string, dest any) error
- func (f *Capacitor) GossipAddr() string
- func (f *Capacitor) HLLAdd(ctx context.Context, key string, elements ...string) (bool, error)
- func (f *Capacitor) HLLCount(ctx context.Context, key string) (int64, error)
- func (f *Capacitor) Increment(ctx context.Context, key string) (int64, error)
- func (f *Capacitor) IncrementBy(ctx context.Context, key string, delta int64) (int64, error)
- func (f *Capacitor) IncrementMetric(ctx context.Context, key string, delta float64) (Metric, error)
- func (f *Capacitor) IncrementMetricParallel(ctx context.Context, keys map[string]float64) (map[string]Metric, error)
- func (f *Capacitor) IncrementParallel(ctx context.Context, keys []string) (map[string]int64, error)
- func (f *Capacitor) IncrementSlidingWindow(ctx context.Context, key string, window time.Duration) (int64, error)
- func (f *Capacitor) ListLeftPopScan(ctx context.Context, key string, destPtr any) (bool, error)
- func (f *Capacitor) ListLeftPush(ctx context.Context, key string, value any) error
- func (f *Capacitor) ListLen(ctx context.Context, key string) (int, error)
- func (f *Capacitor) ListRangeScan(ctx context.Context, key string, start, stop int, destSlicePtr any) error
- func (f *Capacitor) ListRightPopScan(ctx context.Context, key string, destPtr any) (bool, error)
- func (f *Capacitor) ListRightPush(ctx context.Context, key string, value any) error
- func (f *Capacitor) MapExists(ctx context.Context, key, field string) (bool, error)
- func (f *Capacitor) MapGetAll(ctx context.Context, key string) (map[string]string, error)
- func (f *Capacitor) MapGetAllScan(ctx context.Context, key string, destStructPtr any) (bool, error)
- func (f *Capacitor) MapGetExpiry(ctx context.Context, key, field string) (int64, bool, error)
- func (f *Capacitor) MapGetMScan(ctx context.Context, key string, fieldDestMap map[string]any) (int, error)
- func (f *Capacitor) MapGetScan(ctx context.Context, key, field string, destPtr any) (bool, error)
- func (f *Capacitor) MapGetTTL(ctx context.Context, key, field string) (time.Duration, bool, error)
- func (f *Capacitor) MapIncrementBy(ctx context.Context, key, field string, delta float64) (float64, error)
- func (f *Capacitor) MapKeysScan(ctx context.Context, key string, destSlicePtr any) error
- func (f *Capacitor) MapLen(ctx context.Context, key string) (int, error)
- func (f *Capacitor) MapRemove(ctx context.Context, key, field string) (bool, error)
- func (f *Capacitor) MapRemoveExpiry(ctx context.Context, key, field string) (bool, error)
- func (f *Capacitor) MapRemoveTTL(ctx context.Context, key, field string) (bool, error)
- func (f *Capacitor) MapSet(ctx context.Context, key, field string, value any, ttl time.Duration) (bool, error)
- func (f *Capacitor) MapSetExpiry(ctx context.Context, key, field string, expireTimeMs int64) (bool, error)
- func (f *Capacitor) MapSetTTL(ctx context.Context, key, field string, ttl time.Duration) (bool, error)
- func (f *Capacitor) MapValuesScan(ctx context.Context, key string, destSlicePtr any) error
- func (f *Capacitor) NMapExists(ctx context.Context, key, field string) (bool, error)
- func (f *Capacitor) NMapGetAll(ctx context.Context, key string) (map[string]any, error)
- func (f *Capacitor) NMapGetAllScan(ctx context.Context, key string, destStructPtr any) (bool, error)
- func (f *Capacitor) NMapGetExpiry(ctx context.Context, key, field string) (int64, bool, error)
- func (f *Capacitor) NMapGetMScan(ctx context.Context, key string, fieldDestMap map[string]any) (int, error)
- func (f *Capacitor) NMapGetScan(ctx context.Context, key, field string, destPtr any) (bool, error)
- func (f *Capacitor) NMapGetTTL(ctx context.Context, key, field string) (time.Duration, bool, error)
- func (f *Capacitor) NMapIncrementBy(ctx context.Context, key, field string, delta float64) (float64, error)
- func (f *Capacitor) NMapKeysScan(ctx context.Context, key string, destSlicePtr any) error
- func (f *Capacitor) NMapLen(ctx context.Context, key string) (int, error)
- func (f *Capacitor) NMapRemove(ctx context.Context, key, field string) (bool, error)
- func (f *Capacitor) NMapRemoveExpiry(ctx context.Context, key, field string) (bool, error)
- func (f *Capacitor) NMapRemoveTTL(ctx context.Context, key, field string) (bool, error)
- func (f *Capacitor) NMapSet(ctx context.Context, key, field string, value any, ttl time.Duration) (bool, error)
- func (f *Capacitor) NMapSetExpiry(ctx context.Context, key, field string, expireTimeMs int64) (bool, error)
- func (f *Capacitor) NMapSetTTL(ctx context.Context, key, field string, ttl time.Duration) (bool, error)
- func (f *Capacitor) NMapValuesScan(ctx context.Context, key string, destSlicePtr any) error
- func (f *Capacitor) Publish(ctx context.Context, topic string, message any) error
- func (f *Capacitor) Set(ctx context.Context, key string, value any, ttl time.Duration) error
- func (f *Capacitor) SetAdd(ctx context.Context, key string, member any) (bool, error)
- func (f *Capacitor) SetCard(ctx context.Context, key string) (int64, error)
- func (f *Capacitor) SetIsMember(ctx context.Context, key string, member any) (bool, error)
- func (f *Capacitor) SetMIsMember(ctx context.Context, key string, members ...any) ([]bool, error)
- func (f *Capacitor) SetMembers(ctx context.Context, key string) ([]string, error)
- func (f *Capacitor) SetMembersScan(ctx context.Context, key string, destSlicePtr any) error
- func (f *Capacitor) SetMove(ctx context.Context, source string, destination string, member any) (bool, error)
- func (f *Capacitor) SetPop(ctx context.Context, key string) (string, error)
- func (f *Capacitor) SetPopScan(ctx context.Context, key string, dest any) (bool, error)
- func (f *Capacitor) SetRandMember(ctx context.Context, key string) (string, error)
- func (f *Capacitor) SetRandMemberScan(ctx context.Context, key string, dest any) (bool, error)
- func (f *Capacitor) SetRemove(ctx context.Context, key string, member any) (bool, error)
- func (f *Capacitor) SortedSetAdd(ctx context.Context, key string, score float64, member any) (bool, error)
- func (f *Capacitor) SortedSetCard(ctx context.Context, key string) (int64, error)
- func (f *Capacitor) SortedSetCount(ctx context.Context, key string, min, max float64) (int64, error)
- func (f *Capacitor) SortedSetIncrementBy(ctx context.Context, key string, member any, delta float64) (float64, error)
- func (f *Capacitor) SortedSetPopScan(ctx context.Context, key string, dest any, outScore *float64) (bool, error)
- func (f *Capacitor) SortedSetRangeByScoreScan(ctx context.Context, key string, min, max float64, destSlicePtr any, ...) error
- func (f *Capacitor) SortedSetRangeScan(ctx context.Context, key string, start, stop int64, destSlicePtr any, ...) error
- func (f *Capacitor) SortedSetRank(ctx context.Context, key string, member any) (int64, error)
- func (f *Capacitor) SortedSetRemove(ctx context.Context, key string, member any) (bool, error)
- func (f *Capacitor) SortedSetRevRangeByScoreScan(ctx context.Context, key string, max, min float64, destSlicePtr any, ...) error
- func (f *Capacitor) SortedSetRevRangeScan(ctx context.Context, key string, start, stop int64, destSlicePtr any, ...) error
- func (f *Capacitor) SortedSetScore(ctx context.Context, key string, member any) (float64, bool, error)
- func (f *Capacitor) Subscribe(ctx context.Context, topic string) (*Subscription, error)
- type Config
- type DeltaLog
- type HLC
- type HLLData
- type HLLPayload
- type Handshake
- type ListElement
- type ListPayload
- type LogEntry
- type Logger
- type MapField
- type MapPayload
- type Message
- func (z *Message) DecodeMsg(dc *msgp.Reader) (err error)
- func (m *Message) Encode() ([]byte, error)
- func (z *Message) EncodeMsg(en *msgp.Writer) (err error)
- func (z *Message) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Message) Msgsize() (s int)
- func (z *Message) UnmarshalMsg(bts []byte) (o []byte, err error)
- type Metric
- type MetricsTracker
- type MsgType
- type NMapField
- type NMapPayload
- type PubSubMessage
- type PubSubPayload
- type SetElement
- type SortedSetElement
- type Stat
- type StreamClient
- type StreamServer
- type Subscription
- type Summary
- type Timestamp
- func (t Timestamp) After(other Timestamp) bool
- func (z *Timestamp) DecodeMsg(dc *msgp.Reader) (err error)
- func (z Timestamp) EncodeMsg(en *msgp.Writer) (err error)
- func (t Timestamp) GreaterOrEqual(other Timestamp) bool
- func (z Timestamp) MarshalMsg(b []byte) (o []byte, err error)
- func (z Timestamp) Msgsize() (s int)
- func (t Timestamp) String() string
- func (z *Timestamp) UnmarshalMsg(bts []byte) (o []byte, err error)
Constants ¶
const DefaultMaxOffset = 500 * time.Millisecond
const NoExpiry = time.Duration(-1)
const Version = "0.26.8"
Version is the current version of the capacitor library.
Variables ¶
var ErrClockSmash = errors.New("HLC clock smash detected")
var ErrKeyNotFound = errors.New("capacitor: key not found")
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch struct {
FromNode string `json:"f" msg:"f"`
Entries [][]byte `json:"e" msg:"e"`
Handshake *Handshake `json:"h,omitempty" msg:"h,omitempty"`
}
func (*Batch) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type BloomPayload ¶ added in v0.12.0
type BloomPayload struct {
Indices []uint32 `msgpack:"i"`
}
type CMSPayload ¶ added in v0.12.0
type Capacitor ¶
type Capacitor struct {
// contains filtered or unexported fields
}
Capacitor represents an active-active, local-first replicated caching node. It manages local key-value storage, cluster membership discovery, logical clocks, and replication orchestration.
func New ¶
New initializes, configures, and starts a local Capacitor node. This constructs the storage, starts the replication stream listener, and registers the node with the gossip cluster.
func (*Capacitor) BloomExists ¶ added in v0.12.0
BloomExists checks if the element is likely present in the Bloom Filter.
func (*Capacitor) CMSIncrement ¶ added in v0.12.0
func (f *Capacitor) CMSIncrement(ctx context.Context, key string, element string, count int64) error
CMSIncrement increments the count of an element in the Count-Min Sketch grid.
func (*Capacitor) CMSQuery ¶ added in v0.12.0
CMSQuery returns the estimated frequency of the element in the Count-Min Sketch grid.
func (*Capacitor) Close ¶
Close gracefully shuts down the node, leaving the SWIM gossip group, shutting down active replication streams, and closing local storage engines.
func (*Capacitor) Delete ¶ added in v0.5.0
Delete removes a key-value pair from the local store and replicates the deletion tombstone to the cluster.
func (*Capacitor) Exists ¶ added in v0.4.0
Exists checks if a key exists in the cache and has not expired.
func (*Capacitor) Get ¶
Get retrieves a key-value pair's serialized value from the local cache database. Returns an empty string and nil error if the key is not found or has expired.
func (*Capacitor) GetCount ¶
GetCount retrieves the converged aggregate sum of a distributed counter across all nodes.
func (*Capacitor) GetMetric ¶
GetMetric retrieves the aggregated Metric details (count, sum, average) for the specified key.
func (*Capacitor) GetMetrics ¶
GetMetrics returns a snapshot summary of all built-in metrics (latencies, counts).
func (*Capacitor) GetScan ¶ added in v0.3.0
GetScan retrieves a key's value and unmarshals it into the destination pointer dest (similar to json.Unmarshal or database rows.Scan).
func (*Capacitor) GossipAddr ¶ added in v0.24.8
GossipAddr returns the actual local address and port bound by the gossip layer.
func (*Capacitor) HLLAdd ¶ added in v0.12.0
HLLAdd adds one or more elements to the HyperLogLog cardinality estimator.
func (*Capacitor) HLLCount ¶ added in v0.12.0
HLLCount returns the estimated cardinality of the HyperLogLog structure.
func (*Capacitor) IncrementBy ¶
IncrementBy increments a distributed PN-Counter key by the specified delta. It tracks counts per-node to construct CRDT conflict-free convergence.
func (*Capacitor) IncrementMetric ¶
IncrementMetric records a floating-point update to a distributed aggregate metric (tracking both hit frequency and aggregated sums).
func (*Capacitor) IncrementMetricParallel ¶
func (f *Capacitor) IncrementMetricParallel(ctx context.Context, keys map[string]float64) (map[string]Metric, error)
IncrementMetricParallel updates multiple aggregate metrics concurrently.
func (*Capacitor) IncrementParallel ¶
IncrementParallel performs concurrent increment calls for multiple counter keys.
func (*Capacitor) IncrementSlidingWindow ¶
func (f *Capacitor) IncrementSlidingWindow(ctx context.Context, key string, window time.Duration) (int64, error)
IncrementSlidingWindow appends an event timestamp for rate limiting or hit tracking, and returns the count of active occurrences within the rolling window duration.
func (*Capacitor) ListLeftPopScan ¶ added in v0.11.0
ListLeftPopScan pops and returns the first element from the head of the list, unmarshaling it into destPtr.
func (*Capacitor) ListLeftPush ¶ added in v0.11.0
ListLeftPush prepends a value to the list.
func (*Capacitor) ListRangeScan ¶ added in v0.11.0
func (f *Capacitor) ListRangeScan(ctx context.Context, key string, start, stop int, destSlicePtr any) error
ListRangeScan retrieves a sub-range of elements and unmarshals them into destSlicePtr.
func (*Capacitor) ListRightPopScan ¶ added in v0.11.0
ListRightPopScan pops and returns the last element from the tail of the list, unmarshaling it into destPtr.
func (*Capacitor) ListRightPush ¶ added in v0.11.0
ListRightPush appends a value to the list.
func (*Capacitor) MapExists ¶ added in v0.9.0
MapExists returns true if a field exists and is active in a Map.
func (*Capacitor) MapGetAll ¶ added in v0.9.0
MapGetAll returns a copy of the raw map containing all non-expired fields as string values.
func (*Capacitor) MapGetAllScan ¶ added in v0.9.0
MapGetAllScan retrieves all active fields of a Map and unmarshals them into destStructPtr using `map` tags. Returns true if the map exists and contains active fields, false otherwise.
func (*Capacitor) MapGetExpiry ¶ added in v0.9.0
MapGetExpiry retrieves the expiry Unix timestamp in milliseconds of a field.
func (*Capacitor) MapGetMScan ¶ added in v0.9.0
func (f *Capacitor) MapGetMScan(ctx context.Context, key string, fieldDestMap map[string]any) (int, error)
MapGetMScan retrieves multiple fields and unmarshals them into pointers mapped in fieldDestMap. Returns the number of successfully scanned fields.
func (*Capacitor) MapGetScan ¶ added in v0.9.0
MapGetScan retrieves a field's value and unmarshals it into destPtr. Returns true if found and scanned, false if the field does not exist or expired.
func (*Capacitor) MapGetTTL ¶ added in v0.9.0
MapGetTTL retrieves the remaining TTL duration of a field.
func (*Capacitor) MapIncrementBy ¶ added in v0.9.0
func (f *Capacitor) MapIncrementBy(ctx context.Context, key, field string, delta float64) (float64, error)
MapIncrementBy increments a numeric field by a delta. Returns the final score.
func (*Capacitor) MapKeysScan ¶ added in v0.9.0
MapKeysScan unmarshals all active field keys of a Map into destSlicePtr.
func (*Capacitor) MapRemoveExpiry ¶ added in v0.9.0
MapRemoveExpiry is an alias to MapRemoveTTL.
func (*Capacitor) MapRemoveTTL ¶ added in v0.9.0
MapRemoveTTL removes the TTL of a field, converting it to persistent.
func (*Capacitor) MapSet ¶ added in v0.9.0
func (f *Capacitor) MapSet(ctx context.Context, key, field string, value any, ttl time.Duration) (bool, error)
MapSet sets a field in a map to a primitive value with an optional TTL. Returns true if the field is newly created, false if updated.
func (*Capacitor) MapSetExpiry ¶ added in v0.9.0
func (f *Capacitor) MapSetExpiry(ctx context.Context, key, field string, expireTimeMs int64) (bool, error)
MapSetExpiry sets a field-level expiry timestamp in Unix milliseconds.
func (*Capacitor) MapSetTTL ¶ added in v0.9.0
func (f *Capacitor) MapSetTTL(ctx context.Context, key, field string, ttl time.Duration) (bool, error)
MapSetTTL sets a field-level TTL on a map.
func (*Capacitor) MapValuesScan ¶ added in v0.9.0
MapValuesScan unmarshals all active field values of a Map into destSlicePtr.
func (*Capacitor) NMapExists ¶ added in v0.10.0
NMapExists returns true if a field exists and is active in an NMap.
func (*Capacitor) NMapGetAll ¶ added in v0.10.0
NMapGetAll retrieves all active fields of an NMap as deserialized values.
func (*Capacitor) NMapGetAllScan ¶ added in v0.10.0
func (f *Capacitor) NMapGetAllScan(ctx context.Context, key string, destStructPtr any) (bool, error)
NMapGetAllScan retrieves all active fields of an NMap and unmarshals them into destStructPtr using `map` tags. Returns true if the map exists and contains active fields, false otherwise.
func (*Capacitor) NMapGetExpiry ¶ added in v0.10.0
NMapGetExpiry retrieves the expiry Unix timestamp in milliseconds of a field.
func (*Capacitor) NMapGetMScan ¶ added in v0.10.0
func (f *Capacitor) NMapGetMScan(ctx context.Context, key string, fieldDestMap map[string]any) (int, error)
NMapGetMScan retrieves multiple fields and unmarshals them into pointers mapped in fieldDestMap. Returns the number of successfully scanned fields.
func (*Capacitor) NMapGetScan ¶ added in v0.10.0
NMapGetScan retrieves a field's value (primitive or nested structure) and unmarshals it into destPtr. Returns true if found and scanned, false if the field does not exist or expired.
func (*Capacitor) NMapGetTTL ¶ added in v0.10.0
NMapGetTTL retrieves the remaining TTL duration of a field.
func (*Capacitor) NMapIncrementBy ¶ added in v0.10.0
func (f *Capacitor) NMapIncrementBy(ctx context.Context, key, field string, delta float64) (float64, error)
NMapIncrementBy increments a numeric field by a delta. Returns the final score.
func (*Capacitor) NMapKeysScan ¶ added in v0.10.0
NMapKeysScan unmarshals all active field keys of an NMap into destSlicePtr.
func (*Capacitor) NMapRemove ¶ added in v0.10.0
NMapRemove deletes a field from an NMap.
func (*Capacitor) NMapRemoveExpiry ¶ added in v0.10.0
NMapRemoveExpiry is an alias to NMapRemoveTTL.
func (*Capacitor) NMapRemoveTTL ¶ added in v0.10.0
NMapRemoveTTL removes the TTL of a field, converting it to persistent.
func (*Capacitor) NMapSet ¶ added in v0.10.0
func (f *Capacitor) NMapSet(ctx context.Context, key, field string, value any, ttl time.Duration) (bool, error)
NMapSet sets a field in a nested map to any value (nested map/struct/slice/primitive) with an optional TTL. Returns true if the field is newly created, false if updated.
func (*Capacitor) NMapSetExpiry ¶ added in v0.10.0
func (f *Capacitor) NMapSetExpiry(ctx context.Context, key, field string, expireTimeMs int64) (bool, error)
NMapSetExpiry sets a field-level expiry timestamp in Unix milliseconds.
func (*Capacitor) NMapSetTTL ¶ added in v0.10.0
func (f *Capacitor) NMapSetTTL(ctx context.Context, key, field string, ttl time.Duration) (bool, error)
NMapSetTTL sets a field-level TTL on an NMap.
func (*Capacitor) NMapValuesScan ¶ added in v0.10.0
NMapValuesScan unmarshals all active field values of an NMap into destSlicePtr.
func (*Capacitor) Publish ¶ added in v0.13.0
Publish distributes a message payload to all subscribers of a topic across the cluster.
func (*Capacitor) Set ¶
Set writes a key-value pair to the local store and appends it to the replication log to propagate it to other nodes in the cluster. If a positive TTL is specified, the key-value pair will automatically expire.
func (*Capacitor) SetAdd ¶ added in v0.6.0
SetAdd adds a member to a distributed replicated set. The member can be of any comparable or serializable type (e.g. string, int, struct).
func (*Capacitor) SetCard ¶ added in v0.6.0
SetCard returns the cardinality (number of active members) of the set.
func (*Capacitor) SetIsMember ¶ added in v0.6.0
SetIsMember checks if a member is currently present in the set.
func (*Capacitor) SetMIsMember ¶ added in v0.6.0
SetMIsMember checks membership for multiple members in a single call.
func (*Capacitor) SetMembers ¶ added in v0.6.0
SetMembers returns all active members in the set as strings (or serialized representations).
func (*Capacitor) SetMembersScan ¶ added in v0.6.0
SetMembersScan unmarshals all active members in the set into the slice pointed to by destSlicePtr.
func (*Capacitor) SetMove ¶ added in v0.6.0
func (f *Capacitor) SetMove(ctx context.Context, source string, destination string, member any) (bool, error)
SetMove moves a member from a source set to a destination set.
func (*Capacitor) SetPop ¶ added in v0.6.0
SetPop removes and returns a random member from the set as a string.
func (*Capacitor) SetPopScan ¶ added in v0.6.0
SetPopScan removes a random member from the set and unmarshals it into dest. Returns true if a member was popped, false if the set was empty.
func (*Capacitor) SetRandMember ¶ added in v0.6.0
SetRandMember returns a random member from the set as a string.
func (*Capacitor) SetRandMemberScan ¶ added in v0.6.0
SetRandMemberScan retrieves a random member from the set and unmarshals it into dest. Returns true if a member was found, false if the set was empty.
func (*Capacitor) SetRemove ¶ added in v0.6.0
SetRemove removes a member from a distributed replicated set.
func (*Capacitor) SortedSetAdd ¶ added in v0.7.0
func (f *Capacitor) SortedSetAdd(ctx context.Context, key string, score float64, member any) (bool, error)
SortedSetAdd adds a member with a score to a sorted set, or updates its score. Returns true if the member is newly added to the set, or false if its score was updated.
func (*Capacitor) SortedSetCard ¶ added in v0.7.0
SortedSetCard returns the cardinality (number of active members) of a sorted set.
func (*Capacitor) SortedSetCount ¶ added in v0.7.0
func (f *Capacitor) SortedSetCount(ctx context.Context, key string, min, max float64) (int64, error)
SortedSetCount returns the number of members with a score in [min, max].
func (*Capacitor) SortedSetIncrementBy ¶ added in v0.7.0
func (f *Capacitor) SortedSetIncrementBy(ctx context.Context, key string, member any, delta float64) (float64, error)
SortedSetIncrementBy increments the score of a member by a delta. Returns the new score of the member.
func (*Capacitor) SortedSetPopScan ¶ added in v0.7.0
func (f *Capacitor) SortedSetPopScan(ctx context.Context, key string, dest any, outScore *float64) (bool, error)
SortedSetPopScan removes a random member from the sorted set and unmarshals it into dest. Returns true if a member was popped and its score is returned, false if the set was empty.
func (*Capacitor) SortedSetRangeByScoreScan ¶ added in v0.7.0
func (f *Capacitor) SortedSetRangeByScoreScan(ctx context.Context, key string, min, max float64, destSlicePtr any, destScoresPtr *[]float64) error
SortedSetRangeByScoreScan unmarshals a range of members (by score range min to max) into destSlicePtr. It also optionally populates destScoresPtr if not nil.
func (*Capacitor) SortedSetRangeScan ¶ added in v0.7.0
func (f *Capacitor) SortedSetRangeScan(ctx context.Context, key string, start, stop int64, destSlicePtr any, destScoresPtr *[]float64) error
SortedSetRangeScan unmarshals a range of members (by rank index start to stop) into destSlicePtr. It also optionally populates destScoresPtr if not nil.
func (*Capacitor) SortedSetRank ¶ added in v0.7.0
SortedSetRank returns the 0-based rank of a member (ordered ascending by score). Returns -1 if the member is not present in the set.
func (*Capacitor) SortedSetRemove ¶ added in v0.7.0
SortedSetRemove removes a member from a sorted set. Returns true if the member was present and removed, or false if it was not in the set.
func (*Capacitor) SortedSetRevRangeByScoreScan ¶ added in v0.8.0
func (f *Capacitor) SortedSetRevRangeByScoreScan(ctx context.Context, key string, max, min float64, destSlicePtr any, destScoresPtr *[]float64) error
SortedSetRevRangeByScoreScan unmarshals a range of members in reverse score order (max-to-min) into destSlicePtr. It also optionally populates destScoresPtr if not nil.
func (*Capacitor) SortedSetRevRangeScan ¶ added in v0.8.0
func (f *Capacitor) SortedSetRevRangeScan(ctx context.Context, key string, start, stop int64, destSlicePtr any, destScoresPtr *[]float64) error
SortedSetRevRangeScan unmarshals a range of members in reverse score order (high-to-low) into destSlicePtr. It also optionally populates destScoresPtr if not nil.
type Config ¶
type Config struct {
// NodeID is the unique identifier for this node in the cluster. If left empty,
// a hostname-based identifier will be generated automatically.
NodeID string
// BindAddr is the network address for the gossip memberlist to bind to.
BindAddr string
// BindPort is the port number utilized for gossip memberlist communications.
BindPort int
// StreamPort is the port number utilized for replication TCP streams.
StreamPort int
// AdvertiseAddr is the IP address advertised to other nodes for establishing
// replication TCP streams.
AdvertiseAddr string
// Peers is the initial list of bootstrap addresses ("IP:port") of active cluster nodes.
Peers []string
// DataPath is the local directory path where BadgerDB files are persistently stored.
DataPath string
// LogSize is the capacity (maximum number of entries) of the in-memory circular Delta Log.
LogSize uint64
// TLSConfig is the optional configuration used to secure node-to-node replication streams using mTLS.
TLSConfig *tls.Config
// AuthToken is a shared secret token used to authenticate gossip join requests and TCP streams.
AuthToken string
// Logger is the structured logging engine injected into the Capacitor instance.
Logger Logger
// DisableMetrics disables internal metrics latency tracking for maximum read/write performance.
DisableMetrics bool
}
Config defines the configuration parameters for a Capacitor node instance.
type DeltaLog ¶
type DeltaLog struct {
Overflows uint64 // Count of overflow capacity eviction events
// contains filtered or unexported fields
}
DeltaLog is an in-memory binary circular buffer of operations.
func NewDeltaLog ¶
func (*DeltaLog) GetEntriesRaw ¶
func (*DeltaLog) PutEntriesRaw ¶ added in v0.24.6
type HLC ¶
type HLC struct {
ClockSmashes uint64
// contains filtered or unexported fields
}
HLC (Hybrid Logical Clock) implements a causality-preserving clock.
func (*HLC) SetMaxOffset ¶
SetMaxOffset sets the maximum allowed clock drift.
type HLLPayload ¶ added in v0.12.0
type Handshake ¶
func (Handshake) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type ListElement ¶ added in v0.11.0
type ListPayload ¶ added in v0.11.0
type LogEntry ¶
type LogEntry struct {
Seq uint64 `json:"s" msg:"s"`
TS Timestamp `json:"t" msg:"t"`
BornAt int64 `json:"ba" msg:"ba"` // NEW: For end-to-end latency tracking
Op MsgType `json:"o" msg:"o"`
Key string `json:"k" msg:"k"`
NodeID string `json:"n,omitempty" msg:"n,omitempty"`
Value []byte `json:"v,omitempty" msg:"v,omitempty"`
Delta float64 `json:"d,omitempty" msg:"d,omitempty"`
TTL int64 `json:"ttl,omitempty" msg:"ttl,omitempty"`
}
LogEntry represents a single operation in the delta log.
func (*LogEntry) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Logger ¶
type Logger interface {
Debug(msg string, args ...any)
Info(msg string, args ...any)
Warn(msg string, args ...any)
Error(msg string, args ...any)
}
Logger is a generic structured logging interface.
type MapPayload ¶ added in v0.9.0
type Message ¶
type Message struct {
Type MsgType `msg:"t"`
Key string `msg:"k"`
Value []byte `msg:"v,omitempty"`
ValueObj any `msg:"-"` // Used for lazy serialization
Delta float64 `msg:"d,omitempty"`
TTL int64 `msg:"ttl,omitempty"` // Seconds
Timestamp int64 `msg:"ts"` // UnixNano for LWW
NodeID string `msg:"n"` // Source node
}
Message is the container for all gossip data.
func (*Message) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type MetricsTracker ¶
type MetricsTracker struct {
// Latencies
SetLat Stat
GetLat Stat
IncrLat Stat
ReplicateLat Stat // End-to-end (BornAt to Apply)
BadgerWriteLat Stat // BadgerDB write latency during flush
// Counters
ReplicationFailures uint64
PeerConnectFailures uint64
ActiveSubscriptions int64
// Memory (Peak)
PeakAlloc uint64
PeakHeapAlloc uint64
PeakSys uint64
// contains filtered or unexported fields
}
func NewMetricsTracker ¶
func NewMetricsTracker() *MetricsTracker
func (*MetricsTracker) GetSummary ¶
func (m *MetricsTracker) GetSummary() []Summary
func (*MetricsTracker) Stop ¶
func (m *MetricsTracker) Stop()
type MsgType ¶
type MsgType byte
MsgType defines the type of gossip message.
func (MsgType) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type NMapPayload ¶ added in v0.10.0
type PubSubMessage ¶ added in v0.13.0
func (*PubSubMessage) Scan ¶ added in v0.13.0
func (m *PubSubMessage) Scan(destPtr any) error
type PubSubPayload ¶ added in v0.13.0
type SetElement ¶ added in v0.6.0
type SortedSetElement ¶ added in v0.7.0
type StreamClient ¶
type StreamClient struct {
// contains filtered or unexported fields
}
func NewStreamClient ¶
func NewStreamClient(tlsConfig *tls.Config, authToken string, metrics *MetricsTracker) *StreamClient
func (*StreamClient) Close ¶
func (c *StreamClient) Close()
func (*StreamClient) CloseConn ¶
func (c *StreamClient) CloseConn(nodeID string)
type StreamServer ¶
type StreamServer struct {
// contains filtered or unexported fields
}
func NewStreamServer ¶
func (*StreamServer) Start ¶
func (s *StreamServer) Start()
func (*StreamServer) Stop ¶
func (s *StreamServer) Stop()
type Subscription ¶ added in v0.13.0
type Subscription struct {
Channel <-chan PubSubMessage
// contains filtered or unexported fields
}
func (*Subscription) Unsubscribe ¶ added in v0.13.0
func (s *Subscription) Unsubscribe()
type Timestamp ¶
func (Timestamp) GreaterOrEqual ¶
GreaterOrEqual returns true if this timestamp is logically greater than or equal to the other timestamp.
func (Timestamp) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler