mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-17 13:31:55 +08:00
Added godoc commends for embedded methods and types to extend commands. Moved constants to internal directory
This commit is contained in:
@@ -35,27 +35,66 @@ type EchoVault interface {
|
||||
DeleteKey(ctx context.Context, key string) error
|
||||
}
|
||||
|
||||
type PluginKeyExtractionFuncResult struct {
|
||||
// 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 CommandKeyExtractionFuncResult struct {
|
||||
ReadKeys []string
|
||||
WriteKeys []string
|
||||
}
|
||||
type PluginKeyExtractionFunc func(cmd []string) (PluginKeyExtractionFuncResult, error)
|
||||
|
||||
type PluginHandlerFunc func(params PluginHandlerFuncParams) ([]byte, error)
|
||||
type PluginHandlerFuncParams struct {
|
||||
// CommandKeyExtractionFunc if the function that extracts the keys accessed by the command or subcommand.
|
||||
type CommandKeyExtractionFunc func(cmd []string) (CommandKeyExtractionFuncResult, 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 CommandHandlerFunc func(params CommandHandlerFuncParams) ([]byte, 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.
|
||||
//
|
||||
// Connection is the TCP connection that triggered this command. In embedded mode, this will always be nil.
|
||||
// Any TCP client that trigger the custom command will have its connection passed to the handler here.
|
||||
//
|
||||
// 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 CommandHandlerFuncParams struct {
|
||||
Context context.Context
|
||||
Command []string
|
||||
Connection *net.Conn
|
||||
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)
|
||||
KeyExists func(ctx context.Context, key string) bool
|
||||
CreateKeyAndLock func(ctx context.Context, key string) (bool, error)
|
||||
GetValue func(ctx context.Context, key string) interface{}
|
||||
SetValue func(ctx context.Context, key string, value interface{}) error
|
||||
GetExpiry func(ctx context.Context, key string) time.Time
|
||||
SetExpiry func(ctx context.Context, key string, expire time.Time, touch bool)
|
||||
RemoveExpiry func(ctx context.Context, key string)
|
||||
DeleteKey func(ctx context.Context, key string) error
|
||||
}
|
||||
|
Reference in New Issue
Block a user