Documentation
¶
Overview ¶
Package redis is a history Store backed by Redis via go-redis.
Each conversation maps to a Redis list keyed by `<KeyPrefix><conversationID>` (default prefix `chat:history:`). Messages are RPUSH'd as canonical chat.Message JSON, so a LRANGE 0 -1 preserves list order. When TTL is configured, append and expiry refresh execute in one Redis transaction.
Example:
client := goredis.NewUniversalClient(&goredis.UniversalOptions{...})
store, _ := redis.NewStore(redis.StoreConfig{Client: client})
Index ¶
- Constants
- type Store
- func (s *Store) Clear(ctx context.Context, conversationID history.ConversationID) (err error)
- func (s *Store) Conversations(ctx context.Context) (ids []history.ConversationID, err error)
- func (s *Store) Read(ctx context.Context, conversationID history.ConversationID) (storedMessages []chat.Message, err error)
- func (s *Store) Write(ctx context.Context, conversationID history.ConversationID, ...) (err error)
- type StoreConfig
Constants ¶
const DefaultKeyPrefix = "chat:history:"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists each conversation as an ordered Redis list through a caller-owned client. It never closes the client; when TTL is configured, append and expiry refresh share one transaction so retention cannot lag a successful write.
func NewStore ¶
func NewStore(config StoreConfig) (*Store, error)
func (*Store) Clear ¶
Clear drops the entire list for conversationID. Unknown ids are silently ignored (DEL on a missing key is a no-op in Redis).
func (*Store) Conversations ¶
Conversations enumerates stored conversation IDs via SCAN and returns them in lexical order. SCAN may observe concurrent mutations and repeat keys, so results are de-duplicated.
type StoreConfig ¶
type StoreConfig struct {
// Client is the live go-redis client. Required. The store does
// not take ownership — callers Close() the client themselves.
Client goredis.UniversalClient
// KeyPrefix is prepended to every conversation id to namespace the
// keys. Optional: defaults to [DefaultKeyPrefix].
KeyPrefix string
// TTL, when non-zero, applies a millisecond-precision expiry to every
// conversation key and refreshes it on each Write. Zero means "never
// expire".
TTL time.Duration
}
func (StoreConfig) Validate ¶
func (s StoreConfig) Validate() error