core

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package core provides the core types used by other Redka packages.

Index

Constants

View Source
const (
	TypeString    = TypeID(1)
	TypeList      = TypeID(2)
	TypeSet       = TypeID(3)
	TypeHash      = TypeID(4)
	TypeSortedSet = TypeID(5)
)
View Source
const InitialVersion = 1

InitialVersion is the initial version of the key.

Variables

View Source
var (
	ErrNotFound   = errors.New("key not found")
	ErrKeyType    = errors.New("key type mismatch") // the key already exists with a different type.
	ErrValueType  = errors.New("invalid value type")
	ErrNotAllowed = errors.New("operation not allowed")
)

Common errors returned by data structure methods.

Functions

func IsValueType

func IsValueType(v any) bool

IsValueType reports if the value has a valid type to be persisted in the database. Only the following types are allowed:

  • string
  • integer
  • float
  • boolean
  • byte slice

Types

type Key

type Key struct {
	ID      int
	Key     string
	Type    TypeID
	Version int    // incremented on each update
	ETime   *int64 // expiration time in unix milliseconds
	MTime   int64  // last modification time in unix milliseconds
}

Key represents a key data structure. Each key uniquely identifies a data structure stored in the database (e.g. a string, a list, or a hash). There can be only one data structure with a given key, regardless of type. For example, you can't have a string and a hash map with the same key.

func (Key) Exists

func (k Key) Exists() bool

Exists reports whether the key exists. Returns false for expired keys.

func (Key) TypeName

func (k Key) TypeName() string

TypeName returns the name of the key type.

type TypeID added in v0.2.0

type TypeID int

A TypeID identifies the type of the key and thus the data structure of the value with that key.

type Value

type Value []byte

Value represents a value stored in a database (a byte slice). It can be converted to other scalar types.

func (Value) Bool

func (v Value) Bool() (bool, error)

Bool returns the value as a boolean.

func (Value) Bytes

func (v Value) Bytes() []byte

Bytes returns the value as a byte slice.

func (Value) Exists added in v0.2.0

func (v Value) Exists() bool

func (Value) Float

func (v Value) Float() (float64, error)

Float returns the value as a float64.

func (Value) Int

func (v Value) Int() (int, error)

Int returns the value as an integer.

func (Value) MustBool

func (v Value) MustBool() bool

MustBool returns the value as a boolean, and panics if the value is not a valid boolean. Use this method only if you are sure of the value type.

func (Value) MustFloat

func (v Value) MustFloat() float64

MustFloat returns the value as a float64, and panics if the value is not a valid float. Use this method only if you are sure of the value type.

func (Value) MustInt

func (v Value) MustInt() int

MustInt returns the value as an integer, and panics if the value is not a valid integer. Use this method only if you are sure of the value type.

func (Value) String

func (v Value) String() string

String returns the value as a string.

Jump to

Keyboard shortcuts

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