indexedmap

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Type primitive.Type = "IndexedMap"

Type is the indexedmap type

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// GetIndexedMap gets the IndexedMap instance of the given name
	GetIndexedMap(ctx context.Context, name string) (IndexedMap, error)
}

Client provides an API for creating IndexedMaps

type Entry

type Entry struct {
	// Index is the unique, monotonically increasing, globally unique index of the entry. The index is static
	// for the lifetime of a key.
	Index Index

	// Version is the unique, monotonically increasing version number for the key/value pair. The version is
	// suitable for use in optimistic locking.
	Version Version

	// Key is the key of the pair
	Key string

	// Value is the value of the pair
	Value []byte

	// Created is the time at which the key was created
	Created time.Time

	// Updated is the time at which the key was last updated
	Updated time.Time
}

Entry is an indexed key/value pair

func (Entry) String

func (kv Entry) String() string

type Event

type Event struct {
	// Type indicates the change event type
	Type EventType

	// Entry is the event entry
	Entry *Entry
}

Event is a map change event

type EventType

type EventType string

EventType is the type of a map event

const (
	// EventNone indicates the event is not a change event
	EventNone EventType = ""

	// EventInserted indicates a key was newly created in the map
	EventInserted EventType = "inserted"

	// EventUpdated indicates the value of an existing key was changed
	EventUpdated EventType = "updated"

	// EventRemoved indicates a key was removed from the map
	EventRemoved EventType = "removed"
)

type Filter

type Filter struct {
	Key   string
	Index Index
}

Filter is a watch filter configuration

type GetOption

type GetOption interface {
	// contains filtered or unexported methods
}

GetOption is an option for the Get method

func WithDefault

func WithDefault(def []byte) GetOption

WithDefault sets the default value to return if the key is not present

type Index

type Index uint64

Index is the index of an entry

type IndexedMap

type IndexedMap interface {
	primitive.Primitive

	// Append appends the given key/value to the map
	Append(ctx context.Context, key string, value []byte) (*Entry, error)

	// Put appends the given key/value to the map
	Put(ctx context.Context, key string, value []byte) (*Entry, error)

	// Set sets the given index in the map
	Set(ctx context.Context, index Index, key string, value []byte, opts ...SetOption) (*Entry, error)

	// Get gets the value of the given key
	Get(ctx context.Context, key string, opts ...GetOption) (*Entry, error)

	// GetIndex gets the entry at the given index
	GetIndex(ctx context.Context, index Index, opts ...GetOption) (*Entry, error)

	// FirstIndex gets the first index in the map
	FirstIndex(ctx context.Context) (Index, error)

	// LastIndex gets the last index in the map
	LastIndex(ctx context.Context) (Index, error)

	// PrevIndex gets the index before the given index
	PrevIndex(ctx context.Context, index Index) (Index, error)

	// NextIndex gets the index after the given index
	NextIndex(ctx context.Context, index Index) (Index, error)

	// FirstEntry gets the first entry in the map
	FirstEntry(ctx context.Context) (*Entry, error)

	// LastEntry gets the last entry in the map
	LastEntry(ctx context.Context) (*Entry, error)

	// PrevEntry gets the entry before the given index
	PrevEntry(ctx context.Context, index Index) (*Entry, error)

	// NextEntry gets the entry after the given index
	NextEntry(ctx context.Context, index Index) (*Entry, error)

	// Replace replaces the given key with the given value
	Replace(ctx context.Context, key string, value []byte, opts ...ReplaceOption) (*Entry, error)

	// ReplaceIndex replaces the given index with the given value
	ReplaceIndex(ctx context.Context, index Index, value []byte, opts ...ReplaceOption) (*Entry, error)

	// Remove removes a key from the map
	Remove(ctx context.Context, key string, opts ...RemoveOption) (*Entry, error)

	// RemoveIndex removes an index from the map
	RemoveIndex(ctx context.Context, index Index, opts ...RemoveOption) (*Entry, error)

	// Len returns the number of entries in the map
	Len(ctx context.Context) (int, error)

	// Clear removes all entries from the map
	Clear(ctx context.Context) error

	// Entries lists the entries in the map
	// This is a non-blocking method. If the method returns without error, key/value paids will be pushed on to the
	// given channel and the channel will be closed once all entries have been read from the map.
	Entries(ctx context.Context, ch chan<- *Entry) error

	// Watch watches the map for changes
	// This is a non-blocking method. If the method returns without error, map events will be pushed onto
	// the given channel in the order in which they occur.
	Watch(ctx context.Context, ch chan<- *Event, opts ...WatchOption) error
}

IndexedMap is a distributed linked map

func New

func New(ctx context.Context, name primitive.Name, partitions []*primitive.Session) (IndexedMap, error)

New creates a new IndexedMap primitive

type NotSetOption

type NotSetOption struct {
}

NotSetOption is a SetOption that sets the value only if it's not already set

type RemoveOption

type RemoveOption interface {
	// contains filtered or unexported methods
}

RemoveOption is an option for the Remove method

type ReplaceOption

type ReplaceOption interface {
	// contains filtered or unexported methods
}

ReplaceOption is an option for the Replace method

type SetOption

type SetOption interface {
	// contains filtered or unexported methods
}

SetOption is an option for the Put method

func IfNotSet

func IfNotSet() SetOption

IfNotSet sets the value if the entry is not yet set

type Version

type Version uint64

Version is the version of an entry

type VersionOption

type VersionOption struct {
	SetOption
	ReplaceOption
	RemoveOption
	// contains filtered or unexported fields
}

VersionOption is an implementation of SetOption and RemoveOption to specify the version for concurrency control

func IfVersion

func IfVersion(version Version) VersionOption

IfVersion sets the required version for optimistic concurrency control

type WatchOption

type WatchOption interface {
	// contains filtered or unexported methods
}

WatchOption is an option for the Watch method

func WithFilter

func WithFilter(filter Filter) WatchOption

WithFilter returns a watch option that filters the watch events

func WithReplay

func WithReplay() WatchOption

WithReplay returns a watch option that enables replay of watch events

Jump to

Keyboard shortcuts

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