redis

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package redis implements basis for Redis-compatible commands in Redka.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArgNum     = errors.New("ERR wrong number of arguments")
	ErrInvalidCursor     = errors.New("ERR invalid cursor")
	ErrInvalidExpireTime = errors.New("ERR invalid expire time")
	ErrInvalidFloat      = errors.New("ERR value is not a float")
	ErrInvalidInt        = errors.New("ERR value is not an integer")
	ErrNestedMulti       = errors.New("ERR MULTI calls can not be nested")
	ErrNotFound          = errors.New("ERR no such key")
	ErrNotInMulti        = errors.New("ERR EXEC without MULTI")
	ErrOutOfRange        = errors.New("ERR index out of range")
	ErrSyntaxError       = errors.New("ERR syntax error")
	ErrUnknownCmd        = errors.New("ERR unknown command")
	ErrUnknownSubcmd     = errors.New("ERR unknown subcommand")
)

Redis-like errors.

Functions

func MustParse

func MustParse[T Cmd](parse func(BaseCmd) (T, error), s string) T

MustParse parses a text representation of a command into a command and panics if an error occurs.

func NewFakeConn

func NewFakeConn() *fakeConn

NewFakeConn creates a new fake connection for testing.

func Parse

func Parse[T Cmd](parse func(BaseCmd) (T, error), s string) (T, error)

Parse parses a text representation of a command into a command.

func WriteFloat

func WriteFloat(w Writer, f float64)

WriteFloat writes a float64 value to the writer.

Types

type BaseCmd

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

BaseCmd is a base for Redis-compatible commands.

func NewBaseCmd

func NewBaseCmd(args [][]byte) BaseCmd

NewBaseCmd creates a new BaseCmd.

func (BaseCmd) Args

func (cmd BaseCmd) Args() [][]byte

Args returns the command arguments.

func (BaseCmd) Error

func (cmd BaseCmd) Error(err error) string

Error translates a domain error to a command error.

func (BaseCmd) Name

func (cmd BaseCmd) Name() string

Name returns the command name.

func (BaseCmd) String

func (cmd BaseCmd) String() string

String returns the command string representation (name and arguments).

type Cmd

type Cmd interface {
	// Name returns the command name.
	Name() string

	// String returns the command string representation (name and arguments).
	String() string

	// Error translates a domain error to a command error
	// and returns its string representation.
	Error(err error) string

	// Run executes the command and writes the result to the writer.
	Run(w Writer, red Redka) (any, error)
}

Cmd is a Redis-compatible command.

type RHash

type RHash interface {
	Delete(key string, fields ...string) (int, error)
	Exists(key, field string) (bool, error)
	Fields(key string) ([]string, error)
	Get(key, field string) (core.Value, error)
	GetMany(key string, fields ...string) (map[string]core.Value, error)
	Incr(key, field string, delta int) (int, error)
	IncrFloat(key, field string, delta float64) (float64, error)
	Items(key string) (map[string]core.Value, error)
	Len(key string) (int, error)
	Scan(key string, cursor int, pattern string, pageSize int) (rhash.ScanResult, error)
	Scanner(key, pattern string, pageSize int) *rhash.Scanner
	Set(key, field string, value any) (bool, error)
	SetMany(key string, items map[string]any) (int, error)
	SetNotExists(key, field string, value any) (bool, error)
	Values(key string) ([]core.Value, error)
}

RHash is a hash repository.

type RKey

type RKey interface {
	Count(keys ...string) (int, error)
	Delete(keys ...string) (int, error)
	DeleteAll() error
	Exists(key string) (bool, error)
	Expire(key string, ttl time.Duration) error
	ExpireAt(key string, at time.Time) error
	Get(key string) (core.Key, error)
	Keys(pattern string) ([]core.Key, error)
	Len() (int, error)
	Persist(key string) error
	Random() (core.Key, error)
	Rename(key, newKey string) error
	RenameNotExists(key, newKey string) (bool, error)
	Scan(cursor int, pattern string, ktype core.TypeID, count int) (rkey.ScanResult, error)
	Scanner(pattern string, ktype core.TypeID, pageSize int) *rkey.Scanner
}

RKey is a key repository.

type RList

type RList interface {
	Delete(key string, elem any) (int, error)
	DeleteBack(key string, elem any, count int) (int, error)
	DeleteFront(key string, elem any, count int) (int, error)
	Get(key string, idx int) (core.Value, error)
	InsertAfter(key string, pivot, elem any) (int, error)
	InsertBefore(key string, pivot, elem any) (int, error)
	Len(key string) (int, error)
	PopBack(key string) (core.Value, error)
	PopBackPushFront(src, dest string) (core.Value, error)
	PopFront(key string) (core.Value, error)
	PushBack(key string, elem any) (int, error)
	PushFront(key string, elem any) (int, error)
	Range(key string, start, stop int) ([]core.Value, error)
	Set(key string, idx int, elem any) error
	Trim(key string, start, stop int) (int, error)
}

RList is a list repository.

type RSet

type RSet interface {
	Add(key string, elems ...any) (int, error)
	Delete(key string, elems ...any) (int, error)
	Diff(keys ...string) ([]core.Value, error)
	DiffStore(dest string, keys ...string) (int, error)
	Exists(key, elem any) (bool, error)
	Inter(keys ...string) ([]core.Value, error)
	InterStore(dest string, keys ...string) (int, error)
	Items(key string) ([]core.Value, error)
	Len(key string) (int, error)
	Move(src, dest string, elem any) error
	Pop(key string) (core.Value, error)
	Random(key string) (core.Value, error)
	Scan(key string, cursor int, pattern string, count int) (rset.ScanResult, error)
	Scanner(key, pattern string, pageSize int) *rset.Scanner
	Union(keys ...string) ([]core.Value, error)
	UnionStore(dest string, keys ...string) (int, error)
}

RSet is a set repository.

type RStr

type RStr interface {
	Get(key string) (core.Value, error)
	GetMany(keys ...string) (map[string]core.Value, error)
	Incr(key string, delta int) (int, error)
	IncrFloat(key string, delta float64) (float64, error)
	Set(key string, value any) error
	SetExpires(key string, value any, ttl time.Duration) error
	SetMany(items map[string]any) error
	SetWith(key string, value any) rstring.SetCmd
}

RStr is a string repository.

type RZSet

type RZSet interface {
	Add(key string, elem any, score float64) (bool, error)
	AddMany(key string, items map[any]float64) (int, error)
	Count(key string, min, max float64) (int, error)
	Delete(key string, elems ...any) (int, error)
	DeleteWith(key string) rzset.DeleteCmd
	GetRank(key string, elem any) (rank int, score float64, err error)
	GetRankRev(key string, elem any) (rank int, score float64, err error)
	GetScore(key string, elem any) (float64, error)
	Incr(key string, elem any, delta float64) (float64, error)
	Inter(keys ...string) ([]rzset.SetItem, error)
	InterWith(keys ...string) rzset.InterCmd
	Len(key string) (int, error)
	Range(key string, start, stop int) ([]rzset.SetItem, error)
	RangeWith(key string) rzset.RangeCmd
	Scan(key string, cursor int, pattern string, count int) (rzset.ScanResult, error)
	Scanner(key, pattern string, pageSize int) *rzset.Scanner
	Union(keys ...string) ([]rzset.SetItem, error)
	UnionWith(keys ...string) rzset.UnionCmd
}

RZSet is a sorted set repository.

type Redka

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

Redka is an abstraction for *redka.DB and *redka.Tx. Used to execute commands in a unified way.

func RedkaDB

func RedkaDB(db *redka.DB) Redka

RedkaDB creates a new Redka instance for a database.

func RedkaTx

func RedkaTx(tx *redka.Tx) Redka

RedkaTx creates a new Redka instance for a transaction.

func (Redka) Hash

func (r Redka) Hash() RHash

Hash returns the hash repository.

func (Redka) Key

func (r Redka) Key() RKey

Key returns the key repository.

func (Redka) List

func (r Redka) List() RList

List returns the list repository.

func (Redka) Set

func (r Redka) Set() RSet

Set returns the set repository.

func (Redka) Str

func (r Redka) Str() RStr

Str returns the string repository.

func (Redka) ZSet

func (r Redka) ZSet() RZSet

ZSet returns the sorted set repository.

type Writer

type Writer interface {
	WriteAny(v any)
	WriteArray(count int)
	WriteBulk(bulk []byte)
	WriteBulkString(bulk string)
	WriteError(msg string)
	WriteInt(num int)
	WriteInt64(num int64)
	WriteNull()
	WriteRaw(data []byte)
	WriteString(str string)
	WriteUint64(num uint64)
}

Writer is an interface to write responses to the client.

Jump to

Keyboard shortcuts

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