Documentation
¶
Overview ¶
Package rdb serializes and deserializes values in Redis RDB wire form. It backs DUMP and RESTORE, whose payloads are RDB value bytes plus a short version and checksum footer, and it is the same codec a full snapshot file would reuse.
Index ¶
- Constants
- Variables
- func Marshal(v Value) ([]byte, error)
- func MarshalFile(snap Snapshot) ([]byte, error)
- func SortMembers(members []Member)
- type DBData
- type Entry
- type Field
- type Kind
- type Member
- type Snapshot
- type StreamConsumer
- type StreamData
- type StreamEntry
- type StreamGroup
- type StreamID
- type StreamPEL
- type Value
Constants ¶
const (
Version = 11
)
Version is the RDB payload version aki writes into the DUMP footer. Redis 7.x uses 11; we accept up to maxVersion on load so a payload from a slightly newer peer still restores.
Variables ¶
var ErrUnsupported = errors.New("rdb: unsupported value type")
ErrUnsupported means the payload used a type aki does not deserialize yet, such as a module value. RESTORE maps it to the generic bad-payload reply.
Functions ¶
func Marshal ¶
Marshal serializes v into a DUMP payload: the type byte and value bytes, then a 2-byte little-endian version, then an 8-byte little-endian CRC-64 over all the preceding bytes.
func MarshalFile ¶
MarshalFile serializes a snapshot to a complete RDB file: the REDIS header, the aux records, then each non-empty database as a selector, a resize hint, and its keys, then the EOF marker and the CRC-64 over everything before the checksum.
func SortMembers ¶
func SortMembers(members []Member)
SortMembers orders sorted-set members by score then member bytes, the order aki's stored body expects. RESTORE calls it before re-encoding a decoded set.
Types ¶
type Entry ¶
type Entry struct {
Key []byte
Value Value
ExpireMS int64 // -1 for no expiry
Idle uint32
HasIdle bool
Freq uint8
HasFreq bool
}
Entry is one key in a snapshot: its name, value, optional expiry, and the access metadata that seeds the LRU and LFU state on load.
type Snapshot ¶
type Snapshot struct {
DBs []DBData
Aux map[string]string // auxiliary header fields such as redis-ver
Functions []string // function library sources, one per library
}
Snapshot is a whole dataset across its databases, the unit SAVE writes and load reads.
func UnmarshalFile ¶
UnmarshalFile parses a complete RDB file into a snapshot. It checks the header magic and version, verifies the trailing CRC-64 unless it is zero, and reads the opcode stream until EOF.
type StreamConsumer ¶
StreamConsumer is one named reader in a group, with its seen and active times and the IDs it currently holds pending.
type StreamData ¶
type StreamData struct {
Entries []StreamEntry
LastMS uint64
LastSeq uint64
FirstMS uint64
FirstSeq uint64
MaxDelMS uint64
MaxDelSeq uint64
EntriesAdded uint64
Groups []StreamGroup
}
StreamData is the neutral carrier for a stream value between aki's keyspace and the RDB byte form, the stream counterpart of the List, Set, Hash and ZSet fields on Value.
type StreamEntry ¶
StreamEntry is one log entry: its ID and a flat field/value list where even indices are field names and odd indices are the matching values.
type StreamGroup ¶
type StreamGroup struct {
Name []byte
LastMS uint64
LastSeq uint64
EntriesRead uint64
PEL []StreamPEL
Consumers []StreamConsumer
}
StreamGroup is a consumer group: its name, last delivered ID, entries-read counter, the group PEL, and the consumers.
type StreamID ¶
StreamID is a 128-bit stream entry ID inside an RDB stream value: a millisecond timestamp and a sequence number.
type StreamPEL ¶
StreamPEL is one Pending Entries List record of a consumer group: an entry that was delivered to a consumer but not yet acknowledged.
type Value ¶
type Value struct {
Kind Kind
Str []byte
List [][]byte
Set [][]byte
Hash []Field
ZSet []Member
Stream *StreamData
}
Value is a decoded logical value, the bridge between aki's keyspace and the RDB byte form. The command layer fills the field matching Kind and hands it to Marshal, or reads it back from Unmarshal.