Documentation
¶
Overview ¶
Package extension provides application-level patterns built on Grove KV.
Index ¶
- type AtomicCounter
- func (c *AtomicCounter) Decrement(ctx context.Context, delta int64) (int64, error)
- func (c *AtomicCounter) Get(ctx context.Context) (int64, error)
- func (c *AtomicCounter) Increment(ctx context.Context, delta int64) (int64, error)
- func (c *AtomicCounter) Reset(ctx context.Context) error
- func (c *AtomicCounter) Set(ctx context.Context, value int64) error
- type Job
- type Leaderboard
- func (lb *Leaderboard) Add(ctx context.Context, member string, score float64) error
- func (lb *Leaderboard) Rank(ctx context.Context, member string) (int, error)
- func (lb *Leaderboard) Remove(ctx context.Context, member string) error
- func (lb *Leaderboard) Score(ctx context.Context, member string) (float64, error)
- func (lb *Leaderboard) Size(ctx context.Context) (int, error)
- func (lb *Leaderboard) TopN(ctx context.Context, n int) ([]LeaderboardEntry, error)
- type LeaderboardEntry
- type Lock
- type Queue
- type QueueOption
- type RateLimitResult
- type RateLimiter
- type SessionOption
- type SessionStore
- func (ss *SessionStore) Create(ctx context.Context, data any) (string, error)
- func (ss *SessionStore) Delete(ctx context.Context, id string) error
- func (ss *SessionStore) Exists(ctx context.Context, id string) (bool, error)
- func (ss *SessionStore) Get(ctx context.Context, id string, dest any) error
- func (ss *SessionStore) Touch(ctx context.Context, id string) error
- func (ss *SessionStore) Update(ctx context.Context, id string, data any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtomicCounter ¶
type AtomicCounter struct {
// contains filtered or unexported fields
}
AtomicCounter provides a distributed atomic counter backed by a KV store. Unlike the CRDT counter, this requires a consistent store (no eventual consistency).
func NewAtomicCounter ¶
func NewAtomicCounter(store *kv.Store, key string) *AtomicCounter
NewAtomicCounter creates a new atomic counter at the given key.
func (*AtomicCounter) Decrement ¶
Decrement subtracts delta from the counter and returns the new value.
func (*AtomicCounter) Get ¶
func (c *AtomicCounter) Get(ctx context.Context) (int64, error)
Get returns the current counter value.
type Job ¶
type Job struct {
ID string `json:"id"`
Payload any `json:"payload"`
EnqueuedAt time.Time `json:"enqueued_at"`
}
Job represents a job in the queue.
type Leaderboard ¶
type Leaderboard struct {
// contains filtered or unexported fields
}
Leaderboard provides a sorted leaderboard backed by a KV store. For Redis, this could be backed by ZSET natively via Unwrap. This generic implementation stores scores in a map.
func NewLeaderboard ¶
func NewLeaderboard(store *kv.Store, key string) *Leaderboard
NewLeaderboard creates a new leaderboard at the given key.
func (*Leaderboard) Remove ¶
func (lb *Leaderboard) Remove(ctx context.Context, member string) error
Remove removes a member from the leaderboard.
func (*Leaderboard) Size ¶
func (lb *Leaderboard) Size(ctx context.Context) (int, error)
Size returns the number of members in the leaderboard.
func (*Leaderboard) TopN ¶
func (lb *Leaderboard) TopN(ctx context.Context, n int) ([]LeaderboardEntry, error)
TopN returns the top N entries in descending order.
type LeaderboardEntry ¶
LeaderboardEntry represents a single entry in the leaderboard.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is a distributed lock backed by a KV store. It uses SetNX for locking and DELETE for unlocking.
func (*Lock) Acquire ¶
Acquire attempts to acquire the lock. Returns an error if the lock cannot be acquired.
func (*Lock) AcquireWithRetry ¶
func (l *Lock) AcquireWithRetry(ctx context.Context, retryInterval time.Duration, maxRetries int) error
AcquireWithRetry attempts to acquire the lock with retries.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue provides a simple distributed job queue backed by a KV store.
func NewQueue ¶
func NewQueue(store *kv.Store, prefix string, opts ...QueueOption) *Queue
NewQueue creates a new job queue.
type QueueOption ¶
type QueueOption func(*Queue)
QueueOption configures a Queue.
func WithVisibilityTimeout ¶
func WithVisibilityTimeout(d time.Duration) QueueOption
WithVisibilityTimeout sets the visibility timeout for dequeued jobs.
type RateLimitResult ¶
RateLimitResult contains the result of a rate limit check.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides distributed rate limiting backed by a KV store.
func NewRateLimiter ¶
NewRateLimiter creates a new rate limiter that allows `rate` requests per `window`.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(ctx context.Context, key string) (*RateLimitResult, error)
Allow checks if the request identified by key is within the rate limit. It uses a sliding window counter approach.
type SessionOption ¶
type SessionOption func(*SessionStore)
SessionOption configures a SessionStore.
func WithSessionPrefix ¶
func WithSessionPrefix(prefix string) SessionOption
WithSessionPrefix sets the key prefix for sessions.
func WithSessionTTL ¶
func WithSessionTTL(ttl time.Duration) SessionOption
WithSessionTTL sets the default session TTL.
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore provides HTTP session storage backed by a KV store.
func NewSessionStore ¶
func NewSessionStore(store *kv.Store, opts ...SessionOption) *SessionStore
NewSessionStore creates a new session store.
func (*SessionStore) Create ¶
Create creates a new session with the given data and returns the session ID.
func (*SessionStore) Delete ¶
func (ss *SessionStore) Delete(ctx context.Context, id string) error
Delete removes a session.