client

package
v0.0.0-...-a76a3ae Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package client is a library that provides abstracted methods for interacting with the Keye database, including GET, PUT, DEL, and WATCH operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type C

type C struct {
	Config
	// contains filtered or unexported fields
}

C represents the Keye database client.

func New

func New(conf Config) (*C, error)

New creates a Keye client based on the provided configuration.

func (*C) Backup

func (c *C) Backup(chunkSize int64) ([]byte, error)

Backup requests and concatenates database snapshot.

func (*C) Close

func (c *C) Close() error

Close terminates the connection to the Keye database server.

func (*C) Del

func (c *C) Del(k string, optfns ...OptFunc) ([]string, error)

Del deletes the specified key and its corresponding value from the database, returning the deleted key(s). When used with WithRegex(), Del treats the "key" as a regex, deleting all matching keys.

func (*C) Get

func (c *C) Get(k string, optfns ...OptFunc) ([]*pb.KV, error)

Get retrieves keys. By default, Get returns the value for "key", if any. When WithRegex() is passed, Get treats the "key" as a regex. When WithKeysOnly() is passed, Get only returns the key(s) without the value(s).

func (*C) Put

func (c *C) Put(k string, v []byte, optfns ...OptFunc) ([]string, error)

Put adds a key-value pair to the database and returns the modified key(s). When used with WithRegex(), Put treats the "key" as a regex, updating all matching keys with the specified value.

func (*C) Stats

func (c *C) Stats(delta time.Duration) (*Measures, error)

Stats calculates database performance statistics over a delta time range.

func (*C) Watch

func (c *C) Watch(ctx context.Context, k string, optfns ...OptFunc) (*Watcher, error)

Watch watches specified key(s) in the database. If used with WithRegex(), it treats the "key" as a regex, watching all matched keys.

type Config

type Config struct {
	// Addr is the Keye database server address.
	//
	// Default: localhost:23023
	Addr string
	// Timeout sets the request cancellation time.
	//
	// Default: 5s
	Timeout time.Duration
}

Config holds configurations for the Keye client.

type Measures

type Measures struct {
	// global, ongoing stats
	TxStats *TxStats

	// freelist stats
	FreePageN     int32 // total number of free pages on the freelist
	PendingPageN  int32 // total number of pending pages on the freelist
	FreeAlloc     int32 // total bytes allocated in free pages
	FreelistInuse int32 // total bytes used by the freelist

	// transaction stats
	TxN     int32 // total number of started read transactions
	OpenTxN int32 // number of currently open read transactions
}

Measures represents statistics about the database.

type OptFunc

type OptFunc func(*opts)

func WithKeysOnly

func WithKeysOnly() OptFunc

WithKeysOnly configures the operation to only return keys without values.

Applicable for: GET, WATCH

func WithRegex

func WithRegex() OptFunc

WithRegex configures the operation to treat the key as a regex.

Applicable for: GET, PUT, DEL, WATCH

type TxStats

type TxStats struct {
	// page statistics
	PageCount int64 // number of page allocations
	PageAlloc int64 // total bytes allocated

	// cursor statistics
	CursorCount int64 // number of cursors created

	// node statistics
	NodeCount int64 // number of node allocations
	NodeDeref int64 // number of node dereferences

	// rebalance statistics
	Rebalance     int64         // number of node rebalances
	RebalanceTime time.Duration // total time spent rebalancing

	// split/spill statistics
	Split     int64         // number of nodes split
	Spill     int64         // number of nodes spilled
	SpillTime time.Duration // total time spent spilling

	// write statistics
	Write     int64         // number of writes performed
	WriteTime time.Duration // total time spent writing to disk
}

TxStats represents statistics about the actions performed by the transaction.

type Watcher

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

Watcher notifies clients of subscribed key events.

func (Watcher) Error

func (w Watcher) Error() <-chan error

Error returns the error channel.

func (Watcher) NextEvent

func (w Watcher) NextEvent() <-chan watch.Event

NextEvent returns the next event channel.

Jump to

Keyboard shortcuts

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