feat: use postgres

This commit is contained in:
Ilia Denisov
2026-04-26 20:34:39 +02:00
committed by GitHub
parent 48b0056b49
commit fe829285a6
365 changed files with 29223 additions and 24049 deletions
@@ -0,0 +1,40 @@
package redisstate
import (
"encoding/json"
"fmt"
"time"
)
// StreamOffset stores the persisted progress of one plain-XREAD consumer.
type StreamOffset struct {
// Stream stores the Redis Stream key the offset belongs to.
Stream string `json:"stream"`
// LastProcessedEntryID stores the most recently processed Stream entry id.
LastProcessedEntryID string `json:"last_processed_entry_id"`
// UpdatedAt stores when the offset was last persisted.
UpdatedAt time.Time `json:"updated_at"`
}
// MarshalStreamOffset returns the JSON encoding of the persisted offset.
func MarshalStreamOffset(offset StreamOffset) ([]byte, error) {
payload, err := json.Marshal(offset)
if err != nil {
return nil, fmt.Errorf("marshal stream offset: %w", err)
}
return payload, nil
}
// UnmarshalStreamOffset parses one persisted offset payload.
func UnmarshalStreamOffset(payload []byte) (StreamOffset, error) {
var offset StreamOffset
if err := json.Unmarshal(payload, &offset); err != nil {
return StreamOffset{}, fmt.Errorf("unmarshal stream offset: %w", err)
}
if offset.UpdatedAt.IsZero() {
return StreamOffset{}, fmt.Errorf("unmarshal stream offset: updated_at must not be zero")
}
return offset, nil
}