Documentation
¶
Index ¶
- Constants
- func DelCommand(c *Client, cmd redcon.Command)
- func GetCommand(c *Client, cmd redcon.Command)
- func LPopCommand(c *Client, cmd redcon.Command)
- func LPushCommand(c *Client, cmd redcon.Command)
- func LRangeCommand(c *Client, cmd redcon.Command)
- func PingCommand(c *Client, cmd redcon.Command)
- func RPopCommand(c *Client, cmd redcon.Command)
- func RPushCommand(c *Client, cmd redcon.Command)
- func Run(addr string) error
- func SetCommand(c *Client, cmd redcon.Command)
- func TimeExpired(expireAt time.Time) bool
- func TtlCommand(c *Client, cmd redcon.Command)
- type Accept
- type Client
- type ClientId
- type Clients
- type CmdFlag
- type Command
- type CommandHandler
- type Commands
- type DatabaseId
- type Expirer
- type ExpiringKeys
- type Handler
- type Item
- type KeyExpirer
- type Keys
- type List
- func (l *List) LIndex(index int) (*string, error)
- func (l *List) LInsert(isBefore bool, pivot, value *string) int
- func (l *List) LLen() int
- func (l *List) LPop() (*string, bool)
- func (l *List) LPush(values ...*string) int
- func (l *List) LRange(start int, end int) []string
- func (l *List) LRem(count int, value *string) int
- func (l *List) LSet(index int, value *string) error
- func (l *List) LTrim(start int, end int) bool
- func (l *List) OnDelete(key *string, db *RedisDb)
- func (l *List) RPop() (*string, bool)
- func (l *List) RPush(values ...*string) int
- func (l *List) Type() uint64
- func (l *List) TypeFancy() string
- func (l *List) Value() interface{}
- type OnClose
- type Redis
- func (r *Redis) AcceptFn() Accept
- func (r *Redis) Clients() Clients
- func (r *Redis) Command(name string) *Command
- func (r *Redis) CommandExists(cmds ...string) bool
- func (r *Redis) CommandHandlerFn(name string) CommandHandler
- func (r *Redis) Commands() Commands
- func (r *Redis) FlushCommands()
- func (r *Redis) HandlerFn() Handler
- func (r *Redis) KeyExpirer() KeyExpirer
- func (r *Redis) Mu() *sync.RWMutex
- func (r *Redis) NewClient(conn redcon.Conn) *Client
- func (r *Redis) NextClientId() ClientId
- func (r *Redis) OnCloseFn() OnClose
- func (r *Redis) RedisDb(dbId DatabaseId) *RedisDb
- func (r *Redis) RedisDbs() RedisDbs
- func (r *Redis) RegisterCommand(cmd *Command)
- func (r *Redis) RegisterCommands(cmds []*Command)
- func (r *Redis) Run(addr string) error
- func (r *Redis) RunTLS(addr string, tls *tls.Config) error
- func (r *Redis) SetAcceptFn(new Accept)
- func (r *Redis) SetHandlerFn(new Handler)
- func (r *Redis) SetKeyExpirer(ke KeyExpirer)
- func (r *Redis) SetOnCloseFn(new OnClose)
- func (r *Redis) UnknownCommandFn() UnknownCommand
- func (r *Redis) UnregisterCommand(name string)
- type RedisDb
- func (db *RedisDb) Delete(keys ...*string) int
- func (db *RedisDb) DeleteExpired(keys ...*string) int
- func (db *RedisDb) Exists(key *string) bool
- func (db *RedisDb) Expired(key *string) bool
- func (db *RedisDb) Expires(key *string) bool
- func (db *RedisDb) ExpiringKeys() ExpiringKeys
- func (db *RedisDb) Expiry(key *string) time.Time
- func (db *RedisDb) Get(key *string) Item
- func (db *RedisDb) GetOrExpire(key *string, deleteIfExpired bool) Item
- func (db *RedisDb) HasExpiringKeys() bool
- func (db *RedisDb) Id() DatabaseId
- func (db *RedisDb) IsEmpty() bool
- func (db *RedisDb) Keys() Keys
- func (db *RedisDb) Mu() *sync.RWMutex
- func (db *RedisDb) Redis() *Redis
- func (db *RedisDb) Set(key *string, i Item, expires bool, expiry time.Time)
- type RedisDbs
- type String
- type UnknownCommand
Constants ¶
const ( SyntaxErr = "ERR syntax error" InvalidIntErr = "ERR value is not an integer or out of range" WrongTypeErr = "WRONGTYPE Operation against a key holding the wrong kind of value" WrongNumOfArgsErr = "ERR wrong number of arguments for '%s' command" )
const ListType = uint64(1)
const ListTypeFancy = "list"
const StringType = uint64(0)
const StringTypeFancy = "string"
Variables ¶
This section is empty.
Functions ¶
func DelCommand ¶
func GetCommand ¶
func LPopCommand ¶
func LPushCommand ¶
func LRangeCommand ¶
func PingCommand ¶
func RPopCommand ¶
func RPushCommand ¶
func SetCommand ¶
SET key value [NX] [XX] [EX <seconds>] [PX <milliseconds>]
func TimeExpired ¶
TimeExpired check if a timestamp is older than now.
func TtlCommand ¶
Types ¶
type Accept ¶
Accept is called when a Client tries to connect and before everything else, the Client connection will be closed instantaneously if the function returns false.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A connected Client.
func (*Client) DbId ¶
func (c *Client) DbId() DatabaseId
DbId gets the clients selected database id.
func (*Client) SelectDb ¶
func (c *Client) SelectDb(db DatabaseId)
SelectDb selects the clients database.
type CmdFlag ¶
type CmdFlag uint
Command flag type.
const ( CMD_WRITE CmdFlag = iota + 1 /* "w" flag */ CMD_READONLY /* "r" flag */ CMD_DENYOOM /* "m" flag */ CMD_MODULE /* Command exported by module. */ CMD_ADMIN /* "a" flag */ CMD_PUBSUB /* "p" flag */ CMD_NOSCRIPT /* "s" flag */ CMD_RANDOM /* "R" flag */ CMD_SORT_FOR_SCRIPT /* "S" flag */ CMD_LOADING /* "l" flag */ CMD_STALE /* "t" flag */ CMD_SKIP_MONITOR /* "M" flag */ CMD_ASKING /* "k" flag */ CMD_FAST /* "F" flag */ CMD_MODULE_GETKEYS /* Use the modules getkeys interface. */ CMD_MODULE_NO_CLUSTER /* Deny on Redis Cluster. */ )
Command flags. Please check the command table defined in the redis.c file for more information about the meaning of every flag.
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
A command can be registered.
func NewCommand ¶
func NewCommand(name string, handler CommandHandler, flags ...CmdFlag) *Command
type CommandHandler ¶
The CommandHandler is triggered when the received command equals a registered command.
However the CommandHandler is executed by the Handler, so if you implement an own Handler make sure the CommandHandler is called.
type Expirer ¶
type Expirer struct {
// contains filtered or unexported fields
}
func NewKeyExpirer ¶
type Handler ¶
A Handler is called when a request is received and after Accept (if Accept allowed the connection by returning true).
For implementing an own handler see the default handler as a perfect example in the createDefault() function.
type Item ¶
type Item interface { // The pointer to the value. Value() interface{} // The id of the type of the Item. // This need to be constant for the type because it is // used when de-/serializing item from/to disk. Type() uint64 // The type of the Item as readable string. TypeFancy() string // OnDelete is triggered before the key of the item is deleted. // db is the affected database. OnDelete(key *string, db *RedisDb) }
The item interface. An item is the value of a key.
type KeyExpirer ¶
type List ¶
type List struct {
// contains filtered or unexported fields
}
func (*List) LPop ¶
LPop returns popped value and false - returns true if list is now emptied so the key can be deleted.
func (*List) LTrim ¶
LTrim see redis docs - returns true if list is now emptied so the key can be deleted.
func (*List) RPop ¶
RPop returns popped value and false - returns true if list is now emptied so the key can be deleted.
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
This is the redis server.
func Default ¶
func Default() *Redis
Default redis server. Initializes the default redis if not already. You can change the fields or value behind the pointer of the returned redis pointer to extend/change the default.
func (*Redis) CommandExists ¶
CommandExists checks if one or more commands are registered.
func (*Redis) CommandHandlerFn ¶
func (r *Redis) CommandHandlerFn(name string) CommandHandler
CommandHandlerFn returns the CommandHandler of cmd.
func (*Redis) KeyExpirer ¶
func (r *Redis) KeyExpirer() KeyExpirer
func (*Redis) NextClientId ¶
NextClientId atomically gets and increments a counter to return the next client id.
func (*Redis) RedisDb ¶
func (r *Redis) RedisDb(dbId DatabaseId) *RedisDb
RedisDb gets the redis database by its id or creates and returns it if not exists.
func (*Redis) RegisterCommand ¶
RegisterCommand adds a command to the redis instance. If cmd already exists the handler is overridden.
func (*Redis) RegisterCommands ¶
RegisterCommands adds commands to the redis instance. If a cmd already exists the handler is overridden.
func (*Redis) SetAcceptFn ¶
Sets the accept func. Live updates (while redis is running) works.
func (*Redis) SetHandlerFn ¶
Sets the handler func. Live updates (while redis is running) works.
func (*Redis) SetKeyExpirer ¶
func (r *Redis) SetKeyExpirer(ke KeyExpirer)
func (*Redis) SetOnCloseFn ¶
Sets the onclose func. Live updates (while redis is running) works.
func (*Redis) UnknownCommandFn ¶
func (r *Redis) UnknownCommandFn() UnknownCommand
UnknownCommandFn returns the UnknownCommand function.
func (*Redis) UnregisterCommand ¶
UnregisterCommand removes a command.
type RedisDb ¶
type RedisDb struct {
// contains filtered or unexported fields
}
A redis database. There can be more than one in a redis instance.
func (*RedisDb) DeleteExpired ¶
func (*RedisDb) ExpiringKeys ¶
func (db *RedisDb) ExpiringKeys() ExpiringKeys
ExpiringKeys gets keys with an expiry set and their timeout.
func (*RedisDb) GetOrExpire ¶
GetOrExpire gets the item or nil if expired or not exists. If 'deleteIfExpired' is true the key will be deleted.
func (*RedisDb) HasExpiringKeys ¶
HasExpiringKeys checks if db has any expiring keys.
type UnknownCommand ¶
Is called when a request is received, after Accept and if the command is not registered.
However UnknownCommand is executed by the Handler, so if you implement an own Handler make sure to include UnknownCommand.