command

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UnKnownCommandStr is the command not find
	UnKnownCommandStr = "unknown command '%s'"
	// WrongArgs is for wrong number of arguments error
	WrongArgs = "ERR wrong number of arguments for '%s' command"
)
View Source
const (
	//ScanMaxCount is the max limitation of a single scan
	ScanMaxCount = 255
)

Variables

View Source
var (
	// OK is the simple string "OK" returned to client
	OK = "OK"

	// Queued is the simple string "QUEUED" return to client
	Queued = "QUEUED"

	// ErrNoAuth authentication required
	ErrNoAuth = errors.New("NOAUTH Authentication required")

	// ErrAuthInvalid invalid password
	ErrAuthInvalid = errors.New("ERR invalid password")

	// ErrAuthUnSet Client sent AUTH, but no password is set
	ErrAuthUnSet = errors.New("ERR Client sent AUTH, but no password is set")

	// ErrInvalidDB invalid DB index
	ErrInvalidDB = errors.New("ERR invalid DB index")

	//ErrExpire expire time in set
	ErrExpire = errors.New("ERR invalid expire time in set")

	//ErrExpire expire time in setex
	ErrExpireSetEx = errors.New("ERR invalid expire time in setex")

	// ErrInteger value is not an integer or out of range
	ErrInteger = errors.New("ERR value is not an integer or out of range")

	// ErrFloat value is not a valid float
	ErrFloat = errors.New("ERR value is not a valid float")

	// ErrBitInteger bit is not an integer or out of range
	ErrBitInteger = errors.New("ERR bit is not an integer or out of range")

	// ErrBitInvaild the bit argument must be 1 or 0
	ErrBitInvaild = errors.New("ERR The bit argument must be 1 or 0")

	// ErrBitOffset bit offset is not an integer or out of range
	ErrBitOffset = errors.New("ERR bit offset is not an integer or out of range")

	//ErrBitOp not must be called with a single source key.
	ErrBitOp = errors.New("BITOP NOT must be called with a single source key.")

	// ErrOffset offset is out of range
	ErrOffset = errors.New("ERR offset is out of range")

	// ErrIndex offset is out of range
	ErrIndex = errors.New("ERR index out of range")

	// ErrSyntax syntax error
	ErrSyntax = errors.New("ERR syntax error")

	// ErrMSet wrong number of arguments for MSET
	ErrMSet = errors.New("ERR wrong number of arguments for MSET")

	// ErrNoSuchKey reteurn on lset for key which no exist
	ErrNoSuchKey = errors.New("ERR no such key")

	// ErrReturnType return data type error
	ErrReturnType = errors.New("ERR return data type error")

	//ErrMaximum allows the maximum size of a string
	ErrMaximum = errors.New("ERR string exceeds maximum allowed size")

	// ErrMultiNested indicates a nested multi command which is not allowed
	ErrMultiNested = errors.New("ERR MULTI calls can not be nested")

	// ErrTypeMismatch Operation against a key holding the wrong kind of value
	ErrTypeMismatch = errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")

	// ErrEmptyArray error
	ErrEmptyArray = errors.New("EmptyArray error")

	//ErrExec exec without multi
	ErrExec = errors.New("ERR EXEC without MULTI")

	//ErrDiscard without multi
	ErrDiscard = errors.New("ERR DISCARD without MULTI")

	//argument min or max isn't float
	ErrMinOrMaxNotFloat = errors.New("ERR min or max is not a float")
)
View Source
var (
	//MaxRangeInteger max index in setrange command
	MaxRangeInteger = 2<<29 - 1
)

Functions

func Auth

func Auth(ctx *Context)

Auth verifies the client

func Call

func Call(ctx *Context)

Call a command

func Client

func Client(ctx *Context)

Client manages client connections

func Discard

func Discard(ctx *Context)

Discard flushes all previously queued commands in a transaction and restores the connection state to normal

func Echo

func Echo(ctx *Context)

Echo the given string

func ErrUnKnownCommand

func ErrUnKnownCommand(cmd string) error

ErrUnKnownCommand return RedisError of the cmd

func ErrWrongArgs

func ErrWrongArgs(cmd string) error

ErrWrongArgs return RedisError of the cmd

func Exec

func Exec(ctx *Context)

Exec all the commands queued in client

func Info

func Info(ctx *Context)

Info returns information and statistics about the server in a format that is simple to parse by computers and easy to read by humans

func Monitor

func Monitor(ctx *Context)

Monitor streams back every command processed by the Titan server

func Multi

func Multi(ctx *Context)

Multi starts a transaction which will block subsequent commands until 'exec'

func Ping

func Ping(ctx *Context)

Ping the server

func Quit

func Quit(ctx *Context)

Quit asks the server to close the connection

func RedisCommand

func RedisCommand(ctx *Context)

RedisCommand returns Array reply of details about all Redis commands

func Select

func Select(ctx *Context)

Select the logical database

func SwapDB

func SwapDB(ctx *Context)

SwapDB swaps two Redis databases

func Time

func Time(ctx *Context)

Time returns the server time

func Token

func Token(key, namespace []byte, createAt int64) ([]byte, error)

Token token create through key server namespace create time

func Unwatch

func Unwatch(ctx *Context)

Unwatch flushes all the previously watched keys for a transaction

func Verify

func Verify(token, key []byte) ([]byte, error)

func Watch

func Watch(ctx *Context)

Watch starts a transaction, watch is a global transaction and is not key associated(this is different from redis)

Types

type Base

type Base struct {
	Version   int8   `json:"version"`
	CreateAt  int64  `json:"create_at"`
	Namespace []byte `json:"namespace"`
}

Base token base msg

func (*Base) MarshalBinary

func (t *Base) MarshalBinary() (data []byte, err error)

MarshalBinary Namespace SHOULD NOT contains a colon

func (*Base) UnmarshalBinary

func (t *Base) UnmarshalBinary(data []byte) error

UnmarshalBinary token base unmarshl

type Command

type Command func(ctx *Context)

Command is a redis command implementation

func AutoCommit

func AutoCommit(cmd TxnCommand) Command

AutoCommit commits to database after run a txn command

type Constraint

type Constraint struct {
	Arity    int // number of arguments, it is possible to use -N to say >= N
	Flags    Flag
	FirstKey int
	LastKey  int
	KeyStep  int
}

Constraint is the rule of command

type Context

type Context struct {
	Name    string
	Args    []string
	In      io.Reader
	Out     io.Writer
	TraceID string
	*context.Context
}

Context is the runtime context of a command

type Desc

type Desc struct {
	Proc Command
	Stat Statistic
	Cons Constraint
}

Desc describes a command with constraints

type Executor

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

Executor executes a command

func NewExecutor

func NewExecutor() *Executor

NewExecutor news a Executor

func (*Executor) Execute

func (e *Executor) Execute(ctx *Context)

Execute a command

type Flag

type Flag int

Flag is the redis command flag

const (
	CmdWrite Flag = 1 << iota
	CmdReadOnly
	CmdDenyOOM
	CmdModule
	CmdAdmin
	CmdPubsub
	CmdNoScript
	CmdRandom
	CmdSortForScript
	CmdLoading
	CmdStale
	CmdSkipMonitor
	CmdAsking
	CmdFast
	CmdModuleGetKeys
	CmdModuleNoCluster
)

Command flags

func (Flag) String

func (f Flag) String() string

String returns the string representation of flag

type MinHeap added in v0.6.0

type MinHeap []*db.SetIter

func (MinHeap) Len added in v0.6.0

func (h MinHeap) Len() int

func (MinHeap) Less added in v0.6.0

func (h MinHeap) Less(i, j int) bool

func (*MinHeap) Pop added in v0.6.0

func (h *MinHeap) Pop() interface{}

func (*MinHeap) Push added in v0.6.0

func (h *MinHeap) Push(x interface{})

func (MinHeap) Swap added in v0.6.0

func (h MinHeap) Swap(i, j int)

type OnCommit

type OnCommit func()

OnCommit returns by TxnCommand and will be called after a transaction being committed

func Append

func Append(ctx *Context, txn *db.Transaction) (OnCommit, error)

Append a value to a key

func BitCount added in v0.6.0

func BitCount(ctx *Context, txn *db.Transaction) (OnCommit, error)

BitCount counts the number of set bits (population counting) in a string.

func BitField added in v0.6.0

func BitField(ctx *Context, txn *db.Transaction) (OnCommit, error)

BitField performs arbitrary bitfield integer operations on strings

func BitOp added in v0.6.0

func BitOp(ctx *Context, txn *db.Transaction) (OnCommit, error)

BitOp performs bitwise operations between strings

func BitPos added in v0.6.0

func BitPos(ctx *Context, txn *db.Transaction) (OnCommit, error)

BitPos finds first bit set or clear in a string

func BulkString

func BulkString(w io.Writer, s string) OnCommit

BulkString replies a bulkstring when commit

func BytesArray

func BytesArray(w io.Writer, a [][]byte) OnCommit

BytesArray replies a [][]byte when commit

func Debug

func Debug(ctx *Context, txn *db.Transaction) (OnCommit, error)

Debug the titan server

func Decr

func Decr(ctx *Context, txn *db.Transaction) (OnCommit, error)

Decr decrements the integer value of a key by one

func DecrBy

func DecrBy(ctx *Context, txn *db.Transaction) (OnCommit, error)

DecrBy decrements the integer value of a key by the given number

func Delete

func Delete(ctx *Context, txn *db.Transaction) (OnCommit, error)

Delete removes the specified keys. A key is ignored if it does not exist

func Exists

func Exists(ctx *Context, txn *db.Transaction) (OnCommit, error)

Exists returns if key exists

func Expire

func Expire(ctx *Context, txn *db.Transaction) (OnCommit, error)

Expire sets a timeout on key

func ExpireAt

func ExpireAt(ctx *Context, txn *db.Transaction) (OnCommit, error)

ExpireAt sets an absolute timestamp to expire on key

func FlushAll

func FlushAll(ctx *Context, txn *db.Transaction) (OnCommit, error)

FlushAll cleans up all databases This function is **VERY DANGEROUS**. It's not only running on one single region, but it can delete a large range that spans over many regions, bypassing the Raft layer.

func FlushDB

func FlushDB(ctx *Context, txn *db.Transaction) (OnCommit, error)

FlushDB clears current db This function is **VERY DANGEROUS**. It's not only running on one single region, but it can delete a large range that spans over many regions, bypassing the Raft layer.

func Get

func Get(ctx *Context, txn *db.Transaction) (OnCommit, error)

Get the value of key

func GetBit added in v0.6.0

func GetBit(ctx *Context, txn *db.Transaction) (OnCommit, error)

GetBit gets the bit at offset in the string value stored at key.

func GetRange

func GetRange(ctx *Context, txn *db.Transaction) (OnCommit, error)

GetRange increments the integer value of a keys by the given amount

func GetSet

func GetSet(ctx *Context, txn *db.Transaction) (OnCommit, error)

GetSet sets the string value of a key and return its old value

func HDel

func HDel(ctx *Context, txn *db.Transaction) (OnCommit, error)

HDel removes the specified fields from the hash stored at key

func HExists

func HExists(ctx *Context, txn *db.Transaction) (OnCommit, error)

HExists returns if field is an existing field in the hash stored at key

func HGet

func HGet(ctx *Context, txn *db.Transaction) (OnCommit, error)

HGet returns the value associated with field in the hash stored at key

func HGetAll

func HGetAll(ctx *Context, txn *db.Transaction) (OnCommit, error)

HGetAll returns all fields and values of the hash stored at key

func HIncrBy

func HIncrBy(ctx *Context, txn *db.Transaction) (OnCommit, error)

HIncrBy increments the number stored at field in the hash stored at key by increment

func HIncrByFloat

func HIncrByFloat(ctx *Context, txn *db.Transaction) (OnCommit, error)

HIncrByFloat increment the specified field of a hash stored at key, and representing a floating point number, by the specified increment

func HKeys

func HKeys(ctx *Context, txn *db.Transaction) (OnCommit, error)

HKeys returns all field names in the hash stored at key

func HLen

func HLen(ctx *Context, txn *db.Transaction) (OnCommit, error)

HLen returns the number of fields contained in the hash stored at key

func HMGet

func HMGet(ctx *Context, txn *db.Transaction) (OnCommit, error)

HMGet returns the values associated with the specified fields in the hash stored at key

func HMSet

func HMSet(ctx *Context, txn *db.Transaction) (OnCommit, error)

HMSet sets the specified fields to their respective values in the hash stored at key

func HScan added in v0.6.0

func HScan(ctx *Context, txn *db.Transaction) (OnCommit, error)

HScan incrementally iterate hash fields and associated values

func HSet

func HSet(ctx *Context, txn *db.Transaction) (OnCommit, error)

HSet sets field in the hash stored at key to value

func HSetNX

func HSetNX(ctx *Context, txn *db.Transaction) (OnCommit, error)

HSetNX sets field in the hash stored at key to value, only if field does not yet exist

func HStrLen

func HStrLen(ctx *Context, txn *db.Transaction) (OnCommit, error)

HStrLen returns the string length of the value associated with field in the hash stored at key

func HVals

func HVals(ctx *Context, txn *db.Transaction) (OnCommit, error)

HVals returns all values in the hash stored at key

func Incr

func Incr(ctx *Context, txn *db.Transaction) (OnCommit, error)

Incr increments the integer value of a key by one

func IncrBy

func IncrBy(ctx *Context, txn *db.Transaction) (OnCommit, error)

IncrBy increments the integer value of a key by the given amount

func IncrByFloat

func IncrByFloat(ctx *Context, txn *db.Transaction) (OnCommit, error)

IncrByFloat increments the float value of a key by the given amount

func Integer

func Integer(w io.Writer, v int64) OnCommit

Integer replies in integer when commit

func Keys

func Keys(ctx *Context, txn *db.Transaction) (OnCommit, error)

Keys returns all keys matching pattern

func LIndex

func LIndex(ctx *Context, txn *db.Transaction) (OnCommit, error)

LIndex get an element from a list by its index

func LInsert

func LInsert(ctx *Context, txn *db.Transaction) (OnCommit, error)

LInsert insert an element before or after another element in a list

func LLen

func LLen(ctx *Context, txn *db.Transaction) (OnCommit, error)

LLen get the length of a list

func LPop

func LPop(ctx *Context, txn *db.Transaction) (OnCommit, error)

LPop removes and returns the first element of the list stored at key

func LPush

func LPush(ctx *Context, txn *db.Transaction) (OnCommit, error)

LPush inserts an entry to the head of the list

func LPushx

func LPushx(ctx *Context, txn *db.Transaction) (OnCommit, error)

LPushx prepend a value to a list, only if the list exists

func LRange

func LRange(ctx *Context, txn *db.Transaction) (OnCommit, error)

LRange get a range of elements from a list

func LRem

func LRem(ctx *Context, txn *db.Transaction) (OnCommit, error)

LRem remove elements from a list

func LSet

func LSet(ctx *Context, txn *db.Transaction) (OnCommit, error)

LSet set the value of an element in a list by its index

func LTrim

func LTrim(ctx *Context, txn *db.Transaction) (OnCommit, error)

LTrim trim a list to the specified range

func MGet

func MGet(ctx *Context, txn *db.Transaction) (OnCommit, error)

MGet returns the values of all specified key

func MSet

func MSet(ctx *Context, txn *db.Transaction) (OnCommit, error)

MSet sets the given keys to their respective values

func MSetNx

func MSetNx(ctx *Context, txn *db.Transaction) (OnCommit, error)

MSetNx et multiple keys to multiple values,only if none of the keys exist TODO bug

func NullBulkString

func NullBulkString(w io.Writer) OnCommit

NullBulkString replies a null bulkstring when commit

func Object

func Object(ctx *Context, txn *db.Transaction) (OnCommit, error)

Object inspects the internals of Redis Objects

func PExpire

func PExpire(ctx *Context, txn *db.Transaction) (OnCommit, error)

PExpire works exactly like expire but the time to live of the key is specified in milliseconds instead of seconds

func PExpireAt

func PExpireAt(ctx *Context, txn *db.Transaction) (OnCommit, error)

PExpireAt has the same effect and semantic as expireAt, but the Unix time at which the key will expire is specified in milliseconds instead of seconds

func PSetEx

func PSetEx(ctx *Context, txn *db.Transaction) (OnCommit, error)

PSetEx sets the value and expiration in milliseconds of a key

func PTTL

func PTTL(ctx *Context, txn *db.Transaction) (OnCommit, error)

PTTL likes TTL this command returns the remaining time to live of a key that has an expire set, with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds

func Persist

func Persist(ctx *Context, txn *db.Transaction) (OnCommit, error)

Persist removes the existing timeout on key, turning the key from volatile to persistent

func RPop

func RPop(ctx *Context, txn *db.Transaction) (OnCommit, error)

RPop remove and get the last element in a list

func RPopLPush

func RPopLPush(ctx *Context, txn *db.Transaction) (OnCommit, error)

RPopLPush remove the last element in a list, prepend it to another list and return it

func RPush

func RPush(ctx *Context, txn *db.Transaction) (OnCommit, error)

RPush append one or multiple values to a list

func RPushx

func RPushx(ctx *Context, txn *db.Transaction) (OnCommit, error)

RPushx append a value to a list, only if the list exists

func RandomKey

func RandomKey(ctx *Context, txn *db.Transaction) (OnCommit, error)

RandomKey returns a random key from the currently selected database

func SAdd

func SAdd(ctx *Context, txn *db.Transaction) (OnCommit, error)

SAdd adds the specified members to the set stored at key

func SCard added in v0.6.0

func SCard(ctx *Context, txn *db.Transaction) (OnCommit, error)

SCard returns the set cardinality (number of elements) of the set stored at key

func SDiff added in v0.6.0

func SDiff(ctx *Context, txn *db.Transaction) (OnCommit, error)

SDiff returns the members of the set resulting from the difference between the first set and all the successive sets.

func SInter added in v0.6.0

func SInter(ctx *Context, txn *db.Transaction) (OnCommit, error)

SInter returns the members of the set resulting from the intersection of all the given sets.

func SIsmember added in v0.6.0

func SIsmember(ctx *Context, txn *db.Transaction) (OnCommit, error)

SIsmember returns if member is a member of the set stored at key

func SMembers

func SMembers(ctx *Context, txn *db.Transaction) (OnCommit, error)

SMembers returns all the members of the set value stored at key

func SMove added in v0.6.0

func SMove(ctx *Context, txn *db.Transaction) (OnCommit, error)

SMove movies member from the set at source to the set at destination

func SPop added in v0.6.0

func SPop(ctx *Context, txn *db.Transaction) (OnCommit, error)

SPop removes and returns one or more random elements from the set value store at key

func SRem added in v0.6.0

func SRem(ctx *Context, txn *db.Transaction) (OnCommit, error)

SRem removes the specified members from the set stored at key

func SUnion added in v0.6.0

func SUnion(ctx *Context, txn *db.Transaction) (OnCommit, error)

SUnion returns the members of the set resulting from the union of all the given sets.

func Scan

func Scan(ctx *Context, txn *db.Transaction) (OnCommit, error)

Scan incrementally iterates the key space

func Set

func Set(ctx *Context, txn *db.Transaction) (OnCommit, error)

Set key to hold the string value

func SetBit added in v0.6.0

func SetBit(ctx *Context, txn *db.Transaction) (OnCommit, error)

SetBit sets or clears the bit at offset in the string value stored at key.

func SetEx

func SetEx(ctx *Context, txn *db.Transaction) (OnCommit, error)

SetEx sets the value and expiration of a key KEY_NAME TIMEOUT VALUE

func SetNx

func SetNx(ctx *Context, txn *db.Transaction) (OnCommit, error)

SetNx sets the value of a key ,only if the key does not exist

func SetRange

func SetRange(ctx *Context, txn *db.Transaction) (OnCommit, error)

SetRange overwrites part of the string stored at key, starting at the specified offset, for the entire length of value.

func SimpleString

func SimpleString(w io.Writer, s string) OnCommit

SimpleString replies a simplestring when commit

func Strlen

func Strlen(ctx *Context, txn *db.Transaction) (OnCommit, error)

Strlen returns the length of the string value stored at key

func TTL

func TTL(ctx *Context, txn *db.Transaction) (OnCommit, error)

TTL returns the remaining time to live of a key that has a timeout

func Touch added in v0.6.0

func Touch(ctx *Context, txn *db.Transaction) (OnCommit, error)

Touch alters the last access time of a key(s)

func TxnCall

func TxnCall(ctx *Context, txn *db.Transaction) (OnCommit, error)

TxnCall calls a command with transaction, it is used with multi/exec

func Type

func Type(ctx *Context, txn *db.Transaction) (OnCommit, error)

Type returns the string representation of the type of the value stored at key

func ZAdd added in v0.6.0

func ZAdd(ctx *Context, txn *db.Transaction) (OnCommit, error)

ZAdd adds the specified members with scores to the sorted set

func ZCard added in v0.6.0

func ZCard(ctx *Context, txn *db.Transaction) (OnCommit, error)

func ZRange added in v0.6.0

func ZRange(ctx *Context, txn *db.Transaction) (OnCommit, error)

func ZRangeByScore added in v0.6.0

func ZRangeByScore(ctx *Context, txn *db.Transaction) (OnCommit, error)

func ZRem added in v0.6.0

func ZRem(ctx *Context, txn *db.Transaction) (OnCommit, error)

func ZRevRange added in v0.6.0

func ZRevRange(ctx *Context, txn *db.Transaction) (OnCommit, error)

func ZRevRangeByScore added in v0.6.0

func ZRevRangeByScore(ctx *Context, txn *db.Transaction) (OnCommit, error)

func ZScore added in v0.6.0

func ZScore(ctx *Context, txn *db.Transaction) (OnCommit, error)

type RedisError

type RedisError error

RedisError defines the redis protocol error

type Statistic

type Statistic struct {
	Microseconds int64
	Calls        int64
}

Statistic for the redis command

type TxnCommand

type TxnCommand func(ctx *Context, txn *db.Transaction) (OnCommit, error)

TxnCommand runs a command in transaction

Jump to

Keyboard shortcuts

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