deks

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

README

Deks

Deks is a Distributed Embedded Key-value Store. It comes with a simple interface and a lazy distribution algorithm.

Documentation

Index

Constants

View Source
const ItemSize = keyHashSize + 8

ItemSize specifies the item size.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn implements a client connection based on the redis protocol.

func Dial

func Dial(url string) (*Conn, error)

Dial establishes a connection to the server at the provided url.

func (*Conn) Close

func (c *Conn) Close() error

Close tears down the connection.

func (*Conn) Delete

func (c *Conn) Delete(key []byte) error

Delete removes the value at the provided key.

func (*Conn) Get

func (c *Conn) Get(key []byte) ([]byte, error)

Get returns the value at the provided key.

func (*Conn) Keys

func (c *Conn) Keys() ([][]byte, error)

Keys returns a slice containing all keys.

func (*Conn) Ping

func (c *Conn) Ping() error

Ping sends a ping to the server and fails if the connection is broken.

func (*Conn) Reconsilate

func (c *Conn) Reconsilate() (net.Conn, error)

Reconsilate sets the server into reconsilation mode and returns the underlying connection.

func (*Conn) Set

func (c *Conn) Set(key, value []byte) error

Set sets the provided value at the provided key.

func (*Conn) Tidy

func (c *Conn) Tidy() error

Tidy cleans up the store.

type Item

type Item [ItemSize]byte

Item defines the set item.

type Metric

type Metric interface {
	CountChanged(int, int)
	ClientConnected(string)
	ClientDisconnected(string)
	PeerConnected(string)
	PeerDisconnected(string)
}

Metric defines the metric interface.

type MetricLog

type MetricLog struct{}

MetricLog defines a metric log.

func NewMetricLog

func NewMetricLog() *MetricLog

NewMetricLog returns a new metric log.

func (*MetricLog) ClientConnected

func (ml *MetricLog) ClientConnected(clientURL string)

ClientConnected is called if a new client connects.

func (*MetricLog) ClientDisconnected

func (ml *MetricLog) ClientDisconnected(clientURL string)

ClientDisconnected is called if a client disconnects.

func (*MetricLog) CountChanged

func (ml *MetricLog) CountChanged(valueCount, deletedCount int)

CountChanged is called if the number of value or deleted values has changed.

func (*MetricLog) PeerConnected

func (ml *MetricLog) PeerConnected(peerURL string)

PeerConnected is called if a new peer connects.

func (*MetricLog) PeerDisconnected

func (ml *MetricLog) PeerDisconnected(peerURL string)

PeerDisconnected is called if a peer disconnects.

type MetricMock

type MetricMock struct{}

MetricMock defines a metric mock.

func NewMetricMock

func NewMetricMock() *MetricMock

NewMetricMock returns a new metric mock.

func (*MetricMock) ClientConnected

func (mm *MetricMock) ClientConnected(_ string)

ClientConnected is called if a new client connects.

func (*MetricMock) ClientDisconnected

func (mm *MetricMock) ClientDisconnected(_ string)

ClientDisconnected is called if a client disconnects.

func (*MetricMock) CountChanged

func (mm *MetricMock) CountChanged(valueCount, deletedCount int)

CountChanged is called if the number of value or deleted values has changed.

func (*MetricMock) PeerConnected

func (mm *MetricMock) PeerConnected(_ string)

PeerConnected is called if a new peer connects.

func (*MetricMock) PeerDisconnected

func (mm *MetricMock) PeerDisconnected(_ string)

PeerDisconnected is called if a peer disconnects.

type Node

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

Node defines the node.

func NewNode

func NewNode(o Options, m Metric) (*Node, error)

NewNode returns a new node.

func (*Node) Close

func (n *Node) Close() error

Close tears down the node.

func (*Node) ListenURL

func (n *Node) ListenURL() string

ListenURL returns the listen url.

type Options

type Options struct {
	// Listener address in format 'tcp://localhost:5000'.
	ListenURL string

	// Peer addreses in the format `tcp://localhost:5000`.
	PeerURLs []string

	// PeerPingInterval defines the interval in which a peer is pinged in order to test it's availbility.
	PeerPingInterval time.Duration

	// PeerReconnectInterval defines a duration after which a failing peer is reconnected.
	PeerReconnectInterval time.Duration

	// TidyInterval defines the interval in which the store is cleaned up.
	TidyInterval time.Duration
}

Options defines all deks options.

type Server

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

Server defines a server.

func NewServer

func NewServer(store *Store, listenURL string, m Metric) (*Server, error)

NewServer returns a new server.

func (*Server) AddPeer

func (s *Server) AddPeer(
	peerURL string,
	peerPingInterval time.Duration,
	peerReconnectInterval time.Duration,
)

AddPeer adds another node as a target for updates.

func (*Server) Close

func (s *Server) Close() error

Close tears down the node.

func (*Server) ListenURL

func (s *Server) ListenURL() string

ListenURL returns the url of the listener.

func (*Server) Reconcilate

func (s *Server) Reconcilate(url string) (int, error)

Reconcilate performs a reconsiliation with the node at the provided address.

type Set

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

Set defines a set of items.

func NewSet

func NewSet() *Set

NewSet returns a new empty set.

func (*Set) Insert

func (s *Set) Insert(item Item) error

Insert adds the provided item to the set.

func (*Set) Items

func (s *Set) Items() []Item

Items returns a slice of all items in the set.

func (*Set) Len

func (s *Set) Len() int

Len returns the length of the set.

func (*Set) Remove

func (s *Set) Remove(item Item) error

Remove removes the provided item from the set.

type Store

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

Store defines a key-value store.

func NewStore

func NewStore(m Metric) *Store

NewStore returns a new store.

func (*Store) Delete

func (s *Store) Delete(key []byte) error

Delete removes the value at the provided key.

func (*Store) DeletedLen

func (s *Store) DeletedLen() int

DeletedLen returns the length of deleted values.

func (*Store) Each

func (s *Store) Each(fn func([]byte, []byte) error) (err error)

Each interates over all key-value-pairs.

func (*Store) Get

func (s *Store) Get(key []byte) ([]byte, error)

Get returns the value at the provided key. If no value exists, nil is returned.

func (*Store) Len

func (s *Store) Len() int

Len returns the length of the store.

func (*Store) Set

func (s *Store) Set(key, value []byte) error

Set sets the provided value at the provided key.

func (*Store) State

func (s *Store) State() *Set

State returns a set containing all keys and revisions.

func (*Store) Tidy

func (s *Store) Tidy() error

Tidy removes all deleted values from the store.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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