New
This commit is contained in:
88
internal/store/store.go
Normal file
88
internal/store/store.go
Normal file
@@ -0,0 +1,88 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user