list

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const Type primitive.Type = "List"

Type is the list type

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides an API for creating Lists

type Event

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

	// Index is the index at which the event occurred
	Index int

	// Value is the value that was changed
	Value []byte
}

Event is a list change event

type EventType

type EventType string

EventType is the type for a list Event

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

	// EventInserted indicates a value was added to the list
	EventInserted EventType = "added"

	// EventRemoved indicates a value was removed from the list
	EventRemoved EventType = "removed"
)

type List

type List interface {
	primitive.Primitive

	// Append pushes a value on to the end of the list
	Append(ctx context.Context, value []byte) error

	// Insert inserts a value at the given index
	Insert(ctx context.Context, index int, value []byte) error

	// Set sets the value at the given index
	Set(ctx context.Context, index int, value []byte) error

	// Get gets the value at the given index
	Get(ctx context.Context, index int) ([]byte, error)

	// Remove removes and returns the value at the given index
	Remove(ctx context.Context, index int) ([]byte, error)

	// Len gets the length of the list
	Len(ctx context.Context) (int, error)

	// Slice returns a slice of the list from the given start index to the given end index
	Slice(ctx context.Context, from int, to int) (List, error)

	// SliceFrom returns a slice of the list from the given index
	SliceFrom(ctx context.Context, from int) (List, error)

	// SliceTo returns a slice of the list to the given index
	SliceTo(ctx context.Context, to int) (List, error)

	// Items iterates through the values in the list
	// This is a non-blocking method. If the method returns without error, values will be pushed on to the
	// given channel and the channel will be closed once all values have been read from the list.
	Items(ctx context.Context, ch chan<- []byte) error

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

	// Clear removes all values from the list
	Clear(ctx context.Context) error
}

List provides a distributed list data structure The list values are defines as strings. To store more complex types in the list, encode values to strings e.g. using base 64 encoding.

func New

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

New creates a new list primitive

type WatchOption

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

WatchOption is an option for list Watch calls

func WithReplay

func WithReplay() WatchOption

WithReplay returns a Watch option to replay entries

Jump to

Keyboard shortcuts

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