Files
gemini-banlancer/internal/store/store.go
2025-11-20 12:24:05 +08:00

89 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package store
import (
"errors"
"time"
)
// ErrNotFound is returned when a key is not found in the store.
var ErrNotFound = errors.New("key not found")
// Message is the struct for received pub/sub messages.
type Message struct {
Channel string
Payload []byte
}
// Subscription represents an active subscription to a pub/sub channel.
type Subscription interface {
Channel() <-chan *Message
Close() error
}
// Pipeliner defines an interface for executing a batch of commands.
type Pipeliner interface {
// General
Del(keys ...string)
Expire(key string, expiration time.Duration)
// HASH
HSet(key string, values map[string]any)
HIncrBy(key, field string, incr int64)
// SET
SAdd(key string, members ...any)
SRem(key string, members ...any)
// LIST
LPush(key string, values ...any)
LRem(key string, count int64, value any)
// Execution
Exec() error
}
// Store is the master interface for our cache service.
type Store interface {
// Basic K/V operations
Set(key string, value []byte, ttl time.Duration) error
Get(key string) ([]byte, error)
Del(keys ...string) error
Exists(key string) (bool, error)
SetNX(key string, value []byte, ttl time.Duration) (bool, error)
// HASH operations
HSet(key string, values map[string]any) error
HGetAll(key string) (map[string]string, error)
HIncrBy(key, field string, incr int64) (int64, error)
HDel(key string, fields ...string) error // [新增]
// LIST operations
LPush(key string, values ...any) error
LRem(key string, count int64, value any) error
Rotate(key string) (string, error)
LIndex(key string, index int64) (string, error)
// SET operations
SAdd(key string, members ...any) error
SPopN(key string, count int64) ([]string, error)
SMembers(key string) ([]string, error)
SRem(key string, members ...any) error
SRandMember(key string) (string, error)
// Pub/Sub operations
Publish(channel string, message []byte) error
Subscribe(channel string) (Subscription, error)
// Pipeline (optional) - 我们在redis实现它内存版暂时不实现
Pipeline() Pipeliner
// Close closes the store and releases any underlying resources.
Close() error
// === 新增方法,支持轮询策略 ===
ZAdd(key string, members map[string]float64) error
ZRange(key string, start, stop int64) ([]string, error)
ZRem(key string, members ...any) error
PopAndCycleSetMember(mainKey, cooldownKey string) (string, error)
}