mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-05 07:56:52 +08:00
Renames Server struct and utils.Server interface to EchoVault and utils.EchoVault respectively
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -70,7 +70,7 @@ func main() {
|
||||
cancelCh := make(chan os.Signal, 1)
|
||||
signal.Notify(cancelCh, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||
|
||||
s := server.NewServer(server.Opts{
|
||||
s := server.NewEchoVault(server.Opts{
|
||||
Config: config,
|
||||
ACL: acl.NewACL(config),
|
||||
PubSub: pubsub.NewPubSub(),
|
||||
|
@@ -43,7 +43,7 @@ type ACL struct {
|
||||
Users []*User // List of ACL user profiles
|
||||
UsersMutex sync.RWMutex // RWMutex for concurrency control when accessing ACL profile list
|
||||
Connections map[*net.Conn]Connection // Connections to the server that are currently registered with the ACL module
|
||||
Config utils.Config // Server configuration that contains the relevant ACL config options
|
||||
Config utils.Config // EchoVault configuration that contains the relevant ACL config options
|
||||
GlobPatterns map[string]glob.Glob
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func handleAuth(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleAuth(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
if len(cmd) < 2 || len(cmd) > 3 {
|
||||
return nil, errors.New(utils.WrongArgsResponse)
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func handleAuth(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handleGetUser(_ context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleGetUser(_ context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
if len(cmd) != 3 {
|
||||
return nil, errors.New(utils.WrongArgsResponse)
|
||||
}
|
||||
@@ -160,7 +160,7 @@ func handleGetUser(_ context.Context, cmd []string, server utils.Server, _ *net.
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleCat(_ context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleCat(_ context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
if len(cmd) > 3 {
|
||||
return nil, errors.New(utils.WrongArgsResponse)
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func handleCat(_ context.Context, cmd []string, server utils.Server, _ *net.Conn
|
||||
return nil, fmt.Errorf("category %s not found", strings.ToUpper(cmd[2]))
|
||||
}
|
||||
|
||||
func handleUsers(_ context.Context, _ []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleUsers(_ context.Context, _ []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
acl, ok := server.GetACL().(*ACL)
|
||||
if !ok {
|
||||
return nil, errors.New("could not load ACL")
|
||||
@@ -233,7 +233,7 @@ func handleUsers(_ context.Context, _ []string, server utils.Server, _ *net.Conn
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleSetUser(_ context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleSetUser(_ context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
acl, ok := server.GetACL().(*ACL)
|
||||
if !ok {
|
||||
return nil, errors.New("could not load ACL")
|
||||
@@ -244,7 +244,7 @@ func handleSetUser(_ context.Context, cmd []string, server utils.Server, _ *net.
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handleDelUser(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleDelUser(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
if len(cmd) < 3 {
|
||||
return nil, errors.New(utils.WrongArgsResponse)
|
||||
}
|
||||
@@ -258,7 +258,7 @@ func handleDelUser(ctx context.Context, cmd []string, server utils.Server, _ *ne
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handleWhoAmI(_ context.Context, _ []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleWhoAmI(_ context.Context, _ []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
acl, ok := server.GetACL().(*ACL)
|
||||
if !ok {
|
||||
return nil, errors.New("could not load ACL")
|
||||
@@ -267,7 +267,7 @@ func handleWhoAmI(_ context.Context, _ []string, server utils.Server, conn *net.
|
||||
return []byte(fmt.Sprintf("+%s\r\n", connectionInfo.User.Username)), nil
|
||||
}
|
||||
|
||||
func handleList(_ context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleList(_ context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
if len(cmd) > 2 {
|
||||
return nil, errors.New(utils.WrongArgsResponse)
|
||||
}
|
||||
@@ -363,7 +363,7 @@ func handleList(_ context.Context, cmd []string, server utils.Server, _ *net.Con
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleLoad(_ context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleLoad(_ context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
if len(cmd) != 3 {
|
||||
return nil, errors.New(utils.WrongArgsResponse)
|
||||
}
|
||||
@@ -430,7 +430,7 @@ func handleLoad(_ context.Context, cmd []string, server utils.Server, _ *net.Con
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handleSave(_ context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleSave(_ context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
if len(cmd) > 2 {
|
||||
return nil, errors.New(utils.WrongArgsResponse)
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ import (
|
||||
|
||||
var bindAddr string
|
||||
var port uint16
|
||||
var mockServer *server.Server
|
||||
var mockServer *server.EchoVault
|
||||
|
||||
var acl *ACL
|
||||
|
||||
@@ -44,7 +44,7 @@ func init() {
|
||||
}()
|
||||
}
|
||||
|
||||
func setUpServer(bindAddr string, port uint16, requirePass bool, aclConfig string) *server.Server {
|
||||
func setUpServer(bindAddr string, port uint16, requirePass bool, aclConfig string) *server.EchoVault {
|
||||
config := utils.Config{
|
||||
BindAddr: bindAddr,
|
||||
Port: port,
|
||||
@@ -58,7 +58,7 @@ func setUpServer(bindAddr string, port uint16, requirePass bool, aclConfig strin
|
||||
acl = NewACL(config)
|
||||
acl.Users = append(acl.Users, generateInitialTestUsers()...)
|
||||
|
||||
return server.NewServer(server.Opts{
|
||||
return server.NewEchoVault(server.Opts{
|
||||
Config: config,
|
||||
ACL: acl,
|
||||
Commands: Commands(),
|
||||
|
@@ -25,7 +25,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func handleGetAllCommands(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleGetAllCommands(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
commands := server.GetAllCommands()
|
||||
|
||||
res := ""
|
||||
@@ -70,7 +70,7 @@ func handleGetAllCommands(ctx context.Context, cmd []string, server utils.Server
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleCommandCount(_ context.Context, _ []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleCommandCount(_ context.Context, _ []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
var count int
|
||||
|
||||
commands := server.GetAllCommands()
|
||||
@@ -87,7 +87,7 @@ func handleCommandCount(_ context.Context, _ []string, server utils.Server, _ *n
|
||||
return []byte(fmt.Sprintf(":%d\r\n", count)), nil
|
||||
}
|
||||
|
||||
func handleCommandList(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleCommandList(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
switch len(cmd) {
|
||||
case 2:
|
||||
// Command is COMMAND LIST
|
||||
@@ -166,7 +166,7 @@ func handleCommandList(ctx context.Context, cmd []string, server utils.Server, _
|
||||
}
|
||||
}
|
||||
|
||||
func handleCommandDocs(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleCommandDocs(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
return []byte("*0\r\n"), nil
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ Allows for filtering by ACL category or glob pattern.`,
|
||||
KeyExtractionFunc: func(cmd []string) ([]string, error) {
|
||||
return []string{}, nil
|
||||
},
|
||||
HandlerFunc: func(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
HandlerFunc: func(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
if err := server.TakeSnapshot(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -239,7 +239,7 @@ Allows for filtering by ACL category or glob pattern.`,
|
||||
KeyExtractionFunc: func(cmd []string) ([]string, error) {
|
||||
return []string{}, nil
|
||||
},
|
||||
HandlerFunc: func(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
HandlerFunc: func(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
msec := server.GetLatestSnapshot()
|
||||
if msec == 0 {
|
||||
return nil, errors.New("no snapshot")
|
||||
@@ -255,7 +255,7 @@ Allows for filtering by ACL category or glob pattern.`,
|
||||
KeyExtractionFunc: func(cmd []string) ([]string, error) {
|
||||
return []string{}, nil
|
||||
},
|
||||
HandlerFunc: func(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
HandlerFunc: func(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
if err := server.RewriteAOF(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -19,12 +19,17 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/echovault/echovault/src/server"
|
||||
"github.com/echovault/echovault/src/utils"
|
||||
"github.com/tidwall/resp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_CommandsHandler(t *testing.T) {
|
||||
mockServer := server.NewServer(server.Opts{
|
||||
mockServer := server.NewEchoVault(server.Opts{
|
||||
Config: utils.Config{
|
||||
DataDir: "",
|
||||
EvictionPolicy: utils.NoEviction,
|
||||
},
|
||||
Commands: Commands(),
|
||||
})
|
||||
|
||||
|
@@ -22,7 +22,7 @@ import (
|
||||
"net"
|
||||
)
|
||||
|
||||
func handlePing(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handlePing(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
switch len(cmd) {
|
||||
default:
|
||||
return nil, errors.New(utils.WrongArgsResponse)
|
||||
|
@@ -24,10 +24,10 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var mockServer *server.Server
|
||||
var mockServer *server.EchoVault
|
||||
|
||||
func init() {
|
||||
mockServer = server.NewServer(server.Opts{
|
||||
mockServer = server.NewEchoVault(server.Opts{
|
||||
Config: utils.Config{
|
||||
DataDir: "",
|
||||
EvictionPolicy: utils.NoEviction,
|
||||
|
@@ -47,7 +47,7 @@ type KeyObject struct {
|
||||
locked bool
|
||||
}
|
||||
|
||||
func handleSet(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleSet(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
keys, err := setKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -111,7 +111,7 @@ func handleSet(ctx context.Context, cmd []string, server utils.Server, _ *net.Co
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func handleMSet(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleMSet(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
if _, err := msetKeyFunc(cmd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func handleMSet(ctx context.Context, cmd []string, server utils.Server, _ *net.C
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handleGet(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleGet(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
keys, err := getKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -189,7 +189,7 @@ func handleGet(ctx context.Context, cmd []string, server utils.Server, _ *net.Co
|
||||
return []byte(fmt.Sprintf("+%v\r\n", value)), nil
|
||||
}
|
||||
|
||||
func handleMGet(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleMGet(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
keys, err := mgetKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -239,7 +239,7 @@ func handleMGet(ctx context.Context, cmd []string, server utils.Server, _ *net.C
|
||||
return bytes, nil
|
||||
}
|
||||
|
||||
func handleDel(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleDel(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
keys, err := delKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -256,7 +256,7 @@ func handleDel(ctx context.Context, cmd []string, server utils.Server, _ *net.Co
|
||||
return []byte(fmt.Sprintf(":%d\r\n", count)), nil
|
||||
}
|
||||
|
||||
func handlePersist(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handlePersist(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
keys, err := persistKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -283,7 +283,7 @@ func handlePersist(ctx context.Context, cmd []string, server utils.Server, _ *ne
|
||||
return []byte(":1\r\n"), nil
|
||||
}
|
||||
|
||||
func handleExpireTime(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleExpireTime(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
keys, err := expireTimeKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -314,7 +314,7 @@ func handleExpireTime(ctx context.Context, cmd []string, server utils.Server, _
|
||||
return []byte(fmt.Sprintf(":%d\r\n", t)), nil
|
||||
}
|
||||
|
||||
func handleTTL(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleTTL(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
keys, err := ttlKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -349,7 +349,7 @@ func handleTTL(ctx context.Context, cmd []string, server utils.Server, _ *net.Co
|
||||
return []byte(fmt.Sprintf(":%d\r\n", t)), nil
|
||||
}
|
||||
|
||||
func handleExpire(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleExpire(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
keys, err := expireKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -417,7 +417,7 @@ func handleExpire(ctx context.Context, cmd []string, server utils.Server, _ *net
|
||||
return []byte(":1\r\n"), nil
|
||||
}
|
||||
|
||||
func handleExpireAt(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleExpireAt(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
keys, err := expireKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -26,10 +26,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var mockServer *server.Server
|
||||
var mockServer *server.EchoVault
|
||||
|
||||
func init() {
|
||||
mockServer = server.NewServer(server.Opts{
|
||||
mockServer = server.NewEchoVault(server.Opts{
|
||||
Config: utils.Config{
|
||||
DataDir: "",
|
||||
EvictionPolicy: utils.NoEviction,
|
||||
|
@@ -26,7 +26,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func handleHSET(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleHSET(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
keys, err := hsetKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -84,7 +84,7 @@ func handleHSET(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(fmt.Sprintf(":%d\r\n", count)), nil
|
||||
}
|
||||
|
||||
func handleHGET(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleHGET(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := hgetKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -135,7 +135,7 @@ func handleHGET(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleHSTRLEN(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleHSTRLEN(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := hstrlenKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -186,7 +186,7 @@ func handleHSTRLEN(ctx context.Context, cmd []string, server utils.Server, conn
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleHVALS(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleHVALS(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := hvalsKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -227,7 +227,7 @@ func handleHVALS(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleHRANDFIELD(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleHRANDFIELD(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := hrandfieldKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -343,7 +343,7 @@ func handleHRANDFIELD(ctx context.Context, cmd []string, server utils.Server, co
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleHLEN(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleHLEN(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := hlenKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -368,7 +368,7 @@ func handleHLEN(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(fmt.Sprintf(":%d\r\n", len(hash))), nil
|
||||
}
|
||||
|
||||
func handleHKEYS(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleHKEYS(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := hkeysKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -398,7 +398,7 @@ func handleHKEYS(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleHINCRBY(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleHINCRBY(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := hincrbyKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -490,7 +490,7 @@ func handleHINCRBY(ctx context.Context, cmd []string, server utils.Server, conn
|
||||
return []byte(fmt.Sprintf(":%d\r\n", i)), nil
|
||||
}
|
||||
|
||||
func handleHGETALL(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleHGETALL(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := hgetallKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -530,7 +530,7 @@ func handleHGETALL(ctx context.Context, cmd []string, server utils.Server, conn
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleHEXISTS(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleHEXISTS(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := hexistsKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -560,7 +560,7 @@ func handleHEXISTS(ctx context.Context, cmd []string, server utils.Server, conn
|
||||
return []byte(":0\r\n"), nil
|
||||
}
|
||||
|
||||
func handleHDEL(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleHDEL(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := hdelKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -26,10 +26,10 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var mockServer *server.Server
|
||||
var mockServer *server.EchoVault
|
||||
|
||||
func init() {
|
||||
mockServer = server.NewServer(server.Opts{
|
||||
mockServer = server.NewEchoVault(server.Opts{
|
||||
Config: utils.Config{
|
||||
DataDir: "",
|
||||
EvictionPolicy: utils.NoEviction,
|
||||
|
@@ -25,7 +25,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func handleLLen(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handleLLen(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
keys, err := llenKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -50,7 +50,7 @@ func handleLLen(ctx context.Context, cmd []string, server utils.Server, _ *net.C
|
||||
return nil, errors.New("LLEN command on non-list item")
|
||||
}
|
||||
|
||||
func handleLIndex(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleLIndex(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := lindexKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -84,7 +84,7 @@ func handleLIndex(ctx context.Context, cmd []string, server utils.Server, conn *
|
||||
return []byte(fmt.Sprintf("+%s\r\n", list[index])), nil
|
||||
}
|
||||
|
||||
func handleLRange(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleLRange(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := lrangeKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -163,7 +163,7 @@ func handleLRange(ctx context.Context, cmd []string, server utils.Server, conn *
|
||||
return bytes, nil
|
||||
}
|
||||
|
||||
func handleLSet(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleLSet(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := lsetKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -202,7 +202,7 @@ func handleLSet(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handleLTrim(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleLTrim(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := ltrimKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -251,7 +251,7 @@ func handleLTrim(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handleLRem(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleLRem(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := lremKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -319,7 +319,7 @@ func handleLRem(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handleLMove(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleLMove(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := lmoveKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -380,7 +380,7 @@ func handleLMove(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handleLPush(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleLPush(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := lpushKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -426,7 +426,7 @@ func handleLPush(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handleRPush(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleRPush(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := rpushKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -474,7 +474,7 @@ func handleRPush(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handlePop(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handlePop(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := popKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -25,10 +25,10 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var mockServer *server.Server
|
||||
var mockServer *server.EchoVault
|
||||
|
||||
func init() {
|
||||
mockServer = server.NewServer(server.Opts{
|
||||
mockServer = server.NewEchoVault(server.Opts{
|
||||
Config: utils.Config{
|
||||
DataDir: "",
|
||||
EvictionPolicy: utils.NoEviction,
|
||||
|
@@ -23,7 +23,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func handleSubscribe(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSubscribe(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
pubsub, ok := server.GetPubSub().(*PubSub)
|
||||
if !ok {
|
||||
return nil, errors.New("could not load pubsub module")
|
||||
@@ -41,7 +41,7 @@ func handleSubscribe(ctx context.Context, cmd []string, server utils.Server, con
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func handleUnsubscribe(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleUnsubscribe(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
pubsub, ok := server.GetPubSub().(*PubSub)
|
||||
if !ok {
|
||||
return nil, errors.New("could not load pubsub module")
|
||||
@@ -54,7 +54,7 @@ func handleUnsubscribe(ctx context.Context, cmd []string, server utils.Server, c
|
||||
return pubsub.Unsubscribe(ctx, conn, channels, withPattern), nil
|
||||
}
|
||||
|
||||
func handlePublish(ctx context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handlePublish(ctx context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
pubsub, ok := server.GetPubSub().(*PubSub)
|
||||
if !ok {
|
||||
return nil, errors.New("could not load pubsub module")
|
||||
@@ -66,7 +66,7 @@ func handlePublish(ctx context.Context, cmd []string, server utils.Server, _ *ne
|
||||
return []byte(utils.OkResponse), nil
|
||||
}
|
||||
|
||||
func handlePubSubChannels(_ context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handlePubSubChannels(_ context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
if len(cmd) > 3 {
|
||||
return nil, errors.New(utils.WrongArgsResponse)
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func handlePubSubChannels(_ context.Context, cmd []string, server utils.Server,
|
||||
return pubsub.Channels(pattern), nil
|
||||
}
|
||||
|
||||
func handlePubSubNumPat(_ context.Context, _ []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handlePubSubNumPat(_ context.Context, _ []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
pubsub, ok := server.GetPubSub().(*PubSub)
|
||||
if !ok {
|
||||
return nil, errors.New("could not load pubsub module")
|
||||
@@ -93,7 +93,7 @@ func handlePubSubNumPat(_ context.Context, _ []string, server utils.Server, _ *n
|
||||
return []byte(fmt.Sprintf(":%d\r\n", num)), nil
|
||||
}
|
||||
|
||||
func handlePubSubNumSubs(_ context.Context, cmd []string, server utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
func handlePubSubNumSubs(_ context.Context, cmd []string, server utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
pubsub, ok := server.GetPubSub().(*PubSub)
|
||||
if !ok {
|
||||
return nil, errors.New("could not load pubsub module")
|
||||
@@ -177,7 +177,7 @@ it's currently subscribe to.`,
|
||||
Description: "",
|
||||
Sync: false,
|
||||
KeyExtractionFunc: func(cmd []string) ([]string, error) { return []string{}, nil },
|
||||
HandlerFunc: func(_ context.Context, _ []string, _ utils.Server, _ *net.Conn) ([]byte, error) {
|
||||
HandlerFunc: func(_ context.Context, _ []string, _ utils.EchoVault, _ *net.Conn) ([]byte, error) {
|
||||
return nil, errors.New("provide CHANNELS, NUMPAT, or NUMSUB subcommand")
|
||||
},
|
||||
SubCommands: []utils.SubCommand{
|
||||
|
@@ -28,14 +28,14 @@ import (
|
||||
)
|
||||
|
||||
var pubsub *PubSub
|
||||
var mockServer *server.Server
|
||||
var mockServer *server.EchoVault
|
||||
|
||||
var bindAddr = "localhost"
|
||||
var port uint16 = 7490
|
||||
|
||||
func init() {
|
||||
pubsub = NewPubSub()
|
||||
mockServer = server.NewServer(server.Opts{
|
||||
mockServer = server.NewEchoVault(server.Opts{
|
||||
PubSub: pubsub,
|
||||
Commands: Commands(),
|
||||
Config: utils.Config{
|
||||
@@ -492,7 +492,7 @@ func Test_HandlePubSubChannels(t *testing.T) {
|
||||
// Create separate mock server for this test
|
||||
var port uint16 = 7590
|
||||
pubsub = NewPubSub()
|
||||
mockServer := server.NewServer(server.Opts{
|
||||
mockServer := server.NewEchoVault(server.Opts{
|
||||
PubSub: pubsub,
|
||||
Commands: Commands(),
|
||||
Config: utils.Config{
|
||||
@@ -637,7 +637,7 @@ func Test_HandleNumPat(t *testing.T) {
|
||||
// Create separate mock server for this test
|
||||
var port uint16 = 7591
|
||||
pubsub = NewPubSub()
|
||||
mockServer := server.NewServer(server.Opts{
|
||||
mockServer := server.NewEchoVault(server.Opts{
|
||||
PubSub: pubsub,
|
||||
Commands: Commands(),
|
||||
Config: utils.Config{
|
||||
@@ -741,7 +741,7 @@ func Test_HandleNumSub(t *testing.T) {
|
||||
// Create separate mock server for this test
|
||||
var port uint16 = 7591
|
||||
pubsub = NewPubSub()
|
||||
mockServer := server.NewServer(server.Opts{
|
||||
mockServer := server.NewEchoVault(server.Opts{
|
||||
PubSub: pubsub,
|
||||
Commands: Commands(),
|
||||
Config: utils.Config{
|
||||
|
@@ -24,7 +24,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func handleSADD(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSADD(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := saddKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -61,7 +61,7 @@ func handleSADD(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(fmt.Sprintf(":%d\r\n", count)), nil
|
||||
}
|
||||
|
||||
func handleSCARD(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSCARD(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := scardKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -88,7 +88,7 @@ func handleSCARD(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte(fmt.Sprintf(":%d\r\n", cardinality)), nil
|
||||
}
|
||||
|
||||
func handleSDIFF(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSDIFF(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := sdiffKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -149,7 +149,7 @@ func handleSDIFF(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleSDIFFSTORE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSDIFFSTORE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := sdiffstoreKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -225,7 +225,7 @@ func handleSDIFFSTORE(ctx context.Context, cmd []string, server utils.Server, co
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleSINTER(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSINTER(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := sinterKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -280,7 +280,7 @@ func handleSINTER(ctx context.Context, cmd []string, server utils.Server, conn *
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleSINTERCARD(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSINTERCARD(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := sintercardKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -347,7 +347,7 @@ func handleSINTERCARD(ctx context.Context, cmd []string, server utils.Server, co
|
||||
return []byte(fmt.Sprintf(":%d\r\n", intersect.Cardinality())), nil
|
||||
}
|
||||
|
||||
func handleSINTERSTORE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSINTERSTORE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := sinterstoreKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -405,7 +405,7 @@ func handleSINTERSTORE(ctx context.Context, cmd []string, server utils.Server, c
|
||||
return []byte(fmt.Sprintf(":%d\r\n", intersect.Cardinality())), nil
|
||||
}
|
||||
|
||||
func handleSISMEMBER(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSISMEMBER(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := sismemberKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -434,7 +434,7 @@ func handleSISMEMBER(ctx context.Context, cmd []string, server utils.Server, con
|
||||
return []byte(":1\r\n"), nil
|
||||
}
|
||||
|
||||
func handleSMEMBERS(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSMEMBERS(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := smembersKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -469,7 +469,7 @@ func handleSMEMBERS(ctx context.Context, cmd []string, server utils.Server, conn
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleSMISMEMBER(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSMISMEMBER(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := smismemberKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -512,7 +512,7 @@ func handleSMISMEMBER(ctx context.Context, cmd []string, server utils.Server, co
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleSMOVE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSMOVE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := smoveKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -566,7 +566,7 @@ func handleSMOVE(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte(fmt.Sprintf(":%d\r\n", res)), nil
|
||||
}
|
||||
|
||||
func handleSPOP(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSPOP(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := spopKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -610,7 +610,7 @@ func handleSPOP(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleSRANDMEMBER(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSRANDMEMBER(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := srandmemberKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -654,7 +654,7 @@ func handleSRANDMEMBER(ctx context.Context, cmd []string, server utils.Server, c
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleSREM(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSREM(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := sremKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -682,7 +682,7 @@ func handleSREM(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(fmt.Sprintf(":%d\r\n", count)), nil
|
||||
}
|
||||
|
||||
func handleSUNION(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSUNION(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := sunionKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -733,7 +733,7 @@ func handleSUNION(ctx context.Context, cmd []string, server utils.Server, conn *
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleSUNIONSTORE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSUNIONSTORE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := sunionstoreKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -26,10 +26,10 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var mockServer *server.Server
|
||||
var mockServer *server.EchoVault
|
||||
|
||||
func init() {
|
||||
mockServer = server.NewServer(server.Opts{
|
||||
mockServer = server.NewEchoVault(server.Opts{
|
||||
Config: utils.Config{
|
||||
DataDir: "",
|
||||
EvictionPolicy: utils.NoEviction,
|
||||
|
@@ -27,7 +27,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func handleZADD(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZADD(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zaddKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -178,7 +178,7 @@ func handleZADD(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(fmt.Sprintf(":%d\r\n", set.Cardinality())), nil
|
||||
}
|
||||
|
||||
func handleZCARD(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZCARD(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zcardKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -202,7 +202,7 @@ func handleZCARD(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte(fmt.Sprintf(":%d\r\n", set.Cardinality())), nil
|
||||
}
|
||||
|
||||
func handleZCOUNT(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZCOUNT(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zcountKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -270,7 +270,7 @@ func handleZCOUNT(ctx context.Context, cmd []string, server utils.Server, conn *
|
||||
return []byte(fmt.Sprintf(":%d\r\n", len(members))), nil
|
||||
}
|
||||
|
||||
func handleZLEXCOUNT(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZLEXCOUNT(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zlexcountKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -315,7 +315,7 @@ func handleZLEXCOUNT(ctx context.Context, cmd []string, server utils.Server, con
|
||||
return []byte(fmt.Sprintf(":%d\r\n", count)), nil
|
||||
}
|
||||
|
||||
func handleZDIFF(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZDIFF(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zdiffKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -388,7 +388,7 @@ func handleZDIFF(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleZDIFFSTORE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZDIFFSTORE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zdiffstoreKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -454,7 +454,7 @@ func handleZDIFFSTORE(ctx context.Context, cmd []string, server utils.Server, co
|
||||
return []byte(fmt.Sprintf(":%d\r\n", diff.Cardinality())), nil
|
||||
}
|
||||
|
||||
func handleZINCRBY(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZINCRBY(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zincrbyKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -517,7 +517,7 @@ func handleZINCRBY(ctx context.Context, cmd []string, server utils.Server, conn
|
||||
strconv.FormatFloat(float64(set.Get(member).score), 'f', -1, 64))), nil
|
||||
}
|
||||
|
||||
func handleZINTER(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZINTER(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zinterKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -577,7 +577,7 @@ func handleZINTER(ctx context.Context, cmd []string, server utils.Server, conn *
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleZINTERSTORE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZINTERSTORE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zinterstoreKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -644,7 +644,7 @@ func handleZINTERSTORE(ctx context.Context, cmd []string, server utils.Server, c
|
||||
return []byte(fmt.Sprintf(":%d\r\n", intersect.Cardinality())), nil
|
||||
}
|
||||
|
||||
func handleZMPOP(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZMPOP(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zmpopKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -722,7 +722,7 @@ func handleZMPOP(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte("*0\r\n"), nil
|
||||
}
|
||||
|
||||
func handleZPOP(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZPOP(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zpopKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -773,7 +773,7 @@ func handleZPOP(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleZMSCORE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZMSCORE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zmscoreKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -815,7 +815,7 @@ func handleZMSCORE(ctx context.Context, cmd []string, server utils.Server, conn
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleZRANDMEMBER(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZRANDMEMBER(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zrandmemberKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -870,7 +870,7 @@ func handleZRANDMEMBER(ctx context.Context, cmd []string, server utils.Server, c
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleZRANK(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZRANK(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zrankKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -920,7 +920,7 @@ func handleZRANK(ctx context.Context, cmd []string, server utils.Server, conn *n
|
||||
return []byte("$-1\r\n"), nil
|
||||
}
|
||||
|
||||
func handleZREM(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZREM(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zremKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -952,7 +952,7 @@ func handleZREM(ctx context.Context, cmd []string, server utils.Server, conn *ne
|
||||
return []byte(fmt.Sprintf(":%d\r\n", deletedCount)), nil
|
||||
}
|
||||
|
||||
func handleZSCORE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZSCORE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zscoreKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -981,7 +981,7 @@ func handleZSCORE(ctx context.Context, cmd []string, server utils.Server, conn *
|
||||
return []byte(fmt.Sprintf("$%d\r\n%s\r\n", len(score), score)), nil
|
||||
}
|
||||
|
||||
func handleZREMRANGEBYSCORE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZREMRANGEBYSCORE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zremrangebyscoreKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1025,7 +1025,7 @@ func handleZREMRANGEBYSCORE(ctx context.Context, cmd []string, server utils.Serv
|
||||
return []byte(fmt.Sprintf(":%d\r\n", deletedCount)), nil
|
||||
}
|
||||
|
||||
func handleZREMRANGEBYRANK(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZREMRANGEBYRANK(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zremrangebyrankKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1090,7 +1090,7 @@ func handleZREMRANGEBYRANK(ctx context.Context, cmd []string, server utils.Serve
|
||||
return []byte(fmt.Sprintf(":%d\r\n", deletedCount)), nil
|
||||
}
|
||||
|
||||
func handleZREMRANGEBYLEX(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZREMRANGEBYLEX(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zremrangebylexKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1137,7 +1137,7 @@ func handleZREMRANGEBYLEX(ctx context.Context, cmd []string, server utils.Server
|
||||
return []byte(fmt.Sprintf(":%d\r\n", deletedCount)), nil
|
||||
}
|
||||
|
||||
func handleZRANGE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZRANGE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zrangeKeyCount(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1277,7 +1277,7 @@ func handleZRANGE(ctx context.Context, cmd []string, server utils.Server, conn *
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleZRANGESTORE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZRANGESTORE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zrangeStoreKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1419,7 +1419,7 @@ func handleZRANGESTORE(ctx context.Context, cmd []string, server utils.Server, c
|
||||
return []byte(fmt.Sprintf(":%d\r\n", newSortedSet.Cardinality())), nil
|
||||
}
|
||||
|
||||
func handleZUNION(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZUNION(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
if _, err := zunionKeyFunc(cmd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1473,7 +1473,7 @@ func handleZUNION(ctx context.Context, cmd []string, server utils.Server, conn *
|
||||
return []byte(res), nil
|
||||
}
|
||||
|
||||
func handleZUNIONSTORE(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleZUNIONSTORE(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := zunionstoreKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -28,10 +28,10 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var mockServer *server.Server
|
||||
var mockServer *server.EchoVault
|
||||
|
||||
func init() {
|
||||
mockServer = server.NewServer(server.Opts{
|
||||
mockServer = server.NewEchoVault(server.Opts{
|
||||
Config: utils.Config{
|
||||
DataDir: "",
|
||||
EvictionPolicy: utils.NoEviction,
|
||||
|
@@ -22,7 +22,7 @@ import (
|
||||
"net"
|
||||
)
|
||||
|
||||
func handleSetRange(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSetRange(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := setRangeKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -97,7 +97,7 @@ func handleSetRange(ctx context.Context, cmd []string, server utils.Server, conn
|
||||
return []byte(fmt.Sprintf(":%d\r\n", len(strRunes))), nil
|
||||
}
|
||||
|
||||
func handleStrLen(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleStrLen(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := strLenKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -123,7 +123,7 @@ func handleStrLen(ctx context.Context, cmd []string, server utils.Server, conn *
|
||||
return []byte(fmt.Sprintf(":%d\r\n", len(value))), nil
|
||||
}
|
||||
|
||||
func handleSubStr(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
func handleSubStr(ctx context.Context, cmd []string, server utils.EchoVault, conn *net.Conn) ([]byte, error) {
|
||||
keys, err := subStrKeyFunc(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -26,10 +26,10 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var mockServer *server.Server
|
||||
var mockServer *server.EchoVault
|
||||
|
||||
func init() {
|
||||
mockServer = server.NewServer(server.Opts{
|
||||
mockServer = server.NewEchoVault(server.Opts{
|
||||
Config: utils.Config{
|
||||
DataDir: "",
|
||||
EvictionPolicy: utils.NoEviction,
|
||||
|
@@ -27,7 +27,7 @@ import (
|
||||
|
||||
type FSMOpts struct {
|
||||
Config utils.Config
|
||||
Server utils.Server
|
||||
Server utils.EchoVault
|
||||
GetCommand func(command string) (utils.Command, error)
|
||||
DeleteKey func(ctx context.Context, key string) error
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ import (
|
||||
|
||||
type Opts struct {
|
||||
Config utils.Config
|
||||
Server utils.Server
|
||||
Server utils.EchoVault
|
||||
GetCommand func(command string) (utils.Command, error)
|
||||
DeleteKey func(ctx context.Context, key string) error
|
||||
}
|
||||
|
@@ -22,11 +22,11 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (server *Server) IsInCluster() bool {
|
||||
func (server *EchoVault) IsInCluster() bool {
|
||||
return server.Config.BootstrapCluster || server.Config.JoinAddr != ""
|
||||
}
|
||||
|
||||
func (server *Server) raftApplyDeleteKey(ctx context.Context, key string) error {
|
||||
func (server *EchoVault) raftApplyDeleteKey(ctx context.Context, key string) error {
|
||||
serverId, _ := ctx.Value(utils.ContextServerID("ServerID")).(string)
|
||||
|
||||
deleteKeyRequest := utils.ApplyRequest{
|
||||
@@ -60,7 +60,7 @@ func (server *Server) raftApplyDeleteKey(ctx context.Context, key string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (server *Server) raftApplyCommand(ctx context.Context, cmd []string) ([]byte, error) {
|
||||
func (server *EchoVault) raftApplyCommand(ctx context.Context, cmd []string) ([]byte, error) {
|
||||
serverId, _ := ctx.Value(utils.ContextServerID("ServerID")).(string)
|
||||
connectionId, _ := ctx.Value(utils.ContextConnID("ConnectionID")).(string)
|
||||
|
||||
|
@@ -30,7 +30,7 @@ import (
|
||||
|
||||
// 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.
|
||||
func (server *Server) KeyLock(ctx context.Context, key string) (bool, error) {
|
||||
func (server *EchoVault) KeyLock(ctx context.Context, key string) (bool, error) {
|
||||
// If context did not set deadline, set the default deadline
|
||||
var cancelFunc context.CancelFunc
|
||||
if _, ok := ctx.Deadline(); !ok {
|
||||
@@ -54,7 +54,7 @@ func (server *Server) KeyLock(ctx context.Context, key string) (bool, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (server *Server) KeyUnlock(ctx context.Context, key string) {
|
||||
func (server *EchoVault) KeyUnlock(ctx context.Context, key string) {
|
||||
if _, ok := server.keyLocks[key]; ok {
|
||||
server.keyLocks[key].Unlock()
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (server *Server) KeyUnlock(ctx context.Context, key string) {
|
||||
|
||||
// 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.
|
||||
func (server *Server) KeyRLock(ctx context.Context, key string) (bool, error) {
|
||||
func (server *EchoVault) KeyRLock(ctx context.Context, key string) (bool, error) {
|
||||
// If context did not set deadline, set the default deadline
|
||||
var cancelFunc context.CancelFunc
|
||||
if _, ok := ctx.Deadline(); !ok {
|
||||
@@ -86,13 +86,13 @@ func (server *Server) KeyRLock(ctx context.Context, key string) (bool, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (server *Server) KeyRUnlock(ctx context.Context, key string) {
|
||||
func (server *EchoVault) KeyRUnlock(ctx context.Context, key string) {
|
||||
if _, ok := server.keyLocks[key]; ok {
|
||||
server.keyLocks[key].RUnlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (server *Server) KeyExists(ctx context.Context, key string) bool {
|
||||
func (server *EchoVault) KeyExists(ctx context.Context, key string) bool {
|
||||
entry, ok := server.store[key]
|
||||
if !ok {
|
||||
return false
|
||||
@@ -126,7 +126,7 @@ func (server *Server) KeyExists(ctx context.Context, key string) bool {
|
||||
|
||||
// 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.
|
||||
func (server *Server) CreateKeyAndLock(ctx context.Context, key string) (bool, error) {
|
||||
func (server *EchoVault) CreateKeyAndLock(ctx context.Context, key string) (bool, error) {
|
||||
if utils.IsMaxMemoryExceeded(server.Config.MaxMemory) && server.Config.EvictionPolicy == utils.NoEviction {
|
||||
return false, errors.New("max memory reached, key not created")
|
||||
}
|
||||
@@ -152,7 +152,7 @@ func (server *Server) CreateKeyAndLock(ctx context.Context, key string) (bool, e
|
||||
|
||||
// GetValue retrieves the current value at the specified key.
|
||||
// The key must be read-locked before calling this function.
|
||||
func (server *Server) GetValue(ctx context.Context, key string) interface{} {
|
||||
func (server *EchoVault) GetValue(ctx context.Context, key string) interface{} {
|
||||
if err := server.updateKeyInCache(ctx, key); err != nil {
|
||||
log.Printf("GetValue error: %+v\n", err)
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func (server *Server) GetValue(ctx context.Context, key string) interface{} {
|
||||
// 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 (server *Server) SetValue(ctx context.Context, key string, value interface{}) error {
|
||||
func (server *EchoVault) SetValue(ctx context.Context, key string, value interface{}) error {
|
||||
if utils.IsMaxMemoryExceeded(server.Config.MaxMemory) && server.Config.EvictionPolicy == utils.NoEviction {
|
||||
return errors.New("max memory reached, key value not set")
|
||||
}
|
||||
@@ -188,7 +188,7 @@ func (server *Server) SetValue(ctx context.Context, key string, value interface{
|
||||
|
||||
// The GetExpiry function returns the expiry time associated with the provided key.
|
||||
// The key must be read locked before calling this function.
|
||||
func (server *Server) GetExpiry(ctx context.Context, key string) time.Time {
|
||||
func (server *EchoVault) GetExpiry(ctx context.Context, key string) time.Time {
|
||||
if err := server.updateKeyInCache(ctx, key); err != nil {
|
||||
log.Printf("GetKeyExpiry error: %+v\n", err)
|
||||
}
|
||||
@@ -201,7 +201,7 @@ func (server *Server) GetExpiry(ctx context.Context, key string) time.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 (server *Server) SetExpiry(ctx context.Context, key string, expireAt time.Time, touch bool) {
|
||||
func (server *EchoVault) SetExpiry(ctx context.Context, key string, expireAt time.Time, touch bool) {
|
||||
server.store[key] = utils.KeyData{
|
||||
Value: server.store[key].Value,
|
||||
ExpireAt: expireAt,
|
||||
@@ -225,7 +225,7 @@ func (server *Server) SetExpiry(ctx context.Context, key string, expireAt time.T
|
||||
|
||||
// RemoveExpiry is called by commands that remove key expiry (e.g. PERSIST).
|
||||
// The key must be locked prior ro calling this function.
|
||||
func (server *Server) RemoveExpiry(key string) {
|
||||
func (server *EchoVault) RemoveExpiry(key string) {
|
||||
// Reset expiry time
|
||||
server.store[key] = utils.KeyData{
|
||||
Value: server.store[key].Value,
|
||||
@@ -244,7 +244,7 @@ func (server *Server) RemoveExpiry(key string) {
|
||||
// functions that require a deep copy of the state.
|
||||
// The copy only starts when there's no current copy in progress (represented by StateCopyInProgress atomic boolean)
|
||||
// and when there's no current state mutation in progress (represented by StateMutationInProgress atomic boolean)
|
||||
func (server *Server) GetState() map[string]utils.KeyData {
|
||||
func (server *EchoVault) GetState() map[string]utils.KeyData {
|
||||
// Wait unit there's no state mutation or copy in progress before starting a new copy process.
|
||||
for {
|
||||
if !server.StateCopyInProgress.Load() && !server.StateMutationInProgress.Load() {
|
||||
@@ -261,7 +261,7 @@ func (server *Server) GetState() map[string]utils.KeyData {
|
||||
}
|
||||
|
||||
// DeleteKey removes the key from store, keyLocks and keyExpiry maps.
|
||||
func (server *Server) DeleteKey(ctx context.Context, key string) error {
|
||||
func (server *EchoVault) DeleteKey(ctx context.Context, key string) error {
|
||||
if _, err := server.KeyLock(ctx, key); err != nil {
|
||||
return fmt.Errorf("deleteKey error: %+v", err)
|
||||
}
|
||||
@@ -288,7 +288,7 @@ func (server *Server) DeleteKey(ctx context.Context, key string) error {
|
||||
|
||||
// updateKeyInCache updates either the key access count or the most recent access time in the cache
|
||||
// depending on whether an LFU or LRU strategy was used.
|
||||
func (server *Server) updateKeyInCache(ctx context.Context, key string) error {
|
||||
func (server *EchoVault) updateKeyInCache(ctx context.Context, key string) error {
|
||||
// Only update cache when in standalone mode or when raft leader
|
||||
if server.IsInCluster() || (server.IsInCluster() && !server.raft.IsRaftLeader()) {
|
||||
return nil
|
||||
@@ -326,7 +326,7 @@ func (server *Server) updateKeyInCache(ctx context.Context, key string) error {
|
||||
}
|
||||
|
||||
// adjustMemoryUsage should only be called from standalone server or from raft cluster leader.
|
||||
func (server *Server) adjustMemoryUsage(ctx context.Context) error {
|
||||
func (server *EchoVault) adjustMemoryUsage(ctx context.Context) error {
|
||||
// If max memory is 0, there's no need to adjust memory usage.
|
||||
if server.Config.MaxMemory == 0 {
|
||||
return nil
|
||||
@@ -487,7 +487,7 @@ func (server *Server) adjustMemoryUsage(ctx context.Context) error {
|
||||
// This function will sample 20 keys from the list of keys with an associated TTL,
|
||||
// if the key is expired, it will be evicted.
|
||||
// This function is only executed in standalone mode or by the raft cluster leader.
|
||||
func (server *Server) evictKeysWithExpiredTTL(ctx context.Context) error {
|
||||
func (server *EchoVault) evictKeysWithExpiredTTL(ctx context.Context) error {
|
||||
// Only execute this if we're in standalone mode, or raft cluster leader.
|
||||
if server.IsInCluster() && !server.raft.IsRaftLeader() {
|
||||
return nil
|
||||
|
@@ -23,19 +23,19 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (server *Server) GetAllCommands() []utils.Command {
|
||||
func (server *EchoVault) GetAllCommands() []utils.Command {
|
||||
return server.Commands
|
||||
}
|
||||
|
||||
func (server *Server) GetACL() interface{} {
|
||||
func (server *EchoVault) GetACL() interface{} {
|
||||
return server.ACL
|
||||
}
|
||||
|
||||
func (server *Server) GetPubSub() interface{} {
|
||||
func (server *EchoVault) GetPubSub() interface{} {
|
||||
return server.PubSub
|
||||
}
|
||||
|
||||
func (server *Server) getCommand(cmd string) (utils.Command, error) {
|
||||
func (server *EchoVault) getCommand(cmd string) (utils.Command, error) {
|
||||
for _, command := range server.Commands {
|
||||
if strings.EqualFold(command.Command, cmd) {
|
||||
return command, nil
|
||||
@@ -44,7 +44,7 @@ func (server *Server) getCommand(cmd string) (utils.Command, error) {
|
||||
return utils.Command{}, fmt.Errorf("command %s not supported", cmd)
|
||||
}
|
||||
|
||||
func (server *Server) handleCommand(ctx context.Context, message []byte, conn *net.Conn, replay bool) ([]byte, error) {
|
||||
func (server *EchoVault) handleCommand(ctx context.Context, message []byte, conn *net.Conn, replay bool) ([]byte, error) {
|
||||
cmd, err := utils.Decode(message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -35,7 +35,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
type EchoVault struct {
|
||||
// Config holds the server configuration variables.
|
||||
Config utils.Config
|
||||
|
||||
@@ -92,8 +92,8 @@ type Opts struct {
|
||||
Commands []utils.Command
|
||||
}
|
||||
|
||||
func NewServer(opts Opts) *Server {
|
||||
server := &Server{
|
||||
func NewEchoVault(opts Opts) *EchoVault {
|
||||
server := &EchoVault{
|
||||
Config: opts.Config,
|
||||
ACL: opts.ACL,
|
||||
PubSub: opts.PubSub,
|
||||
@@ -184,7 +184,7 @@ func NewServer(opts Opts) *Server {
|
||||
return server
|
||||
}
|
||||
|
||||
func (server *Server) StartTCP(ctx context.Context) {
|
||||
func (server *EchoVault) StartTCP(ctx context.Context) {
|
||||
conf := server.Config
|
||||
|
||||
listenConfig := net.ListenConfig{
|
||||
@@ -258,7 +258,7 @@ func (server *Server) StartTCP(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (server *Server) handleConnection(ctx context.Context, conn net.Conn) {
|
||||
func (server *EchoVault) handleConnection(ctx context.Context, conn net.Conn) {
|
||||
// If ACL module is loaded, register the connection with the ACL
|
||||
if server.ACL != nil {
|
||||
server.ACL.RegisterConnection(&conn)
|
||||
@@ -333,7 +333,7 @@ func (server *Server) handleConnection(ctx context.Context, conn net.Conn) {
|
||||
}
|
||||
}
|
||||
|
||||
func (server *Server) Start(ctx context.Context) {
|
||||
func (server *EchoVault) Start(ctx context.Context) {
|
||||
conf := server.Config
|
||||
|
||||
if conf.TLS && len(conf.CertKeyPairs) <= 0 {
|
||||
@@ -372,7 +372,7 @@ func (server *Server) Start(ctx context.Context) {
|
||||
server.StartTCP(ctx)
|
||||
}
|
||||
|
||||
func (server *Server) TakeSnapshot() error {
|
||||
func (server *EchoVault) TakeSnapshot() error {
|
||||
if server.SnapshotInProgress.Load() {
|
||||
return errors.New("snapshot already in progress")
|
||||
}
|
||||
@@ -394,31 +394,31 @@ func (server *Server) TakeSnapshot() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (server *Server) StartSnapshot() {
|
||||
func (server *EchoVault) StartSnapshot() {
|
||||
server.SnapshotInProgress.Store(true)
|
||||
}
|
||||
|
||||
func (server *Server) FinishSnapshot() {
|
||||
func (server *EchoVault) FinishSnapshot() {
|
||||
server.SnapshotInProgress.Store(false)
|
||||
}
|
||||
|
||||
func (server *Server) SetLatestSnapshot(msec int64) {
|
||||
func (server *EchoVault) SetLatestSnapshot(msec int64) {
|
||||
server.LatestSnapshotMilliseconds.Store(msec)
|
||||
}
|
||||
|
||||
func (server *Server) GetLatestSnapshot() int64 {
|
||||
func (server *EchoVault) GetLatestSnapshot() int64 {
|
||||
return server.LatestSnapshotMilliseconds.Load()
|
||||
}
|
||||
|
||||
func (server *Server) StartRewriteAOF() {
|
||||
func (server *EchoVault) StartRewriteAOF() {
|
||||
server.RewriteAOFInProgress.Store(true)
|
||||
}
|
||||
|
||||
func (server *Server) FinishRewriteAOF() {
|
||||
func (server *EchoVault) FinishRewriteAOF() {
|
||||
server.RewriteAOFInProgress.Store(false)
|
||||
}
|
||||
|
||||
func (server *Server) RewriteAOF() error {
|
||||
func (server *EchoVault) RewriteAOF() error {
|
||||
if server.RewriteAOFInProgress.Load() {
|
||||
return errors.New("aof rewrite in progress")
|
||||
}
|
||||
@@ -430,14 +430,14 @@ func (server *Server) RewriteAOF() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (server *Server) ShutDown(ctx context.Context) {
|
||||
func (server *EchoVault) ShutDown(ctx context.Context) {
|
||||
if server.IsInCluster() {
|
||||
server.raft.RaftShutdown(ctx)
|
||||
server.memberList.MemberListShutdown(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func (server *Server) InitialiseCaches() {
|
||||
func (server *EchoVault) InitialiseCaches() {
|
||||
// Set up LFU cache
|
||||
server.lfuCache = struct {
|
||||
mutex sync.Mutex
|
||||
|
@@ -131,7 +131,7 @@ There is no limit by default.`, func(memory string) error {
|
||||
tls := flag.Bool("tls", false, "Start the server in TLS mode. Default is false.")
|
||||
mtls := flag.Bool("mtls", false, "Use mTLS to verify the client.")
|
||||
port := flag.Int("port", 7480, "Port to use. Default is 7480")
|
||||
serverId := flag.String("server-id", "1", "Server ID in raft cluster. Leave empty for client.")
|
||||
serverId := flag.String("server-id", "1", "EchoVault ID in raft cluster. Leave empty for client.")
|
||||
joinAddr := flag.String("join-addr", "", "Address of cluster member in a cluster to you want to join.")
|
||||
bindAddr := flag.String("bind-addr", "", "Address to bind the server to.")
|
||||
raftBindPort := flag.Uint("raft-port", 7481, "Port to use for intra-cluster communication. Leave on the client.")
|
||||
|
@@ -26,7 +26,7 @@ type KeyData struct {
|
||||
ExpireAt time.Time
|
||||
}
|
||||
|
||||
type Server interface {
|
||||
type EchoVault interface {
|
||||
KeyLock(ctx context.Context, key string) (bool, error)
|
||||
KeyUnlock(ctx context.Context, key string)
|
||||
KeyRLock(ctx context.Context, key string) (bool, error)
|
||||
@@ -68,7 +68,7 @@ type ApplyResponse struct {
|
||||
}
|
||||
|
||||
type KeyExtractionFunc func(cmd []string) ([]string, error)
|
||||
type HandlerFunc func(ctx context.Context, cmd []string, server Server, conn *net.Conn) ([]byte, error)
|
||||
type HandlerFunc func(ctx context.Context, cmd []string, echovault EchoVault, conn *net.Conn) ([]byte, error)
|
||||
|
||||
type SubCommand struct {
|
||||
Command string
|
||||
|
Reference in New Issue
Block a user