echovault

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() config.Config

DefaultConfig returns the default configuration. This should be used when using EchoVault as an embedded library.

func WithConfig

func WithConfig(config config.Config) func(echovault *EchoVault)

WithConfig is an option for the NewEchoVault function that allows you to pass a custom configuration to EchoVault. If not specified, EchoVault will use the default configuration from config.DefaultConfig().

func WithContext

func WithContext(ctx context.Context) func(echovault *EchoVault)

WithContext is an options that for the NewEchoVault function that allows you to configure a custom context object to be used in EchoVault. If you don't provide this option, EchoVault will create its own internal context object.

Types

type ACLLoadOptions

type ACLLoadOptions struct {
	Merge   bool
	Replace bool
}

ACLLoadOptions modifies the behaviour of the ACLLoad function. If Merge is true, the ACL configuration from the file will be merged with the in-memory ACL configuration. If Replace is set to true, the ACL configuration from the file will replace the in-memory ACL configuration. If both flags are set to true, Merge will be prioritised.

type CommandHandlerFunc

type CommandHandlerFunc func(params CommandHandlerFuncParams) ([]byte, error)

CommandHandlerFunc is the handler function for the command or subcommand.

This function must return a byte slice containing a valid RESP2 response, or an error.

type CommandHandlerFuncParams

type CommandHandlerFuncParams struct {
	Context          context.Context
	Command          []string
	KeyExists        func(ctx context.Context, key string) bool
	CreateKeyAndLock func(ctx context.Context, key string) (bool, error)
	KeyLock          func(ctx context.Context, key string) (bool, error)
	KeyUnlock        func(ctx context.Context, key string)
	KeyRLock         func(ctx context.Context, key string) (bool, error)
	KeyRUnlock       func(ctx context.Context, key string)
	GetValue         func(ctx context.Context, key string) interface{}
	SetValue         func(ctx context.Context, key string, value interface{}) error
}

CommandHandlerFuncParams contains the helper parameters passed to the command's handler by EchoVault.

Command is the string slice command containing the command that triggered this handler.

KeyExists returns true if the key passed to it exists in the store.

CreateKeyAndLock creates the new key and immediately write locks it. If the key already exists, then it is simply write locked which makes this function safe to call even if the key already exists. Always call KeyUnlock when done after CreateKeyAndLock.

KeyLock acquires a write lock for the specified key. If the lock is successfully acquired, the function will return (true, nil). Otherwise, it will return false and an error describing why the locking failed. Always call KeyUnlock when done after KeyLock.

KeyUnlock releases the write lock for the specified key. Always call this after KeyLock otherwise the key will not be lockable by any future invocations of this command or other commands.

KeyRLock acquires a read lock for the specified key. If the lock is successfully acquired, the function will return (true, nil). Otherwise, it will return false and an error describing why the locking failed. Always call KeyRUnlock when done after KeyRLock.

KeyRUnlock releases the real lock for the specified key. Always call this after KeyRLock otherwise the key will not be write-lockable by any future invocations of this command or other commands.

GetValue returns the value held at the specified key as an interface{}. Make sure to invoke KeyLock or KeyRLock on the key before GetValue to ensure thread safety.

SetValue sets the value at the specified key. Make sure to invoke KeyLock on the key before SetValue to ensure thread safety.

type CommandKeyExtractionFunc

type CommandKeyExtractionFunc func(cmd []string) (CommandKeyExtractionFuncResult, error)

CommandKeyExtractionFunc if the function that extracts the keys accessed by the command or subcommand.

type CommandKeyExtractionFuncResult

type CommandKeyExtractionFuncResult struct {
	ReadKeys  []string
	WriteKeys []string
}

CommandKeyExtractionFuncResult specifies the keys accessed by the associated command or subcommand. ReadKeys is a string slice containing the keys that the commands read from. WriteKeys is a string slice containing the keys that the command writes to.

These keys will typically be extracted from the command slice, but they can also be hardcoded.

type CommandListOptions

type CommandListOptions struct {
	ACLCAT  string
	PATTERN string
	MODULE  string
}

CommandListOptions modifies the result from the CommandList command.

ACLCAT filters the results by the provided category. Has the highest priority.

PATTERN filters the result that match the given glob pattern. Has the second-highest priority.

MODULE filters the result by the provided module. Has the lowest priority.

type CommandOptions

type CommandOptions struct {
	Command           string
	Module            string
	Categories        []string
	Description       string
	SubCommand        []SubCommandOptions
	Sync              bool
	KeyExtractionFunc CommandKeyExtractionFunc
	HandlerFunc       CommandHandlerFunc
}

CommandOptions provides the specification of the command to be added to the EchoVault instance.

Command is the keyword used to trigger this command (e.g. LPUSH, ZADD, ACL ...).

Module is a string that classifies a group of commands.

Categories is a string slice of all the categories that this command belongs to.

Description is a string describing the command, can include an example of how to trigger the command.

SubCommand is a slice of subcommands for this command.

Sync is a boolean value that determines whether this command should be synced across a replication cluster. If subcommands are specified, each subcommand will override this value for its own execution.

KeyExtractionFunc is a function that extracts the keys from the command if the command accesses any keys. the extracted keys are used by the ACL layer to determine whether a TCP client is authorized to execute this command. If subcommands are specified, this function is discarded and each subcommands must implement its own KeyExtractionFunc.

HandlerFunc is the command handler. This function must return a valid RESP2 response as it the command will be available to RESP clients. If subcommands are specified, this function is discarded and each subcommand must implement its own HandlerFunc.

type EchoVault

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

func NewEchoVault

func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error)

NewEchoVault creates a new EchoVault instance. This functions accepts the WithContext, WithConfig and WithCommands options.

func (*EchoVault) ACLCat

func (server *EchoVault) ACLCat(category ...string) ([]string, error)

ACLCat returns either the list of all categories or the list of commands within a specified category.

Parameters:

`category` - ...string - an optional string specifying the category. If more than one category is passed, only the first one will be used.

Returns: string slice of categories loaded in EchoVault if category is not specified. Otherwise, returns string slice of commands within the specified category.

Errors:

"category <category> not found" - when the provided category is not found in the loaded commands.

func (*EchoVault) ACLDelUser

func (server *EchoVault) ACLDelUser(usernames ...string) (bool, error)

ACLDelUser deletes all the users with the specified usernames.

Parameters:

`usernames` - ...string - A string of usernames to delete from the ACL module.

Returns: true if the deletion is successful.

func (*EchoVault) ACLGetUser

func (server *EchoVault) ACLGetUser(username string) (map[string][]string, error)

ACLGetUser gets the ACL configuration of the name with the given username.

Parameters:

`username` - string - the username whose ACL rules you'd like to retrieve.

Returns: A map[string][]string map where each key is the rule category and each value is a string slice of relevant values. The map returned has the following structure:

"username" - string slice containing the user's username.

"flags" - string slices containing the following values: "on" if the user is enabled, otherwise "off", "nokeys" if the user is not allowed to access any keys (and NoKeys is true), "nopass" if the user has no passwords (and NoPass is true).

"categories" - string slice af ACL command categories associated with the user. If the user is allowed to access all categories, it will contain "+@*". For each category the user is allowed to access, the slice will contain "+@<category>". If the user is not allowed to access any categories, it will contain "-@*". For each category the user is not allowed to access, the slice will contain "-@<category>".

"commands" - string slice af commands associated with the user. If the user is allowed to execute all commands, it will contain "+all". For each command the user is allowed to execute, the slice will contain "+<command>". If the user is not allowed to execute any commands, it will contain "-all". For each command the user is not allowed to execute, the slice will contain "-<category>".

"keys" - string slice af keys associated with the user. If the user is allowed read/write access all keys, the slice will contain "%RW~*". For each key glob pattern the user has read/write access to, the slice will contain "%RW~<pattern>". If the user is allowed read access to all keys, the slice will contain "%R~*". For each key glob pattern the user has read access to, the slice will contain "%R~<pattern>". If the user is allowed write access to all keys, the slice will contain "%W~*". For each key glob pattern the user has write access to, the slice will contain "%W~<pattern>".

"channels" - string slice af pubsub channels associated with the user. If the user is allowed to access all channels, the slice will contain "+&*". For each channel the user is allowed to access, the slice will contain "+&<channel>". If the user is not allowed to access any channels, the slice will contain "-&*". For each channel the user is not allowed to access, the slice will contain "-&<channel>".

Errors:

"user not found" - if the user requested does not exist in the ACL rules.

func (*EchoVault) ACLList

func (server *EchoVault) ACLList() ([]string, error)

ACLList lists all the currently loaded ACL users and their rules.

func (*EchoVault) ACLLoad

func (server *EchoVault) ACLLoad(options ACLLoadOptions) (bool, error)

ACLLoad loads the ACL configuration from the configured ACL file. The load function can either merge the loaded config with the in-memory config, or replace the in-memory config with the loaded config entirely.

Parameters:

`options` - ACLLoadOptions - modifies the load behaviour.

Returns: true if the load is successful.

func (*EchoVault) ACLSave

func (server *EchoVault) ACLSave() (bool, error)

ACLSave saves the current ACL configuration to the configured ACL file.

Returns: true if the save is successful.

func (*EchoVault) ACLSetUser

func (server *EchoVault) ACLSetUser(user User) (bool, error)

ACLSetUser modifies or creates a new user. If the user with the specified username exists, the ACL user will be modified. Otherwise, a new User is created.

Parameters:

`user` - User - The user object to add/update.

Returns: true if the user is successfully created/updated.

func (*EchoVault) ACLUsers

func (server *EchoVault) ACLUsers() ([]string, error)

ACLUsers returns a string slice containing the usernames of all the loaded users in the ACL module.

func (*EchoVault) AddCommand

func (server *EchoVault) AddCommand(command CommandOptions) error

AddCommand adds a new command to EchoVault. The added command can be executed using the ExecuteCommand method.

Parameters:

`command` - CommandOptions.

Errors:

"command <command> already exists" - If a command with the same command name as the passed command already exists.

func (*EchoVault) CommandCount

func (server *EchoVault) CommandCount() (int, error)

CommandCount returns the number of commands currently loaded in the EchoVault instance.

Returns: integer representing the count of all available commands.

func (*EchoVault) CommandList

func (server *EchoVault) CommandList(options CommandListOptions) ([]string, error)

CommandList returns the list of commands currently loaded in the EchoVault instance.

Parameters:

`options` - CommandListOptions.

Returns: a string slice of all the loaded commands. SubCommands are represented as "command|subcommand".

func (*EchoVault) CreateKeyAndLock

func (server *EchoVault) CreateKeyAndLock(ctx context.Context, key string) (bool, error)

CreateKeyAndLock creates a new key lock and immediately locks it if the key does not exist. If the key exists, the existing key is locked.

If this functions is called on a node in a replication cluster, the key is only created/locked on that particular node.

func (*EchoVault) Del

func (server *EchoVault) Del(keys ...string) (int, error)

Del removes the given keys from the store.

Parameters:

`keys` - []string - the keys to delete from the store.

Returns: The number of keys that were successfully deleted.

func (*EchoVault) DeleteKey

func (server *EchoVault) DeleteKey(ctx context.Context, key string) error

DeleteKey removes the key from store, keyLocks and keyExpiry maps.

If this functions is called on a node in a replication cluster, the key is only deleted on that particular node.

func (*EchoVault) ExecuteCommand

func (server *EchoVault) ExecuteCommand(command ...string) ([]byte, error)

ExecuteCommand executes the command passed to it. If 1 string is passed, EchoVault will try to execute the command. If 2 strings are passed, EchoVault will attempt to execute the subcommand of the command. If more than 2 strings are provided, all additional strings will be ignored.

This method returns the raw RESP response from the command handler. You will have to parse the RESP response if you want to use the return value from the handler.

This method does not work with handlers that manipulate the client connection directly (i.e SUBSCRIBE, PSUBSCRIBE). If you'd like to (p)subscribe or (p)unsubscribe, use the (P)SUBSCRIBE and (P)UNSUBSCRIBE methods instead.

Parameters:

`command` - ...string.

Returns: []byte - Raw RESP response returned by the command handler.

Errors:

All errors from the command handler are forwarded to the caller. Other errors returned include:

"command <command> not supported" - If the command does not exist.

"command <command> <subcommand> not supported" - If the command exists but the subcommand does not exist for that command.

func (*EchoVault) Expire

func (server *EchoVault) Expire(key string, seconds int, options ExpireOptions) (bool, error)

Expire set the given key's expiry in seconds from now. This command turns a persistent key into a volatile one.

Parameters:

`key` - string.

`seconds` - int - number of seconds from now.

`options` - ExpireOptions

Returns: true if the key's expiry was successfully updated.

func (*EchoVault) ExpireAt

func (server *EchoVault) ExpireAt(key string, unixSeconds int, options ExpireAtOptions) (int, error)

ExpireAt set the given key's expiry in unix epoch seconds. This command turns a persistent key into a volatile one.

Parameters:

`key` - string.

`unixSeconds` - int - number of seconds from now.

`options` - ExpireAtOptions

Returns: true if the key's expiry was successfully updated.

func (*EchoVault) ExpireTime

func (server *EchoVault) ExpireTime(key string) (int, error)

ExpireTime return the current key's expiry time in unix epoch seconds.

Parameters:

`key` - string.

Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.

func (*EchoVault) Get

func (server *EchoVault) Get(key string) (string, error)

Get retrieves the value at the provided key.

Parameters:

`key` - string - the key whose value should be retrieved.

Returns: A string representing the value at the specified key. If the value does not exist, an empty string is returned.

func (*EchoVault) GetExpiry

func (server *EchoVault) GetExpiry(ctx context.Context, key string) time.Time

The GetExpiry function returns the expiry time associated with the provided key. The key must be read locked before calling this function.

func (*EchoVault) GetRange

func (server *EchoVault) GetRange(key string, start, end int) (string, error)

GetRange works the same as SubStr.

func (*EchoVault) GetValue

func (server *EchoVault) GetValue(ctx context.Context, key string) interface{}

GetValue retrieves the current value at the specified key. The key must be read-locked before calling this function.

func (*EchoVault) HDel

func (server *EchoVault) HDel(key string, fields ...string) (int, error)

HDel delete 1 or more fields from a hash map.

Parameters:

`key` - string - the key to the hash map.

`fields` - ...string - a list of fields to delete.

Returns: an integer representing the number of fields deleted.

Errors:

"value at <key> is not a hash" - when the provided key does not exist or is not a hash.

func (*EchoVault) HExists

func (server *EchoVault) HExists(key, field string) (bool, error)

HExists checks if a field exists in a hash map.

Parameters:

`key` - string - the key to the hash map.

`field` - string - the field to check.

Returns: a boolean representing whether the field exists in the hash map. Returns 0 if the hash map does not exist.

Errors:

"value at <key> is not a hash" - when the provided key does not exist or is not a hash.

func (*EchoVault) HGet added in v0.6.0

func (server *EchoVault) HGet(key string, fields ...string) ([]string, error)

HGet retrieves the values corresponding to the provided fields.

Parameters:

`key` - string - the key to the hash map.

`fields` - ...string - the list of fields to fetch.

Returns: A string slice of the values corresponding to the fields in the same order the fields were provided.

Errors:

"value at <key> is not a hash" - when the provided key does not exist or is not a hash.

func (*EchoVault) HGetAll

func (server *EchoVault) HGetAll(key string) ([]string, error)

HGetAll returns a flattened slice of all keys and values in a hash map.

Parameters:

`key` - string - the key to the hash map.

Returns: a flattened string slice where every second element is a value preceded by its corresponding key. If the key does not exist, an empty slice is returned.

Errors:

"value at <key> is not a hash" - when the provided key does not exist or is not a hash.

func (*EchoVault) HIncrBy

func (server *EchoVault) HIncrBy(key, field string, increment int) (float64, error)

HIncrBy increment the value of the hash map at the given field by an integer. If the hash map does not exist, a new hash map is created with the field and increment as the value.

Parameters:

`key` - string - the key to the hash map.

`field` - string - the field of the value to increment.

Returns: a float representing the new value of the field.

Errors:

"value at <key> is not a hash" - when the provided key does not exist or is not a hash.

"value at field <field> is not a number" - when the field holds a value that is not a number.

func (*EchoVault) HIncrByFloat

func (server *EchoVault) HIncrByFloat(key, field string, increment float64) (float64, error)

HIncrByFloat behaves like HIncrBy but with a float increment instead of an integer increment.

func (*EchoVault) HKeys

func (server *EchoVault) HKeys(key string) ([]string, error)

HKeys returns all the keys in a hash map.

Parameters:

`key` - string - the key to the hash map.

Returns: a string slice with all the keys of the hash map. If the key does not exist, an empty slice is returned.

Errors:

"value at <key> is not a hash" - when the provided key does not exist or is not a hash.

func (*EchoVault) HLen

func (server *EchoVault) HLen(key string) (int, error)

HLen returns the length of the hash map.

Parameters:

`key` - string - the key to the hash map.

Returns: an integer representing the length of the hash map. If the key does not exist, 0 is returned.

Errors:

"value at <key> is not a hash" - when the provided key does not exist or is not a hash.

func (*EchoVault) HRandField

func (server *EchoVault) HRandField(key string, options HRandFieldOptions) ([]string, error)

HRandField returns a random list of fields from the hash map.

Parameters:

`key` - string - the key to the hash map.

`options` - HRandFieldOptions

Returns: a string slice containing random fields of the hash map. If the key does not exist, an empty slice is returned.

Errors:

"value at <key> is not a hash" - when the provided key does not exist or is not a hash.

func (*EchoVault) HSet

func (server *EchoVault) HSet(key string, fieldValuePairs map[string]string) (int, error)

HSet creates or modifies a hash map with the values provided. If the hash map does not exist it will be created.

Parameters:

`key` - string - the key to the hash map.

`fieldValuePairs` - map[string]string - a hash used to update or create the hash. Existing fields will be updated with the new values. Non-existent fields will be created.

Returns: The number of fields that were updated/created.

Errors:

"value at <key> is not a hash" - when the provided key exists but is not a hash.

func (*EchoVault) HSetNX

func (server *EchoVault) HSetNX(key string, fieldValuePairs map[string]string) (int, error)

HSetNX modifies an existing hash map with the values provided. This function will only be successful if the hash map already exists.

Parameters:

`key` - string - the key to the hash map.

`fieldValuePairs` - map[string]string - a hash used to update the hash. Existing fields will be updated with the new values. Non-existent fields will be created.

Returns: The number of fields that were updated/created.

Errors:

"value at <key> is not a hash" - when the provided key does not exist or is not a hash.

func (*EchoVault) HStrLen

func (server *EchoVault) HStrLen(key string, fields ...string) ([]int, error)

HStrLen returns the length of the values held at the specified fields of a hash map.

Parameters:

`key` - string - the key to the hash map.

`fields` - ...string - the list of fields to whose values lengths will be checked.

Returns: and integer slice representing the lengths of the strings at the corresponding fields index. Non-existent fields will have length 0. If the key does not exist, an empty slice is returned.

Errors:

"value at <key> is not a hash" - when the provided key does not exist or is not a hash.

func (*EchoVault) HVals

func (server *EchoVault) HVals(key string) ([]string, error)

HVals returns all the values in a hash map.

Parameters:

`key` - string - the key to the hash map.

Returns: a string slice with all the values of the hash map. If the key does not exist, an empty slice is returned.

Errors:

"value at <key> is not a hash" - when the provided key does not exist or is not a hash.

func (*EchoVault) KeyExists

func (server *EchoVault) KeyExists(ctx context.Context, key string) bool

KeyExists returns true if the key exists in the store.

If the key is volatile and expired, checking for its existence with KeyExists will trigger a key deletion and then return false. If the key is determined to be expired by KeyExists, it will be evicted across the entire replication cluster.

func (*EchoVault) KeyLock

func (server *EchoVault) KeyLock(ctx context.Context, key string) (bool, error)

KeyLock tries to acquire the write lock for the specified key. If the context passed to the function finishes before the lock is acquired, an error is returned.

If this functions is called on a node in a replication cluster, the key is only locked on that particular node.

func (*EchoVault) KeyRLock

func (server *EchoVault) KeyRLock(ctx context.Context, key string) (bool, error)

KeyRLock tries to acquire the read lock for the specified key. If the context passed to the function finishes before the lock is acquired, an error is returned.

If this functions is called on a node in a replication cluster, the key is only locked on that particular node.

func (*EchoVault) KeyRUnlock

func (server *EchoVault) KeyRUnlock(_ context.Context, key string)

KeyRUnlock releases the read lock for the specified key.

If this functions is called on a node in a replication cluster, the key is only unlocked on that particular node.

func (*EchoVault) KeyUnlock

func (server *EchoVault) KeyUnlock(_ context.Context, key string)

KeyUnlock releases the write lock for the specified key.

If this functions is called on a node in a replication cluster, the key is only unlocked on that particular node.

func (*EchoVault) LIndex

func (server *EchoVault) LIndex(key string, index uint) (string, error)

LIndex retrieves the element at the provided index from the list without removing it.

Parameters:

`key` - string - the key to the list.

`index` - int - the index to retrieve from.

Returns: The element at the given index as a string.

Errors:

"LIndex command on non-list item" - when the provided key exists but is not a list.

"index must be within list range" - when the index is not within the list boundary.

func (*EchoVault) LLen

func (server *EchoVault) LLen(key string) (int, error)

LLen returns the length of the list.

Parameters:

`key` - string - the key to the list.

Returns: The length of the list as an integer. Returns 0 if the key does not exist.

Errors:

"LLen command on non-list item" - when the provided key exists but is not a list.

func (*EchoVault) LMove

func (server *EchoVault) LMove(source, destination, whereFrom, whereTo string) (bool, error)

LMove moves an element from one list to another.

Parameters:

`source` - string - the key to the source list.

`destination` - string - the key to the destination list.

`whereFrom` - string - either "LEFT" or "RIGHT". If "LEFT", the element is removed from the beginning of the source list. If "RIGHT", the element is removed from the end of the source list.

`whereTo` - string - either "LEFT" or "RIGHT". If "LEFT", the element is added to the beginning of the destination list. If "RIGHT", the element is added to the end of the destination list.

Returns: true if the removal was successful.

Errors:

"both source and destination must be lists" - when either source or destination are not lists.

"wherefrom and whereto arguments must be either LEFT or RIGHT" - if whereFrom or whereTo are not either "LEFT" or "RIGHT".

func (*EchoVault) LPop

func (server *EchoVault) LPop(key string) (string, error)

LPop pops an element from the start of the list and return it.

Parameters:

`key` - string - the key to the list.

Returns: The popped element as a string.

Errors:

"LPop command on non-list item" - when the provided key is not a list.

func (*EchoVault) LPush

func (server *EchoVault) LPush(key string, values ...string) (int, error)

LPush pushed 1 or more values to the beginning of a list. If the list does not exist, a new list is created wth the passed elements as its members.

Parameters:

`key` - string - the key to the list.

`values` - ...string - the list of elements to add to push to the beginning of the list.

Returns: An integer with the length of the new list.

Errors:

"LPush command on non-list item" - when the provided key is not a list.

func (*EchoVault) LPushX

func (server *EchoVault) LPushX(key string, values ...string) (int, error)

LPushX pushed 1 or more values to the beginning of an existing list. The command only succeeds on a pre-existing list.

Parameters:

`key` - string - the key to the list.

`values` - ...string - the list of elements to add to push to the beginning of the list.

Returns: An integer with the length of the new list.

Errors:

"LPushX command on non-list item" - when the provided key is not a list or doesn't exist.

func (*EchoVault) LRange

func (server *EchoVault) LRange(key string, start, end int) ([]string, error)

LRange returns the elements within the index range provided.

Parameters:

`key` - string - the key to the list.

`start` - int - the start index. If start index is less than end index, the returned sub-list will be reversed.

`end` - int - the end index. When -1 is passed for end index, the function will return the list from start index to the end of the list.

Returns: A string slice containing the elements within the given indices.

Errors:

"LRange command on non-list item" - when the provided key exists but is not a list.

"start index must be within list boundary" - when the start index is not within the list boundaries.

"end index must be within list range or -1" - when end index is not within the list boundaries.

func (*EchoVault) LRem

func (server *EchoVault) LRem(key string, count int, value string) (bool, error)

LRem removes 'count' instances of the specified element from the list.

Parameters:

`key` - string - the key to the list.

`count` - int - the number of instances of the element to remove.

`value` - string - the element to remove.

Returns: true if the removal was successful.

Errors:

"LRem command on non-list item" - when the provided key exists but is not a list.

func (*EchoVault) LSet

func (server *EchoVault) LSet(key string, index int, value string) (bool, error)

LSet updates the value at the given index of a list.

Parameters:

`key` - string - the key to the list.

`index` - int - the index to retrieve from.

`value` - string - the new value to place at the given index.

Returns: true if the update is successful.

Errors:

"LSet command on non-list item" - when the provided key exists but is not a list.

"index must be within list range" - when the index is not within the list boundary.

func (*EchoVault) LTrim

func (server *EchoVault) LTrim(key string, start int, end int) (bool, error)

LTrim work similarly to LRange but instead of returning the new list, it replaces the original list with the trimmed list.

Returns: true if the trim is successful.

func (*EchoVault) LastSave

func (server *EchoVault) LastSave() (int, error)

LastSave returns the unix epoch milliseconds timestamp of the last save.

func (*EchoVault) ListModules

func (server *EchoVault) ListModules() []string

ListModules lists the currently loaded modules

Returns: a string slice representing all the currently loaded modules.

func (*EchoVault) LoadModule

func (server *EchoVault) LoadModule(path string, args ...string) error

LoadModule loads an external module into EchoVault ar runtime.

Parameters:

`path` - string - The full path to the .so plugin to be loaded.

`args` - ...string - A list of args that will be passed unmodified to the plugins command's KeyExtractionFunc and HandlerFunc

func (*EchoVault) MGet

func (server *EchoVault) MGet(keys ...string) ([]string, error)

MGet get multiple values from the list of provided keys. The index of each value corresponds to the index of its key in the parameter slice. Values that do not exist will be an empty string.

Parameters:

`keys` - []string - a string slice of all the keys.

Returns: a string slice of all the values.

func (*EchoVault) MSet

func (server *EchoVault) MSet(kvPairs map[string]string) (bool, error)

MSet set multiple values at multiple keys with one command. Existing keys are overwritten and non-existent keys are created.

Parameters:

`kvPairs` - map[string]string - a map representing all the keys and values to be set.

Returns: true if the set is successful.

Errors:

"key <key> already exists" - when the NX flag is set to true and the key already exists.

func (*EchoVault) PExpire

func (server *EchoVault) PExpire(key string, milliseconds int, options PExpireOptions) (bool, error)

PExpire set the given key's expiry in milliseconds from now. This command turns a persistent key into a volatile one.

Parameters:

`key` - string.

`milliseconds` - int - number of seconds from now.

`options` - PExpireOptions

Returns: true if the key's expiry was successfully updated.

func (*EchoVault) PExpireAt

func (server *EchoVault) PExpireAt(key string, unixMilliseconds int, options PExpireAtOptions) (int, error)

PExpireAt set the given key's expiry in unix epoch milliseconds. This command turns a persistent key into a volatile one.

Parameters:

`key` - string.

`unixMilliseconds` - int - number of seconds from now.

`options` - PExpireAtOptions

Returns: true if the key's expiry was successfully updated.

func (*EchoVault) PExpireTime

func (server *EchoVault) PExpireTime(key string) (int, error)

PExpireTime return the current key's expiry time in unix epoch milliseconds.

Parameters:

`key` - string.

Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.

func (*EchoVault) PSubscribe

func (server *EchoVault) PSubscribe(tag string, patterns ...string) ReadPubSubMessage

PSubscribe subscribes the caller to the list of provided glob patterns.

Parameters:

`tag` - string - The tag used to identify this subscription instance.

`patterns` - ...string - The list of glob patterns to subscribe to.

Returns: ReadPubSubMessage function which reads the next message sent to the subscription instance. This function is blocking.

func (*EchoVault) PTTL

func (server *EchoVault) PTTL(key string) (int, error)

PTTL return the current key's expiry time from now in milliseconds.

Parameters:

`key` - string.

Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.

func (*EchoVault) PUnsubscribe

func (server *EchoVault) PUnsubscribe(tag string, patterns ...string)

PUnsubscribe unsubscribes the caller from the given glob patterns.

Parameters:

`tag` - string - The tag used to identify this subscription instance.

`patterns` - ...string - The list of glob patterns to unsubscribe from.

func (*EchoVault) Persist

func (server *EchoVault) Persist(key string) (bool, error)

Persist removes the expiry associated with a key and makes it permanent. Has no effect on a key that is already persistent.

Parameters:

`key` - string - the key to persist.

Returns: true if the keys is successfully persisted.

func (*EchoVault) PubSubChannels

func (server *EchoVault) PubSubChannels(pattern string) ([]string, error)

PubSubChannels returns the list of channels & patterns that match the glob pattern provided.

Parameters:

`pattern` - string - The glob pattern used to match the channel names.

Returns: A string slice of all the active channels and patterns (i.e. channels and patterns that have 1 or more subscribers).

func (*EchoVault) PubSubNmSub

func (server *EchoVault) PubSubNmSub(channels ...string) (map[string]int, error)

PubSubNmSub returns the number of subscribers for each of the specified channels.

Parameters:

`channels` - ...string - The list of channels whose number of subscribers is to be checked.

Returns: A map of map[string]int where the key is the channel name and the value is the number of subscribers.

func (*EchoVault) PubSubNumPat

func (server *EchoVault) PubSubNumPat() (int, error)

PubSubNumPat returns the list of active patterns.

Returns: An integer representing the number of all the active patterns (i.e. patterns that have 1 or more subscribers).

func (*EchoVault) Publish

func (server *EchoVault) Publish(channel, message string) (bool, error)

Publish publishes a message to the given channel.

Parameters:

`channel` - string - The channel to publish the message to.

`message` - string - The message to publish to the specified channel.

Returns: true when the publish is successful. This does not indicate whether each subscriber has received the message, only that the message has been published.

func (*EchoVault) RPop

func (server *EchoVault) RPop(key string) (string, error)

RPop pops an element from the end of the list and return it.

Parameters:

`key` - string - the key to the list.

Returns: The popped element as a string.

Errors:

"RPop command on non-list item" - when the provided key is not a list.

func (*EchoVault) RPush

func (server *EchoVault) RPush(key string, values ...string) (int, error)

RPush pushed 1 or more values to the end of a list. If the list does not exist, a new list is created wth the passed elements as its members.

Parameters:

`key` - string - the key to the list.

`values` - ...string - the list of elements to add to push to the end of the list.

Returns: An integer with the length of the new list.

Errors:

"RPush command on non-list item" - when the provided key is not a list.

func (*EchoVault) RPushX

func (server *EchoVault) RPushX(key string, values ...string) (int, error)

RPushX pushed 1 or more values to the end of an existing list. The command only succeeds on a pre-existing list.

Parameters:

`key` - string - the key to the list.

`values` - ...string - the list of elements to add to push to the end of the list.

Returns: An integer with the length of the new list.

Errors:

"RPushX command on non-list item" - when the provided key is not a list or doesn't exist.

func (*EchoVault) RemoveCommand

func (server *EchoVault) RemoveCommand(command ...string)

RemoveCommand removes the specified command or subcommand from EchoVault. When commands are removed, they will no longer be available for both the embedded instance and for TCP clients.

Note: If a command is removed, the API wrapper for the command will also be unusable. For example, calling RemoveCommand("LPUSH") will cause the LPUSH method to always return a "command LPUSH not supported" error so use this method with caution.

If one string is passed, the command matching that string is removed along will all of its subcommand if it has any. If two strings are passed, only the subcommand of the specified command is removed. If more than 2 strings are passed, all additional strings are ignored.

Parameters:

`command` - ...string.

func (*EchoVault) RemoveExpiry

func (server *EchoVault) RemoveExpiry(_ context.Context, key string)

RemoveExpiry is called by commands that remove key expiry (e.g. Persist). The key must be locked prior ro calling this function.

func (*EchoVault) RewriteAOF

func (server *EchoVault) RewriteAOF() (string, error)

RewriteAOF triggers a compaction of the AOF file.

func (*EchoVault) SAdd

func (server *EchoVault) SAdd(key string, members ...string) (int, error)

SAdd adds member(s) to a set. If the set does not exist, a new sorted set is created with the member(s).

Parameters:

`key` - string - the key to update.

`members` - ...string - a list of members to add to the set.

Returns: The number of members added.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

func (*EchoVault) SCard

func (server *EchoVault) SCard(key string) (int, error)

SCard Returns the cardinality of the set.

Parameters:

`key` - string - the key to update.

Returns: The cardinality of a set. Returns 0 if the key does not exist.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

func (*EchoVault) SDiff

func (server *EchoVault) SDiff(keys ...string) ([]string, error)

SDiff Calculates the difference between the provided sets. Keys that don't exist or that are not sets will be skipped.

Parameters:

`keys` - ...string - the keys of the sets from which to calculate the difference.

Returns: A string slice representing the elements resulting from calculating the difference.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

"key for base set <key> does not exist" - if the first key is not a set.

func (*EchoVault) SDiffStore

func (server *EchoVault) SDiffStore(destination string, keys ...string) (int, error)

SDiffStore works like SDiff but instead of returning the resulting set elements, the resulting set is stored at the 'destination' key.

Returns: an integer representing the cardinality of the new set.

func (*EchoVault) SInter

func (server *EchoVault) SInter(keys ...string) ([]string, error)

SInter Calculates the intersection between the provided sets. If any of the keys does not exist, then there is no intersection.

Parameters:

`keys` - ...string - the keys of the sets from which to calculate the intersection.

Returns: A string slice representing the elements resulting from calculating the intersection.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

"not enough sets in the keys provided" - when only one of the provided keys is a valid set.

func (*EchoVault) SInterCard

func (server *EchoVault) SInterCard(keys []string, limit uint) (int, error)

SInterCard Calculates the cardinality of the intersection between the sets provided.

Parameters:

`keys` - []string - The keys of the sets from which to calculate the intersection.

`limit` - int - When limit is > 0, the intersection calculation will be terminated as soon as the limit is reached.

Returns: The cardinality of the calculated intersection.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

"not enough sets in the keys provided" - when only one of the provided keys is a valid set.

func (*EchoVault) SInterStore

func (server *EchoVault) SInterStore(destination string, keys ...string) (int, error)

SInterStore works the same as SInter but instead of returning the elements in the resulting set, it is stored at the 'destination' key and the cardinality of the resulting set is returned.

func (*EchoVault) SMembers

func (server *EchoVault) SMembers(key string) ([]string, error)

SMembers Returns all the members of the specified set.

Parameters:

`key` - string - The key of the set.

Returns: A string slice of all the members in the set.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

func (*EchoVault) SMisMember

func (server *EchoVault) SMisMember(key string, members ...string) ([]bool, error)

SMisMember Returns the membership status of all the specified members.

Parameters:

`key` - string - The key of the set.

`members` - ...string - The members whose membership in the set will be checked.

Returns: A boolean slices with true/false based on whether the member in the corresponding index is present in the set.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

func (*EchoVault) SMove

func (server *EchoVault) SMove(source, destination, member string) (bool, error)

SMove Move the specified member from 'source' set to 'destination' set.

Parameters:

`source` - string - The key of the set to remove the element from.

`destination` - string - The key of the set to move the element to.

`member` - string - The member to move from the source set to destination set.

Returns: true if the member was successfully moved, false otherwise.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

"source is not a set" - when the source key does not hold a set.

"destination is not a set" - when the destination key does not hold a set.

func (*EchoVault) SPop

func (server *EchoVault) SPop(key string, count uint) ([]string, error)

SPop Pop one or more elements from the set.

Parameters:

`key` - string - The key of the set.

`count` - uint - number of elements to pop.

Returns: A string slice containing all the popped elements. If the key does not exist, an empty array is returned.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

func (*EchoVault) SRandMember

func (server *EchoVault) SRandMember(key string, count int) ([]string, error)

SRandMember Returns one or more random members from the set without removing them.

Parameters:

`key` - string - The key of the set.

`count` - int - number of elements to return. If count is negative, repeated elements are allowed. If the count is positive, all returned elements will be distinct.

Returns: A string slice containing the random elements. If the key does not exist, an empty array is returned.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

func (*EchoVault) SRem

func (server *EchoVault) SRem(key string, members ...string) (int, error)

SRem Remove one or more members from a set.

Parameters:

`key` - string - The key of the set.

`members` - ...string - List of members to remove. If the key does not exist, 0 is returned.

Returns: The number of elements successfully removed.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

func (*EchoVault) SUnion

func (server *EchoVault) SUnion(keys ...string) ([]string, error)

SUnion Calculates the union between the provided sets. Keys that don't exist or that are not sets will be skipped.

Parameters:

`keys` - ...string - the keys of the sets from which to calculate the union.

Returns: A string slice representing the elements resulting from calculating the union.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

func (*EchoVault) SUnionStore

func (server *EchoVault) SUnionStore(destination string, keys ...string) (int, error)

SUnionStore store works like SUnion but instead of returning the resulting elements, it stores the resulting set at the 'destination' key. The return value is an integer representing the cardinality of the new set.

Returns: an integer representing the cardinality of the new union set.

func (*EchoVault) Save

func (server *EchoVault) Save() (string, error)

Save triggers a new snapshot.

func (*EchoVault) Set

func (server *EchoVault) Set(key, value string, options SetOptions) (string, bool, error)

Set creates or modifies the value at the given key.

Parameters:

`key` - string - the key to create or update.

`value` - string - the value to place at the key.

`options` - SetOptions.

Returns: true if the set is successful, If the "Get" flag in SetOptions is set to true, the previous value is returned.

Errors:

"key <key> does not exist"" - when the XX flag is set to true and the key does not exist.

"key <key> does already exists" - when the NX flag is set to true and the key already exists.

func (*EchoVault) SetExpiry

func (server *EchoVault) SetExpiry(ctx context.Context, key string, expireAt time.Time, touch bool)

The SetExpiry receiver function sets the expiry time of a key. The key parameter represents the key whose expiry time is to be set/updated. The expireAt parameter is the new expiry time. The touch parameter determines whether to update the keys access count on lfu eviction policy, or the access time on lru eviction policy. The key must be locked prior to calling this function.

func (*EchoVault) SetRange

func (server *EchoVault) SetRange(key string, offset int, new string) (int, error)

SetRange replaces a portion of the string at the provided key starting at the offset with a new string. If the string does not exist, a new string is created.

Returns: The length of the new string as an integers.

Errors:

- "value at key <key> is not a string" when the key provided does not hold a string.

func (*EchoVault) SetValue

func (server *EchoVault) SetValue(ctx context.Context, key string, value interface{}) error

SetValue updates the value in the store at the specified key with the given value. If we're in not in cluster (i.e. in standalone mode), then the change count is incremented in the snapshot engine. This count triggers a snapshot when the threshold is reached. The key must be locked prior to calling this function.

func (*EchoVault) ShutDown

func (server *EchoVault) ShutDown()

ShutDown gracefully shuts down the EchoVault instance. This function shuts down the memberlist and raft layers.

func (*EchoVault) SisMember

func (server *EchoVault) SisMember(key, member string) (bool, error)

SisMember Returns if member is contained in the set.

Parameters:

`key` - string - The key of the set.

`member` - string - The member whose membership status will be checked.

Returns: true if the member exists in the set, false otherwise.

Errors:

"value at <key> is not a set" - when the provided key exists but is not a set.

func (*EchoVault) Start

func (server *EchoVault) Start()

Start starts the EchoVault instance's TCP listener. This allows the instance to accept connections handle client commands over TCP.

You can still use command functions like echovault.Set if you're embedding EchoVault in your application. However, if you'd like to also accept TCP request on the same instance, you must call this function.

func (*EchoVault) StrLen

func (server *EchoVault) StrLen(key string) (int, error)

StrLen returns the length of the string at the provided key.

Returns: The length of the string as an integer.

Errors:

- "value at key <key> is not a string" - when the value at the keys is not a string.

func (*EchoVault) SubStr

func (server *EchoVault) SubStr(key string, start, end int) (string, error)

SubStr returns a substring from the string at the key. The start and end indices are integers that specify the lower and upper bound respectively.

Returns: The substring from the start index to the end index.

Errors:

- "key <key> does not exist" - when the key does not exist.

- "value at key <key> is not a string" - when the value at the keys is not a string.

func (*EchoVault) Subscribe

func (server *EchoVault) Subscribe(tag string, channels ...string) ReadPubSubMessage

Subscribe subscribes the caller to the list of provided channels.

Parameters:

`tag` - string - The tag used to identify this subscription instance.

`channels` - ...string - The list of channels to subscribe to.

Returns: ReadPubSubMessage function which reads the next message sent to the subscription instance. This function is blocking.

func (*EchoVault) TTL

func (server *EchoVault) TTL(key string) (int, error)

TTL return the current key's expiry time from now in seconds.

Parameters:

`key` - string.

Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.

func (*EchoVault) UnloadModule

func (server *EchoVault) UnloadModule(module string)

UnloadModule unloads the provided module

Parameters:

`module` - string - module name as displayed by the ListModules method.

func (*EchoVault) Unsubscribe

func (server *EchoVault) Unsubscribe(tag string, channels ...string)

Unsubscribe unsubscribes the caller from the given channels.

Parameters:

`tag` - string - The tag used to identify this subscription instance.

`channels` - ...string - The list of channels to unsubscribe from.

func (*EchoVault) ZAdd

func (server *EchoVault) ZAdd(key string, members map[string]float64, options ZAddOptions) (int, error)

ZAdd adds member(s) to a sorted set. If the sorted set does not exist, a new sorted set is created with the member(s).

Parameters:

`key` - string - the key to update.

`members` - map[string]float64 - a map of the members to add. The key is the string and the value is a float64 score.

`options` - ZAddOptions

Returns: The number of members added, or the number of members updated in the "CH" flag is true.

Errors:

"GT/LT flags not allowed if NX flag is provided" - when GT/LT flags are provided alongside NX flag.

"cannot pass more than one score/member pair when INCR flag is provided" - when INCR flag is provided with more than one member-score pair.

"value at <key> is not a sorted set" - when the provided key exists but is not a sorted set

func (*EchoVault) ZCard

func (server *EchoVault) ZCard(key string) (int, error)

ZCard returns the cardinality of the sorted set.

Parameters:

`key` - string - the key of the sorted set.

Returns: The cardinality of the sorted set. Returns 0 if the keys does not exist.

Errors:

"value at <key> is not a sorted set" - when the provided key exists but is not a sorted set

func (*EchoVault) ZCount

func (server *EchoVault) ZCount(key string, min, max float64) (int, error)

ZCount returns the number of elements in the sorted set key with scores in the range of min and max.

Parameters:

`key` - string - the key of the sorted set.

`min` - float64 - the minimum score boundary.

`max` - float64 - the maximum score boundary.

Returns: The number of members with scores in the given range. Returns 0 if the keys does not exist.

Errors:

"value at <key> is not a sorted set" - when the provided key exists but is not a sorted set

func (*EchoVault) ZDiff

func (server *EchoVault) ZDiff(withscores bool, keys ...string) (map[string]float64, error)

ZDiff Calculates the difference between the sorted sets and returns the resulting sorted set. All keys that are non-existed are skipped.

Parameters:

`withscores` - bool - whether to return the results with scores or not. If false, all the returned scores will be 0.

`keys` - []string - the keys to the sorted sets to be used in calculating the difference.

Returns: A map representing the resulting sorted set where the key is the member and the value is a float64 score.

Errors:

"value at <key> is not a sorted set" - when the provided key exists but is not a sorted set.

func (*EchoVault) ZDiffStore

func (server *EchoVault) ZDiffStore(destination string, keys ...string) (int, error)

ZDiffStore Calculates the difference between the sorted sets and stores the resulting sorted set at 'destination'. Non-existent keys will be skipped.

Parameters:

`destination` - string - the destination key at which to store the resulting sorted set.

`keys` - []string - the keys to the sorted sets to be used in calculating the difference.

Returns: The cardinality of the new sorted set.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZIncrBy

func (server *EchoVault) ZIncrBy(key string, increment float64, member string) (float64, error)

ZIncrBy Increments the score of the specified sorted set's member by the increment. If the member does not exist, it is created. If the key does not exist, it is created with new sorted set and the member added with the increment as its score.

Parameters:

`key` - string - the keys to the sorted set.

`increment` - float64 - the increment to apply to the member's score.

`member` - string - the member to increment.

Returns: The cardinality of the new sorted set.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZInter

func (server *EchoVault) ZInter(keys []string, options ZInterOptions) (map[string]float64, error)

ZInter Calculates the intersection between the sorted sets and returns the resulting sorted set. if any of the keys provided are non-existent, an empty map is returned.

Parameters:

`keys` - []string - the keys to the sorted sets to be used in calculating the intersection.

`options` - ZInterOptions

Returns: A map representing the resulting sorted set where the key is the member and the value is a float64 score.

Errors:

"value at <key> is not a sorted set" - when the provided key exists but is not a sorted set.

func (*EchoVault) ZInterStore

func (server *EchoVault) ZInterStore(destination string, keys []string, options ZInterStoreOptions) (int, error)

ZInterStore Calculates the intersection between the sorted sets and stores the resulting sorted set at 'destination'. If any of the keys does not exist, the operation is abandoned.

Parameters:

`destination` - string - the destination key at which to store the resulting sorted set.

`keys` - []string - the keys to the sorted sets to be used in calculating the intersection.

`options` - ZInterStoreOptions

Returns: The cardinality of the new sorted set.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZLexCount

func (server *EchoVault) ZLexCount(key, min, max string) (int, error)

ZLexCount returns the number of elements in the sorted set within the lexicographical range between min and max. This function only returns a non-zero value if all the members have the same score.

Parameters:

`key` - string - the key of the sorted set.

`min` - string - the minimum lex boundary.

`max` - string - the maximum lex boundary.

Returns: The number of members within the given lexicographical range. Returns 0 if the keys does not exist or all the members don't have the same score.

Errors:

"value at <key> is not a sorted set" - when the provided key exists but is not a sorted set

func (*EchoVault) ZMPop

func (server *EchoVault) ZMPop(keys []string, options ZMPopOptions) ([][]string, error)

ZMPop Pop a 'count' elements from multiple sorted sets. MIN or MAX determines whether to pop elements with the lowest or highest scores respectively.

Parameters:

`keys` - []string - the keys to the sorted sets to pop from.

`options` - ZMPopOptions

Returns: A 2-dimensional slice where each slice contains the member and score at the 0 and 1 indices respectively.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZMScore

func (server *EchoVault) ZMScore(key string, members ...string) ([]interface{}, error)

ZMScore Returns the associated scores of the specified member in the sorted set.

Parameters:

`key` - string - The keys to the sorted set.

`members` - ...string - Them members whose scores will be returned.

Returns: A slice of interface{} with the result scores. For existing members, the entry will be represented by a string. For non-existent members, the score will be nil. You will have to format the string score into a float64 if you would like to use it as a float64.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZPopMax

func (server *EchoVault) ZPopMax(key string, count uint) ([][]string, error)

ZPopMax Removes and returns 'count' number of members in the sorted set with the highest scores. Default count is 1.

Parameters:

`key` - string - The keys to the sorted set.

`count` - uint - The number of max elements to pop. If a count of 0 is provided, it will be ignored and 1 element will be popped instead.

Returns: A 2-dimensional slice where each slice contains a member and its score at the 0 and 1 indices respectively. The returned scores are strings. If you'd like to use them as float64 or another numeric type, you will have to format them.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZPopMin

func (server *EchoVault) ZPopMin(key string, count uint) ([][]string, error)

ZPopMin Removes and returns 'count' number of members in the sorted set with the lowest scores. Default count is 1.

Parameters:

`key` - string - The keys to the sorted set.

`count` - uint - The number of min elements to pop. If a count of 0 is provided, it will be ignored and 1 element will be popped instead.

Returns: A 2-dimensional slice where each slice contains a member and its score at the 0 and 1 indices respectively. The returned scores are strings. If you'd like to use them as float64 or another numeric type, you will have to format them.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZRandMember

func (server *EchoVault) ZRandMember(key string, count int, withscores bool) ([][]string, error)

ZRandMember Returns a list of length equivalent to 'count' containing random members of the sorted set. If count is negative, repeated elements are allowed. If count is positive, the returned elements will be distinct. The default count is 1. If a count of 0 is passed, it will be ignored.

Parameters:

`key` - string - The keys to the sorted set.

`count` - int - The number of random members to return. If the absolute value of count is greater than the sorted set's cardinality, the whole sorted set will be returned.

`withscores` - bool - Whether to return the members' associated scores. If this is false, the returned scores will be 0.

Returns: A 2-dimensional slice where each slice contains a member and its score at the 0 and 1 indices respectively. The returned scores are strings. If you'd like to use them as float64 or another numeric type, you will have to format them.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZRange

func (server *EchoVault) ZRange(key, start, stop string, options ZRangeOptions) (map[string]float64, error)

ZRange Returns the range of elements in the sorted set.

Parameters:

`key` - string - The keys to the sorted set.

`start` - string - The minimum boundary.

`stop` - string - The maximum boundary.

`options` - ZRangeOptions

Returns: A map of map[string]float64 where the key is the member and the value is its score.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZRangeStore

func (server *EchoVault) ZRangeStore(destination, source, start, stop string, options ZRangeStoreOptions) (int, error)

ZRangeStore Works like ZRange but stores the result in at the 'destination' key.

Parameters:

`destination` - string - The key at which to store the new sorted set

`key` - string - The keys to the sorted set.

`start` - string - The minimum boundary.

`stop` - string - The maximum boundary.

`options` - ZRangeStoreOptions

Returns: The cardinality of the new sorted set.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZRank

func (server *EchoVault) ZRank(key string, member string, withscores bool) (map[int]float64, error)

ZRank Returns the rank of the specified member in the sorted set. The rank is derived from organising the members in descending order of score.

Parameters:

`key` - string - The keys to the sorted set.

`member` - string - The member whose rank will be returned.

`withscores` - bool - Whether to return the member associated scores. If this is false, the returned score will be 0.

Returns: A map of map[string]float64 where the key is the member and the value is the score. If the member does not exist in the sorted set, an empty map is returned.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZRem

func (server *EchoVault) ZRem(key string, members ...string) (int, error)

ZRem Removes the listed members from the sorted set.

Parameters:

`key` - string - The keys to the sorted set.

`members` - ...string - The members to remove.

Returns: The number of elements that were successfully removed.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZRemRangeByLex added in v0.6.0

func (server *EchoVault) ZRemRangeByLex(key, min, max string) (int, error)

ZRemRangeByLex Removes the elements that are lexicographically between min and max.

Parameters:

`key` - string - The keys to the sorted set.

`min` - string - The minimum lexicographic boundary.

`max` - string - The maximum lexicographic boundary.

Returns: The number of elements that were successfully removed.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZRemRangeByRank added in v0.6.0

func (server *EchoVault) ZRemRangeByRank(key string, min, max int) (int, error)

ZRemRangeByRank Removes the elements that are ranked between min and max.

Parameters:

`key` - string - The keys to the sorted set.

`min` - int - The minimum rank boundary.

`max` - int - The maximum rank boundary.

Returns: The number of elements that were successfully removed.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZRemRangeByScore

func (server *EchoVault) ZRemRangeByScore(key string, min float64, max float64) (int, error)

ZRemRangeByScore Removes the elements whose scores are in the range between min and max.

Parameters:

`key` - string - The keys to the sorted set.

`min` - float64 - The minimum score boundary.

`max` - float64 - The maximum score boundary.

Returns: The number of elements that were successfully removed.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZRevRank

func (server *EchoVault) ZRevRank(key string, member string, withscores bool) (map[int]float64, error)

ZRevRank works the same as ZRank but derives the member's rank based on ascending order of the members' scores.

func (*EchoVault) ZScore

func (server *EchoVault) ZScore(key string, member string) (interface{}, error)

ZScore Returns the score of the member in the sorted set.

Parameters:

`key` - string - The keys to the sorted set.

`member` - string - The member whose rank will be returned.

Returns: An interface representing the score of the member. If the member does not exist in the sorted set, nil is returned. Otherwise, a float64 is returned.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

func (*EchoVault) ZUnion

func (server *EchoVault) ZUnion(keys []string, options ZUnionOptions) (map[string]float64, error)

ZUnion Calculates the union between the sorted sets and returns the resulting sorted set. if any of the keys provided are non-existent, an error is returned.

Parameters:

`keys` - []string - the keys to the sorted sets to be used in calculating the union.

`options` - ZUnionOptions

Returns: A map representing the resulting sorted set where the key is the member and the value is a float64 score.

Errors:

"value at <key> is not a sorted set" - when the provided key exists but is not a sorted set.

func (*EchoVault) ZUnionStore

func (server *EchoVault) ZUnionStore(destination string, keys []string, options ZUnionStoreOptions) (int, error)

ZUnionStore Calculates the union between the sorted sets and stores the resulting sorted set at 'destination'. Non-existent keys will be skipped.

Parameters:

`destination` - string - the destination key at which to store the resulting sorted set.

`keys` - []string - the keys to the sorted sets to be used in calculating the union.

`options` - ZUnionStoreOptions

Returns: The cardinality of the new sorted set.

Errors:

"value at <key> is not a sorted set" - when a key exists but is not a sorted set.

type ExpireAtOptions

type ExpireAtOptions ExpireOptions

type ExpireOptions

type ExpireOptions struct {
	NX bool
	XX bool
	LT bool
	GT bool
}

ExpireOptions modifies the behaviour of the Expire, PExpire, ExpireAt, PExpireAt.

NX - Only set the expiry time if the key has no associated expiry.

XX - Only set the expiry time if the key already has an expiry time.

GT - Only set the expiry time if the new expiry time is greater than the current one.

LT - Only set the expiry time if the new expiry time is less than the current one.

type HRandFieldOptions

type HRandFieldOptions struct {
	Count      uint
	WithValues bool
}

HRandFieldOptions modifies the behaviour of the HRandField function.

Count determines the number of random fields to return. If set to 0, an empty slice will be returned.

WithValues determines whether the returned map should contain the values as well as the fields.

type PExpireAtOptions

type PExpireAtOptions ExpireOptions

type PExpireOptions

type PExpireOptions ExpireOptions

type ReadPubSubMessage

type ReadPubSubMessage func() []string

ReadPubSubMessage is returned by the Subscribe and PSubscribe functions.

This function is lazy, therefore it needs to be invoked in order to read the next message. When the message is read, the function returns a string slice with 3 elements. Index 0 holds the event type which in this case will be "message". Index 1 holds the channel name. Index 2 holds the actual message.

type SetOptions

type SetOptions struct {
	NX   bool
	XX   bool
	GET  bool
	EX   int
	PX   int
	EXAT int
	PXAT int
}

SetOptions modifies the behaviour for the Set command

NX - Only set if the key does not exist. NX is higher priority than XX.

XX - Only set if the key exists.

GET - Return the old value stored at key, or nil if the value does not exist.

EX - Expire the key after the specified number of seconds (positive integer). EX has the highest priority

PX - Expire the key after the specified number of milliseconds (positive integer). PX has the second-highest priority.

EXAT - Expire at the exact time in unix seconds (positive integer). EXAT has the third-highest priority.

PXAT - Expire at the exat time in unix milliseconds (positive integer). PXAT has the least priority.

type SubCommandOptions

type SubCommandOptions struct {
	Command           string
	Module            string
	Categories        []string
	Description       string
	Sync              bool
	KeyExtractionFunc CommandKeyExtractionFunc
	HandlerFunc       CommandHandlerFunc
}

SubCommandOptions provides the specification of a subcommand within CommandOptions.

Command is the keyword used to trigger this subcommand (e.g. "CAT" for the subcommand "ACL CAT").

Module is a string that classifies a group of commands/subcommands.

Categories is a string slice of all the categories that this subcommand belongs to.

Description is a string describing the subcommand, can include an example of how to trigger the subcommand.

Sync is a boolean value that determines whether this subcommand should be synced across a replication cluster. This value overrides the Sync value set by the parent command. It's possible to have some synced and un-synced subcommands with the same parent command regardless of the parent's Sync value.

KeyExtractionFunc is a function that extracts the keys from the subcommand if it accesses any keys.

HandlerFunc is the subcommand handler. This function must return a valid RESP2 response as it will be available to RESP clients.

type User

type User struct {
	Username      string
	Enabled       bool
	NoPassword    bool
	NoKeys        bool
	NoCommands    bool
	ResetPass     bool
	ResetKeys     bool
	ResetChannels bool

	AddPlainPasswords    []string
	RemovePlainPasswords []string
	AddHashPasswords     []string
	RemoveHashPasswords  []string

	IncludeCategories []string
	ExcludeCategories []string

	IncludeCommands []string
	ExcludeCommands []string

	IncludeReadWriteKeys []string
	IncludeReadKeys      []string
	IncludeWriteKeys     []string

	IncludeChannels []string
	ExcludeChannels []string
}

User is the user object passed to the ACLSetUser function to update an existing user or create a new user.

Username - string - the user's username.

Enabled - bool - whether the user should be enabled (i.e connections can authenticate with this user).

NoPassword - bool - if true, this user can be authenticated against without a password.

NoKeys - bool - if true, this user will not be allowed to access any keys.

NoCommands - bool - if true, this user will not be allowed to execute any commands.

ResetPass - bool - if true, all the user's configured passwords are removed and NoPassword is set to false.

ResetKeys - bool - if true, the user's NoKeys flag is set to true and all their currently accessible keys are cleared.

ResetChannels - bool - if true, the user will be allowed to access all PubSub channels.

AddPlainPasswords - []string - the list of plaintext passwords to add to the user's passwords.

RemovePlainPasswords - []string - the list of plaintext passwords to remove from the user's passwords.

AddHashPasswords - []string - the list of SHA256 password hashes to add to the user's passwords.

RemoveHashPasswords - []string - the list of SHA256 password hashes to add to the user's passwords.

IncludeCategories - []string - the list of ACL command categories to allow this user to access, default is all.

ExcludeCategories - []string - the list of ACL command categories to bar the user from accessing. The default is none.

IncludeCommands - []string - the list of commands to allow the user to execute. The default is none. If you want to specify a subcommand, use the format "command|subcommand".

ExcludeCommands - []string - the list of commands to bar the user from executing. The default is none. If you want to specify a subcommand, use the format "command|subcommand".

IncludeReadWriteKeys - []string - the list of keys the user is allowed read and write access to. The default is all. This field accepts glob pattern strings.

IncludeReadKeys - []string - the list of keys the user is allowed read access to. The default is all. This field accepts glob pattern strings.

IncludeWriteKeys - []string - the list of keys the user is allowed write access to. The default is all. This field accepts glob pattern strings.

IncludeChannels - []string - the list of PubSub channels the user is allowed to access ("Subscribe" and "Publish"). This field accepts glob pattern strings.

ExcludeChannels - []string - the list of PubSub channels the user cannot access ("Subscribe" and "Publish"). This field accepts glob pattern strings.

type ZAddOptions

type ZAddOptions struct {
	NX   bool
	XX   bool
	GT   bool
	LT   bool
	CH   bool
	INCR bool
}

ZAddOptions allows you to modify the effects of the ZAdd command.

"NX" only adds the member if it currently does not exist in the sorted set. This flag is mutually exclusive with the "GT" and "LT" flags. The "NX" flag takes higher priority than the "XX" flag.

"XX" only updates the scores of members that exist in the sorted set.

"GT"" only updates the score if the new score is greater than the current score. The "GT" flat is higher priority than the "LT" flag.

"LT" only updates the score if the new score is less than the current score.

"CH" modifies the result to return total number of members changed + added, instead of only new members added. When this flag is set to true, only the number of members that have been updated will be returned.

"INCR" modifies the command to act like ZIncrBy, only one score/member pair can be specified in this mode. When this flag is provided, only one member/score pair is allowed.

type ZInterOptions

type ZInterOptions struct {
	Weights    []float64
	Aggregate  string
	WithScores bool
}

ZInterOptions allows you to modify the result of the ZInter* and ZUnion* family of commands

Weights is a slice of float64 that determines the weights of each sorted set in the aggregation command. each weight will be each weight will be applied to the sorted set at the corresponding index. The weight value is multiplied by each member of corresponding sorted set.

Aggregate determines how the scores are combined AFTER the weights are applied. There are 3 possible vales, "MIN" will select the minimum score element to place in the resulting sorted set. "MAX" will select the maximum score element to place in the resulting sorted set. "SUM" will add all the scores to place in the resulting sorted set.

WithScores determines whether to return the scores of the resulting set.

type ZInterStoreOptions

type ZInterStoreOptions ZInterOptions

type ZMPopOptions

type ZMPopOptions struct {
	Min   bool
	Max   bool
	Count uint
}

ZMPopOptions allows you to modify the result of the ZMPop command.

Min instructs EchoVault to pop the minimum score elements. Min is higher priority than Max.

Max instructs EchoVault to pop the maximum score elements.

Count specifies the number of elements to pop.

type ZRangeOptions

type ZRangeOptions struct {
	WithScores bool
	ByScore    bool
	ByLex      bool
	Rev        bool
	Offset     uint
	Count      uint
}

ZRangeOptions allows you to modify the effects of the ZRange* family of commands.

WithScores specifies whether to return the associated scores.

ByScore compares the elements by score within the numerical ranges specified. ByScore is higher priority than ByLex.

ByLex returns the elements within the lexicographical ranges specified.

Rev reverses the result from the previous filters.

Offset specifies the offset to from which to start the ZRange process.

Count specifies the number of elements to return.

type ZRangeStoreOptions

type ZRangeStoreOptions ZRangeOptions

type ZUnionOptions

type ZUnionOptions ZInterOptions

type ZUnionStoreOptions

type ZUnionStoreOptions ZInterOptions

Jump to

Keyboard shortcuts

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