command

package
v0.0.0-...-e130aba Latest Latest
Warning

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

Go to latest
Published: May 9, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package command

Command describes a set of actions performed on a btree. Each command is isolated from other commands and can only affect one shard.

TODO: Remake commands to support work with multiple shards

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command interface {
	Execute(storage *btree.BTree) (string, error)
	Type() Type
	Key() []byte
}

Command interface describes how a command affects the low level storage. Each command should implement 3 methods: Execute(), Type() and Key()

- Execute should represent how certain Command will affect the storage, Read commands should return value of specified key and Write commands should return it's own value as result. Any error returned will be considered as fatal (for now). Interaction with storage is done via btree.Btree

- Type should return CommandType for a certain Command. If a Command is not writing any data - it is considered as read, otherwise - as write

- Key should return single string which represents what Command is querying. Embed pair struct to automatically embed Key() method

func Get

func Get(key string) Command

func Set

func Set(key, value string) Command

type Type

type Type int

Type represents which mutex behavior will be used for a command.

- Read = 0 - command only reads from storage without altering it. Locks read mutex

- Write = 1 - command can alter the storage. Locks read and write mutex

const (
	Read Type = iota
	Write
)

Jump to

Keyboard shortcuts

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