Documentation
¶
Index ¶
- func AbsInt(n int) int
- func AdaptType(s string) interface{}
- func CompareLex(s1 string, s2 string) int
- func CompareNestedStringArrays(got [][]string, want [][]string) bool
- func Decode(raw []byte) ([]string, error)
- func EncodeCommand(cmd []string) []byte
- func FilterExpiredKeys(now time.Time, state map[int]map[string]KeyData) map[int]map[string]KeyData
- func GetConnection(addr string, port int) (net.Conn, error)
- func GetFreePort() (int, error)
- func GetIPAddress() (string, error)
- func GetSubCommand(command Command, cmd []string) (interface{}, error)
- func GetTLSConnection(addr string, port int, config *tls.Config) (net.Conn, error)
- func IsMaxMemoryExceeded(memUsed int64, maxMemory uint64) bool
- func IsWriteCommand(command Command, subCommand SubCommand) bool
- func ParseBooleanArrayResponse(b []byte) ([]bool, error)
- func ParseBooleanResponse(b []byte) (bool, error)
- func ParseFloatResponse(b []byte) (float64, error)
- func ParseIntegerArrayResponse(b []byte) ([]int, error)
- func ParseIntegerResponse(b []byte) (int, error)
- func ParseMemory(memory string) (uint64, error)
- func ParseNestedStringArrayResponse(b []byte) ([][]string, error)
- func ParseNilResponse(b []byte) (bool, error)
- func ParseStringArrayResponse(b []byte) ([]string, error)
- func ParseStringResponse(b []byte) (string, error)
- func ReadMessage(r io.Reader) ([]byte, error)
- func RetryBackoff(b retry.Backoff, maxRetries uint64, ...) retry.Backoff
- type ApplyRequest
- type ApplyResponse
- type Command
- type ConnectionInfo
- type ContextConnID
- type ContextServerID
- type HandlerFunc
- type HandlerFuncParams
- type KeyData
- type KeyExtractionFunc
- type KeyExtractionFuncResult
- type ServerInfo
- type SnapshotObject
- type SubCommand
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareLex ¶
CompareLex returns -1 when s2 is lexicographically greater than s1, 0 if they're equal and 1 if s2 is lexicographically less than s1.
func EncodeCommand ¶
func FilterExpiredKeys ¶
FilterExpiredKeys filters out keys that are already expired, so they are not persisted.
func GetFreePort ¶
func GetIPAddress ¶
func GetSubCommand ¶
func GetTLSConnection ¶
func IsMaxMemoryExceeded ¶
IsMaxMemoryExceeded checks whether we have exceeded the current maximum memory limit.
func IsWriteCommand ¶
func IsWriteCommand(command Command, subCommand SubCommand) bool
func ParseBooleanResponse ¶
func ParseFloatResponse ¶
func ParseIntegerResponse ¶
func ParseMemory ¶
ParseMemory returns an integer representing the bytes in the memory string
func ParseNilResponse ¶
func ParseStringResponse ¶
func RetryBackoff ¶
Types ¶
type ApplyRequest ¶
type ApplyRequest struct { Type string `json:"Type"` // command | delete-key ServerID string `json:"ServerID"` ConnectionID string `json:"ConnectionID"` Protocol int `json:"Protocol"` Database int `json:"Database"` CMD []string `json:"CMD"` Key string `json:"Key"` // Optional: Used with delete-key type to specify which key to delete. }
type ApplyResponse ¶
type Command ¶
type Command struct { Command string // The command keyword (e.g. "set", "get", "hset"). Module string // The module this command belongs to. All the available modules are in the `constants` package. Categories []string // The ACL categories this command belongs to. All the available categories are in the `constants` package. Description string // The description of the command. Includes the command syntax. SubCommands []SubCommand // The list of subcommands for this command. Empty if the command has no subcommands. Sync bool // Specifies if command should be synced across replication cluster. Type string // The type of command ("BUILT_IN", "GO_MODULE", "LUA_SCRIPT", "JS_SCRIPT"). KeyExtractionFunc HandlerFunc }
type ConnectionInfo ¶
type ConnectionInfo struct { Id uint64 // Connection id. Name string // Alias name for this connection. Protocol int // The RESP protocol used by the client. Can be either 2 or 3. Database int // Database index currently being used by the connection. }
ConnectionInfo holds information about the connection
type ContextConnID ¶
type ContextConnID string
type ContextServerID ¶
type ContextServerID string
type HandlerFunc ¶
type HandlerFunc func(params HandlerFuncParams) ([]byte, error)
HandlerFunc is a functions described by a command where the bulk of the command handling is done. This function returns a byte slice which contains a RESP2 response. The response from this function is forwarded directly to the client connection that triggered the command. In embedded mode, the response is parsed and a native Go type is returned to the caller.
type HandlerFuncParams ¶
type HandlerFuncParams struct { // Context is the context passed from the SugarDB instance. Context context.Context // Command is the string slice contains the command (e.g []string{"SET", "key", "value"}) Command []string // Connection is the connection that triggered this command. // Do not write the response directly to the connection, return it from the function. Connection *net.Conn // KeysExist returns a map that specifies which keys exist in the keyspace. KeysExist func(ctx context.Context, keys []string) map[string]bool // GetExpiry returns the expiry time of a key. GetExpiry func(ctx context.Context, key string) time.Time // GetHashExpiry returns the expiry time of a field in a key whose value is a hash. GetHashExpiry func(ctx context.Context, key string, field string) time.Time // DeleteKey deletes the specified key. Returns an error if the deletion was unsuccessful. DeleteKey func(ctx context.Context, key string) error // GetValues retrieves the values from the specified keys. // Non-existent keys will be nil. GetValues func(ctx context.Context, keys []string) map[string]interface{} // SetValues sets each of the keys with their corresponding values in the provided map. SetValues func(ctx context.Context, entries map[string]interface{}) error // SetExpiry sets the expiry time of the key. SetExpiry func(ctx context.Context, key string, expire time.Time, touch bool) // SetHashExpiry sets the expiry time of a field in a key whose value is a hash. SetHashExpiry func(ctx context.Context, key string, field string, expire time.Time) error // GetClock gets the clock used by the server. // Use this when making use of time methods like .Now and .After. // This inversion of control is a helper for testing as the clock is automatically mocked in tests. GetClock func() clock.Clock // GetAllCommands returns all the commands loaded in the SugarDB instance. GetAllCommands func() []Command // GetACL returns the SugarDB instance's ACL engine. // There's no need to use this outside of the acl package, // ACL authorizations for all commands will be handled automatically by the SugarDB instance as long as the // commands KeyExtractionFunc returns the correct keys. GetACL func() interface{} // GetPubSub returns the SugarDB instance's PubSub engine. // There's no need to use this outside of the pubsub package. GetPubSub func() interface{} // TakeSnapshot triggers a snapshot by the SugarDB instance. TakeSnapshot func() error // RewriteAOF triggers a compaction of the commands logs by the SugarDB instance. RewriteAOF func() error // GetLatestSnapshotTime returns the latest snapshot timestamp. GetLatestSnapshotTime func() int64 // LoadModule loads the provided module with the given args passed to the module's // key extraction and handler functions. LoadModule func(path string, args ...string) error // UnloadModule removes the specified module. // This unloads both custom modules and internal modules. UnloadModule func(module string) // ListModules returns the list of modules loaded in the SugarDB instance. ListModules func() []string // SetConnectionInfo sets the connection's protocol and clientname. SetConnectionInfo func(conn *net.Conn, clientname string, protocol int, database int) // GetConnectionInfo returns information about the current connection. GetConnectionInfo func(conn *net.Conn) ConnectionInfo // GetServerInfo returns information about the server when requested by commands such as HELLO. GetServerInfo func() ServerInfo // SwapDBs swaps two databases, // so that immediately all the clients connected to a given database will see the data of the other database, // and the other way around. SwapDBs func(database1, database2 int) // FlushDB flushes the specified database keys. It accepts the integer index of the database to be flushed. // If -1 is passed as the index, then all databases will be flushed. Flush func(database int) // RandomKey returns a random key RandomKey func(ctx context.Context) string // DBSize returns the number of keys in the currently selected database. DBSize func(ctx context.Context) int // (TOUCH key [key ...]) Alters the last access time or access count of the key(s) // depending on whether LFU or LRU strategy was used. // A key is ignored if it does not exist. TouchKey func(ctx context.Context, keys []string) (int64, error) // GetObjectFrequency retrieves the access frequency count of a key. Can only be used with LFU type eviction policies. GetObjectFrequency func(ctx context.Context, keys string) (int, error) // GetObjectIdleTime retrieves the time in seconds since the last access of a key. // Can only be used with LRU type eviction policies. GetObjectIdleTime func(ctx context.Context, keys string) (float64, error) // AddScript adds a script to SugarDB that isn't associated with a command. // This script is triggered using the EVAL or EVALSHA commands. // engine defines the interpreter to be used. Possible values: "LUA" // scriptType is either "FILE" or "RAW". // content contains the file path if scriptType is "FILE" and the raw script if scriptType is "RAW" AddScript func(engine string, scriptType string, content string, args []string) error }
HandlerFuncParams is the object passed to a command handler when a command is triggered. These params are provided to commands by the SugarDB engine to help the command hook into functions from the echovault package.
type KeyExtractionFunc ¶
type KeyExtractionFunc func(cmd []string) (KeyExtractionFuncResult, error)
KeyExtractionFunc is included with every command/subcommand. This function returns a KeyExtractionFuncResult object. The return value of this function is used in the ACL layer to determine whether the connection is allowed to execute this command. The cmd parameter is a string slice of the command. All the keys are extracted from this command.
type KeyExtractionFuncResult ¶
type KeyExtractionFuncResult struct { Channels []string // The pubsub channels the command accesses. For non pubsub commands, this should be an empty slice. ReadKeys []string // The keys the command reads from. If no keys are read, this should be an empty slice. WriteKeys []string // The keys the command writes to. If no keys are written to, this should be an empty slice. }
KeyExtractionFuncResult is the return type of the KeyExtractionFunc for the command/subcommand.
type ServerInfo ¶
type ServerInfo struct { Server string Version string Id string Mode string Role string Modules []string MemoryUsed int64 MaxMemory uint64 }
ServerInfo holds information about the server/node.
type SnapshotObject ¶
type SubCommand ¶
type SubCommand struct { Command string // The keyword for this subcommand. (Check the acl module for an example of subcommands within a command). Module string // The module this subcommand belongs to. Should be the same as the parent command. Categories []string // The ACL categories the subcommand belongs to. Description string // The description of the subcommand. Includes syntax. Sync bool // Specifies if sub-command should be synced across replication cluster. KeyExtractionFunc HandlerFunc }
Directories
¶
Path | Synopsis |
---|---|
Package aof handles AOF logging in standalone mode only.
|
Package aof handles AOF logging in standalone mode only. |
modules
|
|
volumes
|
|