Documentation ¶
Index ¶
- Constants
- func ReadFile(path string, handler FileHandler) error
- func ReadValue(key string, payload []byte, handler ValueHandler) error
- func VerifyFile(path string, opts VerifyFileOptions) error
- func VerifyValue(payload []byte, opts VerifyValueOptions) error
- func VerifyValueChecksum(payload []byte) error
- type FileHandler
- type ModuleMarker
- type Stream
- type StreamConsumer
- type StreamConsumerGroup
- type StreamEntry
- type StreamID
- type StreamPendingEntry
- type StreamWriter
- type Type
- type ValueHandler
- type VerifyFileOptions
- type VerifyValueOptions
- type Writer
- func (w *Writer) GetBuffer() []byte
- func (w *Writer) WriteChecksum(version uint16) error
- func (w *Writer) WriteHash(hash map[string]string) error
- func (w *Writer) WriteJSON(json string) error
- func (w *Writer) WriteList(list []string) error
- func (w *Writer) WriteSet(set []string) error
- func (w *Writer) WriteStream(stream *Stream) error
- func (w *Writer) WriteString(str string) error
- func (w *Writer) WriteType(objType Type) error
- func (w *Writer) WriteZset(elements []string, scores []float64) error
Constants ¶
const ValueChecksumSize = 10
Size of the checksum block. 2 (RDB version) + 8 (CRC-64) bytes in total.
const Version uint16 = 11
Variables ¶
This section is empty.
Functions ¶
func ReadFile ¶
func ReadFile(path string, handler FileHandler) error
ReadFile reads the RDB file in the given path, and calls the appropriate methods of the handler for the objects read. It also allows partial read of the file which means the function will skip some parts of the file, which is not compatible with Upstash yet. These parts include function data, multiple databases(any database other than 0), and unsupported modules.
func ReadValue ¶
func ReadValue(key string, payload []byte, handler ValueHandler) error
ReadValue reads the single RDB value given in the payload into the handler. The given key is passed into the handler methods directly.
func VerifyFile ¶
func VerifyFile(path string, opts VerifyFileOptions) error
VerifyFile verifies that the given RDB file is not corrupt, or does not exceed the limits in the given options.
func VerifyValue ¶
func VerifyValue(payload []byte, opts VerifyValueOptions) error
VerifyValue verifies that the given RDB value is not corrupt, or does not exceed the limits in the given options.
func VerifyValueChecksum ¶
VerifyValueChecksum uses the checksum block at the end of the payload(last 10 bytes) to verify that the CRC64 of the payload matches with the CRC value encoded at the last 8 bytes of the payload. It also verifies that the RDB version encoded in the checksum block is less than or equal to the RDB version supported by Upstash.
Types ¶
type FileHandler ¶
type FileHandler interface { ValueHandler HandleExpireTime(key string, expireTime time.Duration) }
FileHandler is an extension of ValueHandler, which can handle RDB objects and their expiration information from RDB files.
type ModuleMarker ¶
type ModuleMarker string
const ( EmptyModuleMarker ModuleMarker = "" JSONModuleMarker ModuleMarker = "json" )
type Stream ¶
type Stream struct { LastID StreamID Entries []StreamEntry Length uint64 Groups []StreamConsumerGroup }
type StreamConsumer ¶
type StreamConsumer struct { Name string SeenTime int64 ActiveTime int64 PendingEntries []*StreamPendingEntry }
type StreamConsumerGroup ¶
type StreamConsumerGroup struct { Name string LastID StreamID EntriesRead int64 Consumers []StreamConsumer }
type StreamEntry ¶
type StreamPendingEntry ¶
type StreamPendingEntry struct { Entry StreamEntry DeliveryTime int64 DeliveryCount uint64 }
type StreamWriter ¶
type StreamWriter struct {
// contains filtered or unexported fields
}
func (*StreamWriter) WriteConsumerGroups ¶
func (sw *StreamWriter) WriteConsumerGroups(groups []StreamConsumerGroup) error
func (*StreamWriter) WriteEntries ¶
func (sw *StreamWriter) WriteEntries(entries []StreamEntry) error
Instead of delta encoding entries, we write each entry as a seperate listpack, to make the implementation simpler.
func (*StreamWriter) WriteMetadata ¶
func (sw *StreamWriter) WriteMetadata(length uint64, lastID StreamID) error
type Type ¶
type Type uint8
const ( TypeString Type = 0 TypeList Type = 1 TypeSet Type = 2 TypeZset Type = 3 TypeHash Type = 4 TypeZset2 Type = 5 TypeModule2 Type = 7 // module pre ga with type 6 is not supported TypeHashZipmap Type = 9 // type 8 seems unused by Redis TypeListZiplist Type = 10 TypeSetIntset Type = 11 TypeZsetZiplist Type = 12 TypeHashZiplist Type = 13 TypeListQuicklist Type = 14 TypeStreamListpacks Type = 15 TypeHashListpack Type = 16 TypeZsetListpack Type = 17 TypeListQuicklist2 Type = 18 TypeStreamListpacks2 Type = 19 TypeSetListpack Type = 20 TypeStreamListpacks3 Type = 21 )
type ValueHandler ¶
type ValueHandler interface { // whether the handler can skip known but not yet supported types or not. AllowPartialRead() bool // called when a string value is read for the key. HandleString(key, value string) error // returned function is called for the each enty read for the key. ListEntryHandler(key string) func(elem string) error // called when the list is read completely, with the name and the number of entries read. HandleListEnding(key string, entriesRead uint64) // returned function is called for the each enty read for the key. SetEntryHandler(key string) func(elem string) error // returned function is called for the each enty read for the key. ZsetEntryHandler(key string) func(elem string, score float64) error // called when the zset is read completely, with the name and the number of entries read. HandleZsetEnding(key string, entriesRead uint64) // returned function is called for the each enty read for the key. HashEntryHandler(key string) func(field, value string) error // called when a module value is read for the key. HandleModule(key, value string, marker ModuleMarker) error // returned function is called for the each stream enty read for the key. StreamEntryHandler(key string) func(entry StreamEntry) error // returned function is called for the each stream group read for the key. StreamGroupHandler(key string) func(group StreamConsumerGroup) error // called when the stream entries and groups are read completely, // with the name and the number of entries read. HandleStreamEnding(key string, entriesRead uint64) }
ValueHandler is used to handle RDB objects while reading a file.
type VerifyFileOptions ¶
type VerifyValueOptions ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
func (*Writer) WriteChecksum ¶
WriteChecksum writes the given RDB version and the CRC64 for the payload.
func (*Writer) WriteJSON ¶
WriteJSON writes the JSON string as the ObjectTypeModule2, with the JSON module type with version 3.
func (*Writer) WriteStream ¶
WriteStream writes the stream as the ObjectTypeStreamListpacks.
func (*Writer) WriteString ¶
WriteString writes the given string as the ObjectTypeString.