store

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StringType string = "string"
	HashType          = "hash"
	ListType          = "list"
	SetType           = "set"
	ZSetType          = "zset"
)

string enum

Variables

View Source
var ErrIndexKeySerialization = errors.New("during index serialization key not found in index")
View Source
var ErrKeyNotFound = errors.New("key not found")
View Source
var ErrSecuringReaderPoolDrained = errors.New("pool is drained, no readers available")
View Source
var ErrSecuringReaderTimeout = errors.New("timeout securing reader (timed out getting one from the pool")
View Source
var ErrTimedOutDrainingPool = errors.New("timed out draining pool")

Functions

func MockJsonlBytes

func MockJsonlBytes(records []Record) []byte

func NewReadSeekCloser

func NewReadSeekCloser(readSeeker io.ReadSeeker) io.ReadSeekCloser

Types

type Config

type Config struct {
	MaxConnections      int
	DefaultTimeout      time.Duration
	DrainTimeout        time.Duration
	KeysDontNeedSorting bool
}

type CurrentFile

type CurrentFile struct {
	FileName      string `json:"filename"`
	IndexFileName string `json:"index_filename"`
}

type ErrCreatingPool

type ErrCreatingPool struct {
	Err error
}

func (*ErrCreatingPool) Error

func (e *ErrCreatingPool) Error() string

type ErrReadingIndex

type ErrReadingIndex struct {
	Err error
}

func (*ErrReadingIndex) Error

func (e *ErrReadingIndex) Error() string

type ErrReadingRecordFromDisk

type ErrReadingRecordFromDisk struct {
	Err error
}

func (ErrReadingRecordFromDisk) Error

func (e ErrReadingRecordFromDisk) Error() string

type HashRecord

type HashRecord struct {
	Fields map[string]string `json:"fields"`
}

func (*HashRecord) ScanFields

func (hr *HashRecord) ScanFields(cursor int, count int, pattern string) (fields []string, last int, err error)

type IndexRecord

type IndexRecord struct {
	Key    string `json:"key"`
	Offset int64  `json:"offset"`
	Len    int    `json:"len"`
	Type   string `json:"type"`
}

type ListRecord

type ListRecord struct {
	Elements []string `json:"elements"`
}

type MockReaderSeekCloser

type MockReaderSeekCloser struct {
	// contains filtered or unexported fields
}

func (*MockReaderSeekCloser) Close

func (*MockReaderSeekCloser) Close() error

func (*MockReaderSeekCloser) Read

func (m *MockReaderSeekCloser) Read(p []byte) (n int, err error)

func (*MockReaderSeekCloser) Seek

func (m *MockReaderSeekCloser) Seek(offset int64, whence int) (int64, error)

type OpenReaderSeekCloser

type OpenReaderSeekCloser func() (io.ReadSeekCloser, error)

type OrderedSetElement

type OrderedSetElement struct {
	Value string  `json:"value"`
	Score float64 `json:"score"`
}

type OrderedSetRecord

type OrderedSetRecord struct {
	Elements []OrderedSetElement `json:"elements"`
}

type ReaderPool

type ReaderPool struct {
	// contains filtered or unexported fields
}

ReaderPool is a NON-lazy pool of io.ReaderSeekCloser TODO: make it lazy later

func NewEmptyReaderPool

func NewEmptyReaderPool() *ReaderPool

Always timeouting EmptyReaderPool

func NewReaderPool

func NewReaderPool(openReaderSeekCloser OpenReaderSeekCloser) (readerPool *ReaderPool, err error)

func NewReaderPoolAdvanced

func NewReaderPoolAdvanced(openReaderSeekCloser OpenReaderSeekCloser,
	maxConnections int,
	defaultTimeout time.Duration,
	drainTimeout time.Duration) (readerPool *ReaderPool, err error)

func (*ReaderPool) Drain

func (p *ReaderPool) Drain() (err error)

func (*ReaderPool) DrainWithTimeout

func (p *ReaderPool) DrainWithTimeout(timeout time.Duration) (err error)

func (*ReaderPool) GetReader

func (p *ReaderPool) GetReader() (reader io.ReadSeekCloser, err error)

func (*ReaderPool) GetReaderWithTimeout

func (p *ReaderPool) GetReaderWithTimeout(timeout time.Duration) (reader io.ReadSeekCloser, err error)

func (*ReaderPool) ReturnReader

func (p *ReaderPool) ReturnReader(reader io.ReadSeekCloser)

type Record

type Record struct {
	Key  string `json:"key"`
	Type string `json:"type"`

	StringRecord    *StringRecord     `json:"string_record,omitempty"`
	HashRecord      *HashRecord       `json:"hash_record,omitempty"`
	ListRecord      *ListRecord       `json:"list_record,omitempty"`
	OrdderSetRecord *OrderedSetRecord `json:"ordered_set_record,omitempty"`
}

func MockRecords

func MockRecords() (records []Record)

func (*Record) String

func (r *Record) String() string

type Store

type Store struct {
	StoreIndex *StoreIndex
	// contains filtered or unexported fields
}

func NewEmptyStore

func NewEmptyStore() *Store

func NewStoreFromRecords

func NewStoreFromRecords(openReaderSeekCloser OpenReaderSeekCloser) (store *Store, err error)

func NewStoreFromRecordsWithConfig

func NewStoreFromRecordsWithConfig(openReaderSeekCloser OpenReaderSeekCloser, config Config) (store *Store, err error)

Opens a store w/o an index

func NewStoreFromRecordsWithIndex

func NewStoreFromRecordsWithIndex(openReaderSeekCloser OpenReaderSeekCloser, index io.Reader) (store *Store, err error)

func NewStoreFromRecordsWithIndexAndConfig

func NewStoreFromRecordsWithIndexAndConfig(openReaderSeekCloser OpenReaderSeekCloser, index io.Reader, config Config) (store *Store, err error)

func (*Store) GetLen

func (s *Store) GetLen() int

func (*Store) GetRecord

func (s *Store) GetRecord(key string) (record *Record, err error)

func (*Store) GetRecordIndex

func (s *Store) GetRecordIndex(key string) (*IndexRecord, error)

func (*Store) ScanFields

func (hr *Store) ScanFields(start int, count int, pattern string) (records []IndexRecord, cursor int, err error)

type StoreIndex

type StoreIndex struct {
	SortedKeys []string
	Index      map[string]IndexRecord
}

func BuildIndex

func BuildIndex(in io.Reader) (store *StoreIndex, err error)

This is an extremely simple implementation that assumes that newline is only one symbol long

func ReadJsonlIndex

func ReadJsonlIndex(in io.Reader, keysDontNeedSorting bool) (store *StoreIndex, err error)

func (*StoreIndex) WriteJsonl

func (s *StoreIndex) WriteJsonl(out io.Writer) (err error)

type StringRecord

type StringRecord struct {
	Value string `json:"value"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL