38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package redisstate
|
|
|
|
import (
|
|
"encoding/base64"
|
|
)
|
|
|
|
const defaultPrefix = "notification:"
|
|
|
|
// Keyspace builds the Notification Service Redis keys retained after the
|
|
// Stage 5 PostgreSQL migration: only the route lease, the persisted stream
|
|
// offset, and the inbound intent stream key are managed here. Durable
|
|
// notification state lives in the `notification` PostgreSQL schema.
|
|
//
|
|
// Dynamic key segments are encoded with base64url so raw key structure
|
|
// does not depend on caller-provided characters.
|
|
type Keyspace struct{}
|
|
|
|
// RouteLease returns the temporary Redis key used to coordinate exclusive
|
|
// publication of one notification_route across replicas.
|
|
func (Keyspace) RouteLease(notificationID string, routeID string) string {
|
|
return defaultPrefix + "route_leases:" + encodeKeyComponent(notificationID) + ":" + encodeKeyComponent(routeID)
|
|
}
|
|
|
|
// StreamOffset returns the primary Redis key for one persisted intent-consumer
|
|
// offset.
|
|
func (Keyspace) StreamOffset(stream string) string {
|
|
return defaultPrefix + "stream_offsets:" + encodeKeyComponent(stream)
|
|
}
|
|
|
|
// Intents returns the frozen ingress Redis Stream key.
|
|
func (Keyspace) Intents() string {
|
|
return defaultPrefix + "intents"
|
|
}
|
|
|
|
func encodeKeyComponent(value string) string {
|
|
return base64.RawURLEncoding.EncodeToString([]byte(value))
|
|
}
|