Documentation
¶
Overview ¶
Package redis implements basis for Redis-compatible commands in Redka.
Index ¶
- Variables
- func MustParse[T Cmd](parse func(BaseCmd) (T, error), s string) T
- func NewFakeConn() *fakeConn
- func Parse[T Cmd](parse func(BaseCmd) (T, error), s string) (T, error)
- func WriteFloat(w Writer, f float64)
- type BaseCmd
- type Cmd
- type RHash
- type RKey
- type RList
- type RSet
- type RStr
- type RZSet
- type Redka
- type Writer
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 WriteFloat ¶
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.
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.
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.