
# Unleash the Power of Configurable, Distributed In-Memory Storage
-EchoVault is a highly configurable, distributed, in-memory data store and cache implemented in Go. It can be imported as a Go library or run as an independent service.
+SugarDB is a highly configurable, distributed, in-memory data store and cache implemented in Go. It can be imported as a Go library or run as an independent service.
-EchoVault aims to provide a rich set of data structures and functions for manipulating data in memory. These data structures include, but are not limited to: Lists, Sets, Sorted Sets, Hashes, and more.
+SugarDB aims to provide a rich set of data structures and functions for manipulating data in memory. These data structures include, but are not limited to: Lists, Sets, Sorted Sets, Hashes, and more.
-EchoVault provides a persistence layer for increased reliability. Both Append-Only files and snapshots can be used to persist data in the disk for recovery in case of unexpected shutdowns.
+SugarDB provides a persistence layer for increased reliability. Both Append-Only files and snapshots can be used to persist data in the disk for recovery in case of unexpected shutdowns.
-Replication is a core feature of EchoVault and is implemented using the RAFT algorithm, allowing you to create a fault-tolerant cluster of EchoVault nodes to improve reliability. If you do not need a replication cluster, you can always run EchoVault in standalone mode and have a fully capable single node.
+Replication is a core feature of SugarDB and is implemented using the RAFT algorithm, allowing you to create a fault-tolerant cluster of SugarDB nodes to improve reliability. If you do not need a replication cluster, you can always run SugarDB in standalone mode and have a fully capable single node.
-EchoVault aims to not only be a server but to be importable to existing projects to enhance them with EchoVault features, this capability is always being worked on and improved.
+SugarDB aims to not only be a server but to be importable to existing projects to enhance them with SugarDB features, this capability is always being worked on and improved.
# Features
-Some key features offered by EchoVault include:
+Some key features offered by SugarDB include:
- TLS and mTLS support for multiple server and client RootCAs.
- Replication cluster support using the RAFT algorithm.
diff --git a/docs/static/img/EchoVault Cover.png b/docs/static/img/EchoVault Cover.png
deleted file mode 100644
index 82a505d..0000000
Binary files a/docs/static/img/EchoVault Cover.png and /dev/null differ
diff --git a/docs/static/img/docusaurus-social-card.jpg b/docs/static/img/docusaurus-social-card.jpg
deleted file mode 100644
index ffcb448..0000000
Binary files a/docs/static/img/docusaurus-social-card.jpg and /dev/null differ
diff --git a/docs/static/img/docusaurus.png b/docs/static/img/docusaurus.png
deleted file mode 100644
index f458149..0000000
Binary files a/docs/static/img/docusaurus.png and /dev/null differ
diff --git a/docs/static/img/favicon.ico b/docs/static/img/favicon.ico
deleted file mode 100644
index c01d54b..0000000
Binary files a/docs/static/img/favicon.ico and /dev/null differ
diff --git a/docs/static/img/echovault-logo.png b/docs/static/img/logo.png
similarity index 100%
rename from docs/static/img/echovault-logo.png
rename to docs/static/img/logo.png
diff --git a/docs/static/img/logo.svg b/docs/static/img/logo.svg
deleted file mode 100644
index 9db6d0d..0000000
--- a/docs/static/img/logo.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/docs/static/img/undraw_docusaurus_mountain.svg b/docs/static/img/undraw_docusaurus_mountain.svg
deleted file mode 100644
index af961c4..0000000
--- a/docs/static/img/undraw_docusaurus_mountain.svg
+++ /dev/null
@@ -1,171 +0,0 @@
-
diff --git a/docs/static/img/undraw_docusaurus_react.svg b/docs/static/img/undraw_docusaurus_react.svg
deleted file mode 100644
index 94b5cf0..0000000
--- a/docs/static/img/undraw_docusaurus_react.svg
+++ /dev/null
@@ -1,170 +0,0 @@
-
diff --git a/docs/static/img/undraw_docusaurus_tree.svg b/docs/static/img/undraw_docusaurus_tree.svg
deleted file mode 100644
index d9161d3..0000000
--- a/docs/static/img/undraw_docusaurus_tree.svg
+++ /dev/null
@@ -1,40 +0,0 @@
-
diff --git a/echovault/config.go b/echovault/config.go
deleted file mode 100644
index 49d2fdb..0000000
--- a/echovault/config.go
+++ /dev/null
@@ -1,331 +0,0 @@
-// Copyright 2024 Kelvin Clement Mwinuka
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package echovault
-
-import (
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
- "time"
-)
-
-// DefaultConfig returns the default configuration.
-// This should be used when using EchoVault as an embedded library.
-func DefaultConfig() config.Config {
- return config.DefaultConfig()
-}
-
-func (server *EchoVault) GetServerInfo() internal.ServerInfo {
- return internal.ServerInfo{
- Server: "echovault",
- Version: constants.Version,
- Id: server.config.ServerID,
- Mode: func() string {
- if server.isInCluster() {
- return "cluster"
- }
- return "standalone"
- }(),
- Role: func() string {
- if !server.isInCluster() {
- return "master"
- }
- if server.raft.IsRaftLeader() {
- return "master"
- }
- return "replica"
- }(),
- Modules: server.ListModules(),
- }
-}
-
-// WithTLS is an option to the NewEchoVault function that allows you to pass a
-// custom TLS to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithTLS(b ...bool) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- if len(b) > 0 {
- echovault.config.TLS = b[0]
- } else {
- echovault.config.TLS = true
- }
- }
-}
-
-// WithMTLS is an option to the NewEchoVault function that allows you to pass a
-// custom MTLS to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithMTLS(b ...bool) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- if len(b) > 0 {
- echovault.config.MTLS = b[0]
- } else {
- echovault.config.MTLS = true
- }
- }
-}
-
-// CertKeyPair defines the paths to the cert and key pair files respectively.
-type CertKeyPair struct {
- Cert string
- Key string
-}
-
-// WithCertKeyPairs is an option to the NewEchoVault function that allows you to pass a
-// custom CertKeyPairs to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithCertKeyPairs(certKeyPairs []CertKeyPair) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- for _, pair := range certKeyPairs {
- echovault.config.CertKeyPairs = append(echovault.config.CertKeyPairs, []string{pair.Cert, pair.Key})
- }
- }
-}
-
-// WithClientCAs is an option to the NewEchoVault function that allows you to pass a
-// custom ClientCAs to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithClientCAs(clientCAs []string) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.ClientCAs = clientCAs
- }
-}
-
-// WithPort is an option to the NewEchoVault function that allows you to pass a
-// custom Port to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithPort(port uint16) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.Port = port
- }
-}
-
-// WithServerID is an option to the NewEchoVault function that allows you to pass a
-// custom ServerID to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithServerID(serverID string) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.ServerID = serverID
- }
-}
-
-// WithJoinAddr is an option to the NewEchoVault function that allows you to pass a
-// custom JoinAddr to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithJoinAddr(joinAddr string) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.JoinAddr = joinAddr
- }
-}
-
-// WithBindAddr is an option to the NewEchoVault function that allows you to pass a
-// custom BindAddr to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithBindAddr(bindAddr string) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.BindAddr = bindAddr
- }
-}
-
-// WithDataDir is an option to the NewEchoVault function that allows you to pass a
-// custom DataDir to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithDataDir(dataDir string) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.DataDir = dataDir
- }
-}
-
-// WithBootstrapCluster is an option to the NewEchoVault function that allows you to pass a
-// custom BootstrapCluster to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithBootstrapCluster(b ...bool) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- if len(b) > 0 {
- echovault.config.BootstrapCluster = b[0]
- } else {
- echovault.config.BootstrapCluster = true
- }
- }
-}
-
-// WithAclConfig is an option to the NewEchoVault function that allows you to pass a
-// custom AclConfig to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithAclConfig(aclConfig string) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.AclConfig = aclConfig
- }
-}
-
-// WithForwardCommand is an option to the NewEchoVault function that allows you to pass a
-// custom ForwardCommand to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithForwardCommand(b ...bool) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- if len(b) > 0 {
- echovault.config.ForwardCommand = b[0]
- } else {
- echovault.config.ForwardCommand = true
- }
- }
-}
-
-// WithRequirePass is an option to the NewEchoVault function that allows you to pass a
-// custom RequirePass to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithRequirePass(b ...bool) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- if len(b) > 0 {
- echovault.config.RequirePass = b[0]
- } else {
- echovault.config.RequirePass = true
- }
- }
-}
-
-// WithPassword is an option to the NewEchoVault function that allows you to pass a
-// custom Password to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithPassword(password string) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.Password = password
- }
-}
-
-// WithSnapShotThreshold is an option to the NewEchoVault function that allows you to pass a
-// custom SnapShotThreshold to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithSnapShotThreshold(snapShotThreshold uint64) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.SnapShotThreshold = snapShotThreshold
- }
-}
-
-// WithSnapshotInterval is an option to the NewEchoVault function that allows you to pass a
-// custom SnapshotInterval to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithSnapshotInterval(snapshotInterval time.Duration) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.SnapshotInterval = snapshotInterval
- }
-}
-
-// WithRestoreSnapshot is an option to the NewEchoVault function that allows you to pass a
-// custom RestoreSnapshot to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithRestoreSnapshot(b ...bool) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- if len(b) > 0 {
- echovault.config.RestoreSnapshot = b[0]
- } else {
- echovault.config.RestoreSnapshot = true
- }
- }
-}
-
-// WithRestoreAOF is an option to the NewEchoVault function that allows you to pass a
-// custom RestoreAOF to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithRestoreAOF(b ...bool) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- if len(b) > 0 {
- echovault.config.RestoreAOF = b[0]
- } else {
- echovault.config.RestoreAOF = true
- }
- }
-}
-
-// WithAOFSyncStrategy is an option to the NewEchoVault function that allows you to pass a
-// custom AOFSyncStrategy to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithAOFSyncStrategy(aOFSyncStrategy string) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.AOFSyncStrategy = aOFSyncStrategy
- }
-}
-
-// WithMaxMemory is an option to the NewEchoVault function that allows you to pass a
-// custom MaxMemory to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithMaxMemory(maxMemory uint64) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.MaxMemory = maxMemory
- }
-}
-
-// WithEvictionPolicy is an option to the NewEchoVault function that allows you to pass a
-// custom EvictionPolicy to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithEvictionPolicy(evictionPolicy string) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.EvictionPolicy = evictionPolicy
- }
-}
-
-// WithEvictionSample is an option to the NewEchoVault function that allows you to pass a
-// custom EvictionSample to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithEvictionSample(evictionSample uint) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.EvictionSample = evictionSample
- }
-}
-
-// WithEvictionInterval is an option to the NewEchoVault function that allows you to pass a
-// custom EvictionInterval to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithEvictionInterval(evictionInterval time.Duration) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.EvictionInterval = evictionInterval
- }
-}
-
-// WithModules is an option to the NewEchoVault function that allows you to pass a
-// custom Modules to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithModules(modules []string) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.Modules = modules
- }
-}
-
-// WithDiscoveryPort is an option to the NewEchoVault function that allows you to pass a
-// custom DiscoveryPort to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithDiscoveryPort(discoveryPort uint16) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.DiscoveryPort = discoveryPort
- }
-}
-
-// WithRaftBindAddr is an option to the NewEchoVault function that allows you to pass a
-// custom RaftBindAddr to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithRaftBindAddr(raftBindAddr string) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.RaftBindAddr = raftBindAddr
- }
-}
-
-// WithRaftBindPort is an option to the NewEchoVault function that allows you to pass a
-// custom RaftBindPort to EchoVault.
-// If not specified, EchoVault will use the default configuration from config.DefaultConfig().
-func WithRaftBindPort(raftBindPort uint16) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
- echovault.config.RaftBindPort = raftBindPort
- }
-}
diff --git a/echovault/test_helpers.go b/echovault/test_helpers.go
deleted file mode 100644
index 979b354..0000000
--- a/echovault/test_helpers.go
+++ /dev/null
@@ -1,39 +0,0 @@
-package echovault
-
-import (
- "context"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
-)
-
-func createEchoVault() *EchoVault {
- ev, _ := NewEchoVault(
- WithConfig(config.Config{
- DataDir: "",
- EvictionPolicy: constants.NoEviction,
- }),
- )
- return ev
-}
-
-func createEchoVaultWithConfig(conf config.Config) *EchoVault {
- ev, _ := NewEchoVault(
- WithConfig(conf),
- )
- return ev
-}
-
-func presetValue(server *EchoVault, ctx context.Context, key string, value interface{}) error {
- ctx = context.WithValue(ctx, "Database", 0)
- if err := server.setValues(ctx, map[string]interface{}{key: value}); err != nil {
- return err
- }
- return nil
-}
-
-func presetKeyData(server *EchoVault, ctx context.Context, key string, data internal.KeyData) {
- ctx = context.WithValue(ctx, "Database", 0)
- _ = server.setValues(ctx, map[string]interface{}{key: data.Value})
- server.setExpiry(ctx, key, data.ExpireAt, false)
-}
diff --git a/go.mod b/go.mod
index 09d0f73..864c0d9 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
-module github.com/echovault/echovault
+module github.com/echovault/sugardb
-go 1.21.4
+go 1.22.0
require (
github.com/go-test/deep v1.1.1
diff --git a/images/EchoVault GitHub Cover.png b/images/EchoVault GitHub Cover.png
deleted file mode 100644
index 82a505d..0000000
Binary files a/images/EchoVault GitHub Cover.png and /dev/null differ
diff --git a/images/logo.png b/images/logo.png
new file mode 100644
index 0000000..47b76be
Binary files /dev/null and b/images/logo.png differ
diff --git a/internal/aof/engine.go b/internal/aof/engine.go
index 4319b7a..9c186c5 100644
--- a/internal/aof/engine.go
+++ b/internal/aof/engine.go
@@ -18,10 +18,10 @@ package aof
import (
"fmt"
- "github.com/echovault/echovault/internal"
- logstore "github.com/echovault/echovault/internal/aof/log"
- "github.com/echovault/echovault/internal/aof/preamble"
- "github.com/echovault/echovault/internal/clock"
+ "github.com/echovault/sugardb/internal"
+ logstore "github.com/echovault/sugardb/internal/aof/log"
+ "github.com/echovault/sugardb/internal/aof/preamble"
+ "github.com/echovault/sugardb/internal/clock"
"log"
"sync"
)
diff --git a/internal/aof/engine_test.go b/internal/aof/engine_test.go
index 47ecc76..3b0264a 100644
--- a/internal/aof/engine_test.go
+++ b/internal/aof/engine_test.go
@@ -16,11 +16,11 @@ package aof_test
import (
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/aof"
- "github.com/echovault/echovault/internal/aof/log"
- "github.com/echovault/echovault/internal/aof/preamble"
- "github.com/echovault/echovault/internal/clock"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/aof"
+ "github.com/echovault/sugardb/internal/aof/log"
+ "github.com/echovault/sugardb/internal/aof/preamble"
+ "github.com/echovault/sugardb/internal/clock"
"os"
"sync/atomic"
"testing"
diff --git a/internal/aof/log/store.go b/internal/aof/log/store.go
index 09c71cf..5af280b 100644
--- a/internal/aof/log/store.go
+++ b/internal/aof/log/store.go
@@ -16,8 +16,8 @@ package log
import (
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/clock"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/clock"
"github.com/tidwall/resp"
"io"
"log"
diff --git a/internal/aof/log/store_test.go b/internal/aof/log/store_test.go
index 9064235..d0f6aa9 100644
--- a/internal/aof/log/store_test.go
+++ b/internal/aof/log/store_test.go
@@ -17,8 +17,8 @@ package log_test
import (
"bytes"
"fmt"
- "github.com/echovault/echovault/internal/aof/log"
- "github.com/echovault/echovault/internal/clock"
+ "github.com/echovault/sugardb/internal/aof/log"
+ "github.com/echovault/sugardb/internal/clock"
"os"
"path"
"testing"
diff --git a/internal/aof/preamble/store.go b/internal/aof/preamble/store.go
index 4c22235..3812c85 100644
--- a/internal/aof/preamble/store.go
+++ b/internal/aof/preamble/store.go
@@ -17,8 +17,8 @@ package preamble
import (
"encoding/json"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/clock"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/clock"
"io"
"os"
"path"
diff --git a/internal/aof/preamble/store_test.go b/internal/aof/preamble/store_test.go
index c38e6d1..efddbdc 100644
--- a/internal/aof/preamble/store_test.go
+++ b/internal/aof/preamble/store_test.go
@@ -15,9 +15,9 @@
package preamble_test
import (
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/aof/preamble"
- "github.com/echovault/echovault/internal/clock"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/aof/preamble"
+ "github.com/echovault/sugardb/internal/clock"
"os"
"path"
"testing"
diff --git a/internal/config/config.go b/internal/config/config.go
index c01299f..fe235b5 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -19,8 +19,8 @@ import (
"errors"
"flag"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"log"
"os"
"path"
@@ -135,7 +135,7 @@ There is no limit by default.`, func(memory string) error {
var modules []string
flag.Func(
"loadmodule",
- `Path to shared object library to extend EchoVault commands (e.g. /path/to/plugin.so)`,
+ `Path to shared object library to extend SugarDB commands (e.g. /path/to/plugin.so)`,
func(p string) error {
if !strings.HasSuffix(p, ".so") {
return fmt.Errorf("\"%s\" is not a .so file", p)
@@ -147,7 +147,7 @@ There is no limit by default.`, func(memory string) error {
tls := flag.Bool("tls", false, "Start the echovault 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", "EchoVault ID in raft cluster. Leave empty for client.")
+ serverId := flag.String("server-id", "1", "SugarDB 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", "127.0.0.1", "Address to bind the echovault to.")
discoveryPort := flag.Uint("discovery-port", 7946, "Port to use for memberlist cluster discovery.")
diff --git a/internal/config/default.go b/internal/config/default.go
index b16a545..8073545 100644
--- a/internal/config/default.go
+++ b/internal/config/default.go
@@ -1,8 +1,8 @@
package config
import (
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"time"
)
diff --git a/internal/constants/const.go b/internal/constants/const.go
index 868a8a9..6356df9 100644
--- a/internal/constants/const.go
+++ b/internal/constants/const.go
@@ -14,7 +14,7 @@
package constants
-const Version = "0.10.1" // Next EchoVault version. Update this before each release.
+const Version = "0.13.0" // Next SugarDB version. Update this before each release.
const (
ACLModule = "acl"
diff --git a/internal/eviction/lfu_test.go b/internal/eviction/lfu_test.go
index 68f7d14..118111f 100644
--- a/internal/eviction/lfu_test.go
+++ b/internal/eviction/lfu_test.go
@@ -16,7 +16,7 @@ package eviction_test
import (
"container/heap"
- "github.com/echovault/echovault/internal/eviction"
+ "github.com/echovault/sugardb/internal/eviction"
"sync"
"testing"
)
diff --git a/internal/eviction/lru_test.go b/internal/eviction/lru_test.go
index 7aff9dd..fdc850e 100644
--- a/internal/eviction/lru_test.go
+++ b/internal/eviction/lru_test.go
@@ -16,7 +16,7 @@ package eviction_test
import (
"container/heap"
- "github.com/echovault/echovault/internal/eviction"
+ "github.com/echovault/sugardb/internal/eviction"
"testing"
"time"
)
diff --git a/internal/memberlist/delegate.go b/internal/memberlist/delegate.go
index 26bf200..a9433e8 100644
--- a/internal/memberlist/delegate.go
+++ b/internal/memberlist/delegate.go
@@ -18,8 +18,8 @@ import (
"context"
"encoding/json"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
"github.com/hashicorp/memberlist"
"github.com/hashicorp/raft"
"log"
diff --git a/internal/memberlist/memberlist.go b/internal/memberlist/memberlist.go
index 00c37b3..861bd25 100644
--- a/internal/memberlist/memberlist.go
+++ b/internal/memberlist/memberlist.go
@@ -18,8 +18,8 @@ import (
"context"
"crypto/md5"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
"log"
"sync"
"time"
diff --git a/internal/modules/acl/acl.go b/internal/modules/acl/acl.go
index 8387b89..ba8ee83 100644
--- a/internal/modules/acl/acl.go
+++ b/internal/modules/acl/acl.go
@@ -21,9 +21,9 @@ import (
"encoding/json"
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
"github.com/gobwas/glob"
"gopkg.in/yaml.v3"
"log"
@@ -46,7 +46,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 echovault that are currently registered with the ACL module
- Config config.Config // EchoVault configuration that contains the relevant ACL config options
+ Config config.Config // SugarDB configuration that contains the relevant ACL config options
GlobPatterns map[string]glob.Glob
}
diff --git a/internal/modules/acl/commands.go b/internal/modules/acl/commands.go
index b4ac08f..07c8462 100644
--- a/internal/modules/acl/commands.go
+++ b/internal/modules/acl/commands.go
@@ -18,8 +18,8 @@ import (
"encoding/json"
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"gopkg.in/yaml.v3"
"log"
"os"
diff --git a/internal/modules/acl/commands_test.go b/internal/modules/acl/commands_test.go
index 8fbe635..15cffdc 100644
--- a/internal/modules/acl/commands_test.go
+++ b/internal/modules/acl/commands_test.go
@@ -18,10 +18,10 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
- "github.com/echovault/echovault/echovault"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/sugardb"
"github.com/tidwall/resp"
"os"
"path"
@@ -31,7 +31,7 @@ import (
"testing"
)
-func setUpServer(port int, requirePass bool, aclConfig string) (*echovault.EchoVault, error) {
+func setUpServer(port int, requirePass bool, aclConfig string) (*sugardb.SugarDB, error) {
conf := config.Config{
BindAddr: "localhost",
Port: uint16(port),
@@ -42,8 +42,8 @@ func setUpServer(port int, requirePass bool, aclConfig string) (*echovault.EchoV
AclConfig: aclConfig,
}
- mockServer, err := echovault.NewEchoVault(
- echovault.WithConfig(conf),
+ mockServer, err := sugardb.NewSugarDB(
+ sugardb.WithConfig(conf),
)
if err != nil {
return nil, err
@@ -67,8 +67,8 @@ func setUpServer(port int, requirePass bool, aclConfig string) (*echovault.EchoV
return mockServer, nil
}
-func generateInitialTestUsers() []echovault.User {
- return []echovault.User{
+func generateInitialTestUsers() []sugardb.User {
+ return []sugardb.User{
{
// User with both hash password and plaintext password.
Username: "with_password_user",
@@ -215,7 +215,7 @@ func Test_ACL(t *testing.T) {
})
// Add users to be used in test cases.
- users := []echovault.User{
+ users := []sugardb.User{
{
// User with nokeys flag enables.
Username: "test_nokeys",
@@ -648,7 +648,7 @@ func Test_ACL(t *testing.T) {
tests := []struct {
name string
- presetUser *echovault.User
+ presetUser *sugardb.User
cmd []resp.Value
wantRes string
wantErr string
@@ -720,7 +720,7 @@ func Test_ACL(t *testing.T) {
},
{
name: "4. Remove plaintext and SHA256 password from existing user",
- presetUser: &echovault.User{
+ presetUser: &sugardb.User{
Username: "set_user_4",
Enabled: true,
AddPlainPasswords: []string{"set_user_4_plaintext_password_1", "set_user_4_plaintext_password_2"},
@@ -1033,7 +1033,7 @@ func Test_ACL(t *testing.T) {
},
{
name: "17. Delete all existing users passwords using 'nopass'",
- presetUser: &echovault.User{
+ presetUser: &sugardb.User{
Username: "set_user_17",
Enabled: true,
NoPassword: true,
@@ -1060,7 +1060,7 @@ func Test_ACL(t *testing.T) {
},
{
name: "18. Clear all of an existing user's passwords using 'resetpass'",
- presetUser: &echovault.User{
+ presetUser: &sugardb.User{
Username: "set_user_18",
Enabled: true,
NoPassword: true,
@@ -1087,7 +1087,7 @@ func Test_ACL(t *testing.T) {
},
{
name: "19. Clear all of an existing user's command privileges using 'nocommands'",
- presetUser: &echovault.User{
+ presetUser: &sugardb.User{
Username: "set_user_19",
Enabled: true,
IncludeCommands: []string{"acl|getuser", "acl|setuser", "acl|deluser"},
@@ -1113,7 +1113,7 @@ func Test_ACL(t *testing.T) {
},
{
name: "20. Clear all of an existing user's allowed keys using 'resetkeys'",
- presetUser: &echovault.User{
+ presetUser: &sugardb.User{
Username: "set_user_20",
Enabled: true,
IncludeWriteKeys: []string{"key1", "key2", "key3", "key4", "key5", "key6"},
@@ -1139,7 +1139,7 @@ func Test_ACL(t *testing.T) {
},
{
name: "21. Allow user to access all channels using 'resetchannels'",
- presetUser: &echovault.User{
+ presetUser: &sugardb.User{
Username: "set_user_21",
Enabled: true,
IncludeChannels: []string{"channel1", "channel2"},
@@ -1242,14 +1242,14 @@ func Test_ACL(t *testing.T) {
tests := []struct {
name string
- presetUser *echovault.User
+ presetUser *sugardb.User
cmd []resp.Value
wantRes []resp.Value
wantErr string
}{
{
name: "1. Get the user and all their details",
- presetUser: &echovault.User{
+ presetUser: &sugardb.User{
Username: "get_user_1",
Enabled: true,
NoPassword: false,
@@ -1410,14 +1410,14 @@ func Test_ACL(t *testing.T) {
tests := []struct {
name string
- presetUser *echovault.User
+ presetUser *sugardb.User
cmd []resp.Value
wantRes string
wantErr string
}{
{
name: "1. Delete existing user while skipping default user and non-existent user",
- presetUser: &echovault.User{
+ presetUser: &sugardb.User{
Username: "user_to_delete",
Enabled: true,
},
@@ -1592,14 +1592,14 @@ func Test_ACL(t *testing.T) {
tests := []struct {
name string
- presetUsers []*echovault.User
+ presetUsers []*sugardb.User
cmd []resp.Value
wantRes []string
wantErr string
}{
{
name: "1. Get the user and all their details",
- presetUsers: []*echovault.User{
+ presetUsers: []*sugardb.User{
{
Username: "list_user_1",
Enabled: true,
@@ -1762,7 +1762,7 @@ func Test_ACL(t *testing.T) {
},
}
- servers := make([]*echovault.EchoVault, len(tests))
+ servers := make([]*sugardb.SugarDB, len(tests))
mut := sync.Mutex{}
t.Cleanup(func() {
_ = os.RemoveAll(baseDir)
@@ -1896,14 +1896,14 @@ func Test_ACL(t *testing.T) {
tests := []struct {
name string
path string
- users []echovault.User // Add users after server startup.
- cmd []resp.Value // Command to load users from ACL config.
+ users []sugardb.User // Add users after server startup.
+ cmd []resp.Value // Command to load users from ACL config.
want []string
}{
{
name: "1. Load config from the .json file",
path: path.Join(baseDir, "json_test.json"),
- users: []echovault.User{
+ users: []sugardb.User{
{Username: "user1", Enabled: true},
},
cmd: []resp.Value{resp.StringValue("ACL"), resp.StringValue("LOAD"), resp.StringValue("REPLACE")},
@@ -1919,7 +1919,7 @@ func Test_ACL(t *testing.T) {
{
name: "2. Load users from the .yaml file",
path: path.Join(baseDir, "yaml_test.yaml"),
- users: []echovault.User{
+ users: []sugardb.User{
{Username: "user1", Enabled: true},
},
cmd: []resp.Value{resp.StringValue("ACL"), resp.StringValue("LOAD"), resp.StringValue("REPLACE")},
@@ -1935,7 +1935,7 @@ func Test_ACL(t *testing.T) {
{
name: "3. Load users from the .yml file",
path: path.Join(baseDir, "yml_test.yml"),
- users: []echovault.User{
+ users: []sugardb.User{
{Username: "user1", Enabled: true},
},
cmd: []resp.Value{resp.StringValue("ACL"), resp.StringValue("LOAD"), resp.StringValue("REPLACE")},
@@ -1951,7 +1951,7 @@ func Test_ACL(t *testing.T) {
{
name: "4. Merge loaded users",
path: path.Join(baseDir, "merge.yml"),
- users: []echovault.User{
+ users: []sugardb.User{
{ // Disable user1.
Username: "user1",
Enabled: false,
@@ -1979,7 +1979,7 @@ func Test_ACL(t *testing.T) {
{
name: "5. Replace loaded users",
path: path.Join(baseDir, "replace.yml"),
- users: []echovault.User{
+ users: []sugardb.User{
{ // Disable user1.
Username: "user1",
Enabled: false,
@@ -2006,7 +2006,7 @@ func Test_ACL(t *testing.T) {
},
}
- servers := make([]*echovault.EchoVault, len(tests))
+ servers := make([]*sugardb.SugarDB, len(tests))
mut := sync.Mutex{}
t.Cleanup(func() {
_ = os.RemoveAll(baseDir)
diff --git a/internal/modules/admin/commands.go b/internal/modules/admin/commands.go
index ca39586..727a1f5 100644
--- a/internal/modules/admin/commands.go
+++ b/internal/modules/admin/commands.go
@@ -17,8 +17,8 @@ package admin
import (
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"github.com/gobwas/glob"
"slices"
"strings"
diff --git a/internal/modules/admin/commands_test.go b/internal/modules/admin/commands_test.go
index 5ca76cd..71dc401 100644
--- a/internal/modules/admin/commands_test.go
+++ b/internal/modules/admin/commands_test.go
@@ -17,20 +17,20 @@ package admin_test
import (
"errors"
"fmt"
- "github.com/echovault/echovault/echovault"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/clock"
- "github.com/echovault/echovault/internal/constants"
- "github.com/echovault/echovault/internal/modules/acl"
- "github.com/echovault/echovault/internal/modules/admin"
- "github.com/echovault/echovault/internal/modules/connection"
- "github.com/echovault/echovault/internal/modules/generic"
- "github.com/echovault/echovault/internal/modules/hash"
- "github.com/echovault/echovault/internal/modules/list"
- "github.com/echovault/echovault/internal/modules/pubsub"
- "github.com/echovault/echovault/internal/modules/set"
- "github.com/echovault/echovault/internal/modules/sorted_set"
- str "github.com/echovault/echovault/internal/modules/string"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/clock"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/internal/modules/acl"
+ "github.com/echovault/sugardb/internal/modules/admin"
+ "github.com/echovault/sugardb/internal/modules/connection"
+ "github.com/echovault/sugardb/internal/modules/generic"
+ "github.com/echovault/sugardb/internal/modules/hash"
+ "github.com/echovault/sugardb/internal/modules/list"
+ "github.com/echovault/sugardb/internal/modules/pubsub"
+ "github.com/echovault/sugardb/internal/modules/set"
+ "github.com/echovault/sugardb/internal/modules/sorted_set"
+ str "github.com/echovault/sugardb/internal/modules/string"
+ "github.com/echovault/sugardb/sugardb"
"github.com/tidwall/resp"
"os"
"path"
@@ -40,13 +40,13 @@ import (
"time"
)
-func setupServer(port uint16) (*echovault.EchoVault, error) {
- cfg := echovault.DefaultConfig()
+func setupServer(port uint16) (*sugardb.SugarDB, error) {
+ cfg := sugardb.DefaultConfig()
cfg.DataDir = ""
cfg.BindAddr = "localhost"
cfg.Port = port
cfg.EvictionPolicy = constants.NoEviction
- return echovault.NewEchoVault(echovault.WithConfig(cfg))
+ return sugardb.NewSugarDB(sugardb.WithConfig(cfg))
}
func Test_AdminCommands(t *testing.T) {
@@ -688,8 +688,8 @@ func Test_AdminCommands(t *testing.T) {
name string
dataDir string
values map[string]string
- snapshotFunc func(mockServer *echovault.EchoVault, port int) error
- lastSaveFunc func(mockServer *echovault.EchoVault, port int) (int, error)
+ snapshotFunc func(mockServer *sugardb.SugarDB, port int) error
+ lastSaveFunc func(mockServer *sugardb.SugarDB, port int) (int, error)
wantLastSave int
}{
{
@@ -701,7 +701,7 @@ func Test_AdminCommands(t *testing.T) {
"key3": "value3",
"key4": "value4",
},
- snapshotFunc: func(mockServer *echovault.EchoVault, port int) error {
+ snapshotFunc: func(mockServer *sugardb.SugarDB, port int) error {
// Start the server's TCP listener
go func() {
mockServer.Start()
@@ -726,7 +726,7 @@ func Test_AdminCommands(t *testing.T) {
}
return nil
},
- lastSaveFunc: func(mockServer *echovault.EchoVault, port int) (int, error) {
+ lastSaveFunc: func(mockServer *sugardb.SugarDB, port int) (int, error) {
conn, err := internal.GetConnection("localhost", port)
if err != nil {
return 0, err
@@ -758,13 +758,13 @@ func Test_AdminCommands(t *testing.T) {
return
}
- conf := echovault.DefaultConfig()
+ conf := sugardb.DefaultConfig()
conf.DataDir = test.dataDir
conf.BindAddr = "localhost"
conf.Port = uint16(port)
conf.RestoreSnapshot = true
- mockServer, err := echovault.NewEchoVault(echovault.WithConfig(conf))
+ mockServer, err := sugardb.NewSugarDB(sugardb.WithConfig(conf))
if err != nil {
t.Error(err)
return
@@ -776,7 +776,7 @@ func Test_AdminCommands(t *testing.T) {
// Trigger some write commands
for key, value := range test.values {
- if _, _, err = mockServer.Set(key, value, echovault.SETOptions{}); err != nil {
+ if _, _, err = mockServer.Set(key, value, sugardb.SETOptions{}); err != nil {
t.Error(err)
return
}
@@ -793,7 +793,7 @@ func Test_AdminCommands(t *testing.T) {
ticker.Stop()
// Restart server with the same config. This should restore the snapshot
- mockServer, err = echovault.NewEchoVault(echovault.WithConfig(conf))
+ mockServer, err = sugardb.NewSugarDB(sugardb.WithConfig(conf))
if err != nil {
t.Error(err)
return
@@ -867,7 +867,7 @@ func Test_AdminCommands(t *testing.T) {
return
}
- conf := echovault.DefaultConfig()
+ conf := sugardb.DefaultConfig()
conf.BindAddr = "localhost"
conf.Port = uint16(port)
conf.RestoreAOF = true
@@ -875,7 +875,7 @@ func Test_AdminCommands(t *testing.T) {
conf.AOFSyncStrategy = "always"
// Start new server
- mockServer, err := echovault.NewEchoVault(echovault.WithConfig(conf))
+ mockServer, err := sugardb.NewSugarDB(sugardb.WithConfig(conf))
if err != nil {
t.Error(err)
return
@@ -952,12 +952,12 @@ func Test_AdminCommands(t *testing.T) {
// Yield
<-ticker.C
- // Shutdown the EchoVault instance and close current client connection
+ // Shutdown the SugarDB instance and close current client connection
mockServer.ShutDown()
_ = conn.Close()
- // Start another instance of EchoVault
- mockServer, err = echovault.NewEchoVault(echovault.WithConfig(conf))
+ // Start another instance of SugarDB
+ mockServer, err = sugardb.NewSugarDB(sugardb.WithConfig(conf))
if err != nil {
t.Error(err)
return
diff --git a/internal/modules/connection/commands.go b/internal/modules/connection/commands.go
index 387cf3f..543bc56 100644
--- a/internal/modules/connection/commands.go
+++ b/internal/modules/connection/commands.go
@@ -17,12 +17,12 @@ package connection
import (
"errors"
"fmt"
- "github.com/echovault/echovault/internal/modules/acl"
+ "github.com/echovault/sugardb/internal/modules/acl"
"slices"
"strconv"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
)
func handleAuth(params internal.HandlerFuncParams) ([]byte, error) {
diff --git a/internal/modules/connection/commands_test.go b/internal/modules/connection/commands_test.go
index 4fbf9bb..2266e72 100644
--- a/internal/modules/connection/commands_test.go
+++ b/internal/modules/connection/commands_test.go
@@ -21,20 +21,20 @@ import (
"encoding/hex"
"errors"
"fmt"
- "github.com/echovault/echovault/internal/modules/connection"
+ "github.com/echovault/sugardb/internal/modules/connection"
"reflect"
"strconv"
"strings"
"testing"
- "github.com/echovault/echovault/echovault"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/sugardb"
"github.com/tidwall/resp"
)
-func setUpServer(port int, requirePass bool, aclConfig string) (*echovault.EchoVault, error) {
+func setUpServer(port int, requirePass bool, aclConfig string) (*sugardb.SugarDB, error) {
conf := config.Config{
BindAddr: "localhost",
Port: uint16(port),
@@ -45,8 +45,8 @@ func setUpServer(port int, requirePass bool, aclConfig string) (*echovault.EchoV
AclConfig: aclConfig,
}
- mockServer, err := echovault.NewEchoVault(
- echovault.WithConfig(conf),
+ mockServer, err := sugardb.NewSugarDB(
+ sugardb.WithConfig(conf),
)
if err != nil {
return nil, err
@@ -62,8 +62,8 @@ func setUpServer(port int, requirePass bool, aclConfig string) (*echovault.EchoV
return mockServer, nil
}
-func generateInitialTestUsers() []echovault.User {
- return []echovault.User{
+func generateInitialTestUsers() []sugardb.User {
+ return []sugardb.User{
{
// User with both hash password and plaintext password.
Username: "with_password_user",
@@ -323,8 +323,8 @@ func Test_Connection(t *testing.T) {
expectedErr error
}{
{
- command: []resp.Value{resp.StringValue("ECHO"), resp.StringValue("Hello, EchoVault!")},
- expected: "Hello, EchoVault!",
+ command: []resp.Value{resp.StringValue("ECHO"), resp.StringValue("Hello, SugarDB!")},
+ expected: "Hello, SugarDB!",
expectedErr: nil,
},
{
@@ -335,7 +335,7 @@ func Test_Connection(t *testing.T) {
{
command: []resp.Value{
resp.StringValue("ECHO"),
- resp.StringValue("Hello, EchoVault!"),
+ resp.StringValue("Hello, SugarDB!"),
resp.StringValue("Once more"),
},
expected: "",
@@ -397,7 +397,7 @@ func Test_Connection(t *testing.T) {
command: []resp.Value{resp.StringValue("HELLO")},
wantRes: connection.BuildHelloResponse(
internal.ServerInfo{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: "",
Mode: "standalone",
@@ -417,7 +417,7 @@ func Test_Connection(t *testing.T) {
command: []resp.Value{resp.StringValue("HELLO"), resp.StringValue("2")},
wantRes: connection.BuildHelloResponse(
internal.ServerInfo{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: "",
Mode: "standalone",
@@ -437,7 +437,7 @@ func Test_Connection(t *testing.T) {
command: []resp.Value{resp.StringValue("HELLO"), resp.StringValue("3")},
wantRes: connection.BuildHelloResponse(
internal.ServerInfo{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: "",
Mode: "standalone",
@@ -463,7 +463,7 @@ func Test_Connection(t *testing.T) {
},
wantRes: connection.BuildHelloResponse(
internal.ServerInfo{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: "",
Mode: "standalone",
@@ -502,7 +502,7 @@ func Test_Connection(t *testing.T) {
},
wantRes: connection.BuildHelloResponse(
internal.ServerInfo{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: "",
Mode: "standalone",
diff --git a/internal/modules/connection/utils.go b/internal/modules/connection/utils.go
index d584993..3acd2ab 100644
--- a/internal/modules/connection/utils.go
+++ b/internal/modules/connection/utils.go
@@ -2,8 +2,8 @@ package connection
import (
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"strings"
)
diff --git a/internal/modules/generic/commands.go b/internal/modules/generic/commands.go
index 3b6a870..b321f56 100644
--- a/internal/modules/generic/commands.go
+++ b/internal/modules/generic/commands.go
@@ -23,8 +23,8 @@ import (
"strings"
"time"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
)
type KeyObject struct {
diff --git a/internal/modules/generic/commands_test.go b/internal/modules/generic/commands_test.go
index b9c1268..900343b 100644
--- a/internal/modules/generic/commands_test.go
+++ b/internal/modules/generic/commands_test.go
@@ -22,13 +22,13 @@ import (
"testing"
"time"
- "github.com/echovault/echovault/echovault"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/clock"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
- "github.com/echovault/echovault/internal/modules/set"
- "github.com/echovault/echovault/internal/modules/sorted_set"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/clock"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/internal/modules/set"
+ "github.com/echovault/sugardb/internal/modules/sorted_set"
+ "github.com/echovault/sugardb/sugardb"
"github.com/tidwall/resp"
)
@@ -46,8 +46,8 @@ func Test_Generic(t *testing.T) {
return
}
- mockServer, err := echovault.NewEchoVault(
- echovault.WithConfig(config.Config{
+ mockServer, err := sugardb.NewSugarDB(
+ sugardb.WithConfig(config.Config{
BindAddr: "localhost",
Port: uint16(port),
DataDir: "",
@@ -2634,8 +2634,8 @@ func Test_Generic(t *testing.T) {
t.Error(err)
return
}
- mockServer, err := echovault.NewEchoVault(
- echovault.WithConfig(config.Config{
+ mockServer, err := sugardb.NewSugarDB(
+ sugardb.WithConfig(config.Config{
BindAddr: "localhost",
Port: uint16(port),
DataDir: "",
@@ -2662,7 +2662,7 @@ func Test_Generic(t *testing.T) {
_, _, _ = mockServer.Set(
fmt.Sprintf("key%d", k),
fmt.Sprintf("value%d", k),
- echovault.SETOptions{},
+ sugardb.SETOptions{},
)
}
}
@@ -2768,7 +2768,7 @@ func Test_Generic(t *testing.T) {
_, _, err := mockServer.Set(
fmt.Sprintf("RandomKey%d", i),
fmt.Sprintf("Value%d", i),
- echovault.SETOptions{},
+ sugardb.SETOptions{},
)
if err != nil {
t.Error(err)
@@ -3346,8 +3346,8 @@ func Test_LFU_Generic(t *testing.T) {
duration := time.Duration(30) * time.Second
- mockServer, err := echovault.NewEchoVault(
- echovault.WithConfig(config.Config{
+ mockServer, err := sugardb.NewSugarDB(
+ sugardb.WithConfig(config.Config{
BindAddr: "localhost",
Port: uint16(port),
DataDir: "",
@@ -3527,8 +3527,8 @@ func Test_LRU_Generic(t *testing.T) {
duration := time.Duration(30) * time.Second
- mockServer, err := echovault.NewEchoVault(
- echovault.WithConfig(config.Config{
+ mockServer, err := sugardb.NewSugarDB(
+ sugardb.WithConfig(config.Config{
BindAddr: "localhost",
Port: uint16(port),
DataDir: "",
diff --git a/internal/modules/generic/key_funcs.go b/internal/modules/generic/key_funcs.go
index c1a3c77..0d071b8 100644
--- a/internal/modules/generic/key_funcs.go
+++ b/internal/modules/generic/key_funcs.go
@@ -17,8 +17,8 @@ package generic
import (
"errors"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
)
func setKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
diff --git a/internal/modules/generic/utils.go b/internal/modules/generic/utils.go
index 3e5b215..184b36c 100644
--- a/internal/modules/generic/utils.go
+++ b/internal/modules/generic/utils.go
@@ -17,7 +17,7 @@ package generic
import (
"errors"
"fmt"
- "github.com/echovault/echovault/internal/clock"
+ "github.com/echovault/sugardb/internal/clock"
"strconv"
"strings"
"time"
diff --git a/internal/modules/hash/commands.go b/internal/modules/hash/commands.go
index 73707b9..d5a501e 100644
--- a/internal/modules/hash/commands.go
+++ b/internal/modules/hash/commands.go
@@ -17,8 +17,8 @@ package hash
import (
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"math/rand"
"slices"
"strconv"
diff --git a/internal/modules/hash/commands_test.go b/internal/modules/hash/commands_test.go
index 1d61df5..4f98acb 100644
--- a/internal/modules/hash/commands_test.go
+++ b/internal/modules/hash/commands_test.go
@@ -16,10 +16,10 @@ package hash_test
import (
"errors"
- "github.com/echovault/echovault/echovault"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/sugardb"
"github.com/tidwall/resp"
"slices"
"strconv"
@@ -34,8 +34,8 @@ func Test_Hash(t *testing.T) {
return
}
- mockServer, err := echovault.NewEchoVault(
- echovault.WithConfig(config.Config{
+ mockServer, err := sugardb.NewSugarDB(
+ sugardb.WithConfig(config.Config{
BindAddr: "localhost",
Port: uint16(port),
DataDir: "",
diff --git a/internal/modules/hash/key_funcs.go b/internal/modules/hash/key_funcs.go
index 6d9f17d..3033f20 100644
--- a/internal/modules/hash/key_funcs.go
+++ b/internal/modules/hash/key_funcs.go
@@ -16,8 +16,8 @@ package hash
import (
"errors"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
)
func hsetKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
diff --git a/internal/modules/list/commands.go b/internal/modules/list/commands.go
index 935e9ef..03c0d67 100644
--- a/internal/modules/list/commands.go
+++ b/internal/modules/list/commands.go
@@ -17,8 +17,8 @@ package list
import (
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"slices"
"strconv"
"strings"
diff --git a/internal/modules/list/commands_test.go b/internal/modules/list/commands_test.go
index 69fa0f6..2efe9e6 100644
--- a/internal/modules/list/commands_test.go
+++ b/internal/modules/list/commands_test.go
@@ -16,10 +16,10 @@ package list_test
import (
"errors"
- "github.com/echovault/echovault/echovault"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/sugardb"
"github.com/tidwall/resp"
"go/types"
"slices"
@@ -35,8 +35,8 @@ func Test_List(t *testing.T) {
return
}
- mockServer, err := echovault.NewEchoVault(
- echovault.WithConfig(config.Config{
+ mockServer, err := sugardb.NewSugarDB(
+ sugardb.WithConfig(config.Config{
BindAddr: "localhost",
Port: uint16(port),
DataDir: "",
diff --git a/internal/modules/list/key_funcs.go b/internal/modules/list/key_funcs.go
index 5dca498..190c79d 100644
--- a/internal/modules/list/key_funcs.go
+++ b/internal/modules/list/key_funcs.go
@@ -16,8 +16,8 @@ package list
import (
"errors"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
)
func lpushKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
diff --git a/internal/modules/pubsub/commands.go b/internal/modules/pubsub/commands.go
index eb8e1b2..a6c89bb 100644
--- a/internal/modules/pubsub/commands.go
+++ b/internal/modules/pubsub/commands.go
@@ -17,8 +17,8 @@ package pubsub
import (
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"strings"
)
diff --git a/internal/modules/pubsub/commands_test.go b/internal/modules/pubsub/commands_test.go
index fbf8bf5..6b3b1dd 100644
--- a/internal/modules/pubsub/commands_test.go
+++ b/internal/modules/pubsub/commands_test.go
@@ -15,10 +15,10 @@
package pubsub_test
import (
- "github.com/echovault/echovault/echovault"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/sugardb"
"github.com/tidwall/resp"
"net"
"slices"
@@ -27,9 +27,9 @@ import (
"testing"
)
-func setUpServer(port int) (*echovault.EchoVault, error) {
- return echovault.NewEchoVault(
- echovault.WithConfig(config.Config{
+func setUpServer(port int) (*sugardb.SugarDB, error) {
+ return sugardb.NewSugarDB(
+ sugardb.WithConfig(config.Config{
BindAddr: "localhost",
Port: uint16(port),
DataDir: "",
diff --git a/internal/modules/set/commands.go b/internal/modules/set/commands.go
index 6b5b949..4193438 100644
--- a/internal/modules/set/commands.go
+++ b/internal/modules/set/commands.go
@@ -17,8 +17,8 @@ package set
import (
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"slices"
"strings"
)
diff --git a/internal/modules/set/commands_test.go b/internal/modules/set/commands_test.go
index dd9af2c..aeefd06 100644
--- a/internal/modules/set/commands_test.go
+++ b/internal/modules/set/commands_test.go
@@ -16,11 +16,11 @@ package set_test
import (
"errors"
- "github.com/echovault/echovault/echovault"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
- "github.com/echovault/echovault/internal/modules/set"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/internal/modules/set"
+ "github.com/echovault/sugardb/sugardb"
"github.com/tidwall/resp"
"slices"
"strconv"
@@ -35,8 +35,8 @@ func Test_Set(t *testing.T) {
return
}
- mockServer, err := echovault.NewEchoVault(
- echovault.WithConfig(config.Config{
+ mockServer, err := sugardb.NewSugarDB(
+ sugardb.WithConfig(config.Config{
BindAddr: "localhost",
Port: uint16(port),
DataDir: "",
diff --git a/internal/modules/set/key_funcs.go b/internal/modules/set/key_funcs.go
index 391f846..9ee3aa3 100644
--- a/internal/modules/set/key_funcs.go
+++ b/internal/modules/set/key_funcs.go
@@ -16,8 +16,8 @@ package set
import (
"errors"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"slices"
"strings"
)
diff --git a/internal/modules/set/set.go b/internal/modules/set/set.go
index e5463bf..c07e6e4 100644
--- a/internal/modules/set/set.go
+++ b/internal/modules/set/set.go
@@ -15,7 +15,7 @@
package set
import (
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
"math/rand"
"slices"
)
diff --git a/internal/modules/sorted_set/commands.go b/internal/modules/sorted_set/commands.go
index aa27555..b28b6a9 100644
--- a/internal/modules/sorted_set/commands.go
+++ b/internal/modules/sorted_set/commands.go
@@ -18,8 +18,8 @@ import (
"cmp"
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"math"
"slices"
"strconv"
diff --git a/internal/modules/sorted_set/commands_test.go b/internal/modules/sorted_set/commands_test.go
index e0c4303..b19286f 100644
--- a/internal/modules/sorted_set/commands_test.go
+++ b/internal/modules/sorted_set/commands_test.go
@@ -22,11 +22,11 @@ import (
"strings"
"testing"
- "github.com/echovault/echovault/echovault"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
- "github.com/echovault/echovault/internal/modules/sorted_set"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/internal/modules/sorted_set"
+ "github.com/echovault/sugardb/sugardb"
"github.com/tidwall/resp"
)
@@ -37,8 +37,8 @@ func Test_SortedSet(t *testing.T) {
return
}
- mockServer, err := echovault.NewEchoVault(
- echovault.WithConfig(config.Config{
+ mockServer, err := sugardb.NewSugarDB(
+ sugardb.WithConfig(config.Config{
BindAddr: "localhost",
Port: uint16(port),
DataDir: "",
diff --git a/internal/modules/sorted_set/key_funcs.go b/internal/modules/sorted_set/key_funcs.go
index 05ffff6..238f569 100644
--- a/internal/modules/sorted_set/key_funcs.go
+++ b/internal/modules/sorted_set/key_funcs.go
@@ -16,8 +16,8 @@ package sorted_set
import (
"errors"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
"slices"
"strings"
)
diff --git a/internal/modules/sorted_set/sorted_set.go b/internal/modules/sorted_set/sorted_set.go
index 9769668..af5e1a1 100644
--- a/internal/modules/sorted_set/sorted_set.go
+++ b/internal/modules/sorted_set/sorted_set.go
@@ -17,7 +17,7 @@ package sorted_set
import (
"cmp"
"errors"
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
"math"
"math/rand"
"slices"
diff --git a/internal/modules/string/commands.go b/internal/modules/string/commands.go
index 799f774..00efa9b 100644
--- a/internal/modules/string/commands.go
+++ b/internal/modules/string/commands.go
@@ -18,8 +18,8 @@ import (
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
)
func handleSetRange(params internal.HandlerFuncParams) ([]byte, error) {
diff --git a/internal/modules/string/commands_test.go b/internal/modules/string/commands_test.go
index 8b91ebf..ad8d940 100644
--- a/internal/modules/string/commands_test.go
+++ b/internal/modules/string/commands_test.go
@@ -20,10 +20,10 @@ import (
"strings"
"testing"
- "github.com/echovault/echovault/echovault"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/sugardb"
"github.com/tidwall/resp"
)
@@ -34,8 +34,8 @@ func Test_String(t *testing.T) {
return
}
- mockServer, err := echovault.NewEchoVault(
- echovault.WithConfig(config.Config{
+ mockServer, err := sugardb.NewSugarDB(
+ sugardb.WithConfig(config.Config{
BindAddr: "localhost",
Port: uint16(port),
DataDir: "",
diff --git a/internal/modules/string/key_funcs.go b/internal/modules/string/key_funcs.go
index 792f6bc..d86eae3 100644
--- a/internal/modules/string/key_funcs.go
+++ b/internal/modules/string/key_funcs.go
@@ -17,8 +17,8 @@ package str
import (
"errors"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
)
func setRangeKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
diff --git a/internal/raft/fsm.go b/internal/raft/fsm.go
index 71cf101..d30d570 100644
--- a/internal/raft/fsm.go
+++ b/internal/raft/fsm.go
@@ -18,8 +18,8 @@ import (
"context"
"encoding/json"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
"github.com/hashicorp/raft"
"io"
"log"
diff --git a/internal/raft/fsm_snapshot.go b/internal/raft/fsm_snapshot.go
index 3ecef45..49aee0f 100644
--- a/internal/raft/fsm_snapshot.go
+++ b/internal/raft/fsm_snapshot.go
@@ -16,8 +16,8 @@ package raft
import (
"encoding/json"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
"github.com/hashicorp/raft"
"strconv"
"strings"
diff --git a/internal/raft/raft.go b/internal/raft/raft.go
index 8ef573d..4bbbaf5 100644
--- a/internal/raft/raft.go
+++ b/internal/raft/raft.go
@@ -18,9 +18,9 @@ import (
"context"
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/memberlist"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/memberlist"
"log"
"net"
"os"
diff --git a/internal/snapshot/snapshot.go b/internal/snapshot/snapshot.go
index 017e3e7..a2e0ad8 100644
--- a/internal/snapshot/snapshot.go
+++ b/internal/snapshot/snapshot.go
@@ -19,8 +19,8 @@ import (
"encoding/json"
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/clock"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/clock"
"io"
"io/fs"
"log"
diff --git a/internal/snapshot/snapshot_test.go b/internal/snapshot/snapshot_test.go
index c0c5ca6..a81d8a2 100644
--- a/internal/snapshot/snapshot_test.go
+++ b/internal/snapshot/snapshot_test.go
@@ -16,9 +16,9 @@ package snapshot_test
import (
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/clock"
- "github.com/echovault/echovault/internal/snapshot"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/clock"
+ "github.com/echovault/sugardb/internal/snapshot"
"os"
"sync/atomic"
"testing"
diff --git a/internal/types.go b/internal/types.go
index 23de999..16c9058 100644
--- a/internal/types.go
+++ b/internal/types.go
@@ -16,7 +16,7 @@ package internal
import (
"context"
- "github.com/echovault/echovault/internal/clock"
+ "github.com/echovault/sugardb/internal/clock"
"net"
"time"
)
@@ -81,10 +81,10 @@ type KeyExtractionFuncResult struct {
type KeyExtractionFunc func(cmd []string) (KeyExtractionFuncResult, error)
// HandlerFuncParams is the object passed to a command handler when a command is triggered.
-// These params are provided to commands by the EchoVault engine to help the command hook into functions from the
+// These params are provided to commands by the SugarDB engine to help the command hook into functions from the
// echovault package.
type HandlerFuncParams struct {
- // Context is the context passed from the EchoVault instance.
+ // Context is the context passed from the SugarDB instance.
Context context.Context
// Command is the string slice contains the command (e.g []string{"SET", "key", "value"})
Command []string
@@ -108,19 +108,19 @@ type HandlerFuncParams struct {
// Use this when making use of time methods like .Now and .After.
// This inversion of control is a helper for testing as the clock is automatically mocked in tests.
GetClock func() clock.Clock
- // GetAllCommands returns all the commands loaded in the EchoVault instance.
+ // GetAllCommands returns all the commands loaded in the SugarDB instance.
GetAllCommands func() []Command
- // GetACL returns the EchoVault instance's ACL engine.
+ // GetACL returns the SugarDB instance's ACL engine.
// There's no need to use this outside of the acl package,
- // ACL authorizations for all commands will be handled automatically by the EchoVault instance as long as the
+ // ACL authorizations for all commands will be handled automatically by the SugarDB instance as long as the
// commands KeyExtractionFunc returns the correct keys.
GetACL func() interface{}
- // GetPubSub returns the EchoVault instance's PubSub engine.
+ // GetPubSub returns the SugarDB instance's PubSub engine.
// There's no need to use this outside of the pubsub package.
GetPubSub func() interface{}
- // TakeSnapshot triggers a snapshot by the EchoVault instance.
+ // TakeSnapshot triggers a snapshot by the SugarDB instance.
TakeSnapshot func() error
- // RewriteAOF triggers a compaction of the commands logs by the EchoVault instance.
+ // RewriteAOF triggers a compaction of the commands logs by the SugarDB instance.
RewriteAOF func() error
// GetLatestSnapshotTime returns the latest snapshot timestamp.
GetLatestSnapshotTime func() int64
@@ -130,7 +130,7 @@ type HandlerFuncParams struct {
// UnloadModule removes the specified module.
// This unloads both custom modules and internal modules.
UnloadModule func(module string)
- // ListModules returns the list of modules loaded in the EchoVault instance.
+ // ListModules returns the list of modules loaded in the SugarDB instance.
ListModules func() []string
// SetConnectionInfo sets the connection's protocol and clientname.
SetConnectionInfo func(conn *net.Conn, clientname string, protocol int, database int)
diff --git a/internal/utils.go b/internal/utils.go
index a0af6c3..ae94d68 100644
--- a/internal/utils.go
+++ b/internal/utils.go
@@ -21,7 +21,7 @@ import (
"crypto/tls"
"errors"
"fmt"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal/constants"
"io"
"log"
"math/big"
diff --git a/echovault/api_acl.go b/sugardb/api_acl.go
similarity index 94%
rename from echovault/api_acl.go
rename to sugardb/api_acl.go
index d56e43f..25e92d2 100644
--- a/echovault/api_acl.go
+++ b/sugardb/api_acl.go
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"bytes"
"fmt"
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
"github.com/tidwall/resp"
"strings"
)
@@ -117,13 +117,13 @@ type User struct {
// `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
+// Returns: string slice of categories loaded in SugarDB if category is not specified. Otherwise, returns string
// slice of commands within the specified category.
//
// Errors:
//
// "category
not found" - when the provided category is not found in the loaded commands.
-func (server *EchoVault) ACLCat(category ...string) ([]string, error) {
+func (server *SugarDB) ACLCat(category ...string) ([]string, error) {
cmd := []string{"ACL", "CAT"}
if len(category) > 0 {
cmd = append(cmd, category[0])
@@ -136,7 +136,7 @@ func (server *EchoVault) ACLCat(category ...string) ([]string, error) {
}
// ACLUsers returns a string slice containing the usernames of all the loaded users in the ACL module.
-func (server *EchoVault) ACLUsers() ([]string, error) {
+func (server *SugarDB) ACLUsers() ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "USERS"}), nil, false, true)
if err != nil {
return nil, err
@@ -152,7 +152,7 @@ func (server *EchoVault) ACLUsers() ([]string, error) {
// `user` - User - The user object to add/update.
//
// Returns: true if the user is successfully created/updated.
-func (server *EchoVault) ACLSetUser(user User) (bool, error) {
+func (server *SugarDB) ACLSetUser(user User) (bool, error) {
cmd := []string{"ACL", "SETUSER", user.Username}
if user.Enabled {
@@ -290,7 +290,7 @@ func (server *EchoVault) ACLSetUser(user User) (bool, error) {
// Errors:
//
// "user not found" - if the user requested does not exist in the ACL rules.
-func (server *EchoVault) ACLGetUser(username string) (map[string][]string, error) {
+func (server *SugarDB) ACLGetUser(username string) (map[string][]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "GETUSER", username}), nil, false, true)
if err != nil {
return nil, err
@@ -327,7 +327,7 @@ func (server *EchoVault) ACLGetUser(username string) (map[string][]string, error
// `usernames` - ...string - A string of usernames to delete from the ACL module.
//
// Returns: true if the deletion is successful.
-func (server *EchoVault) ACLDelUser(usernames ...string) (bool, error) {
+func (server *SugarDB) ACLDelUser(usernames ...string) (bool, error) {
cmd := append([]string{"ACL", "DELUSER"}, usernames...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -338,7 +338,7 @@ func (server *EchoVault) ACLDelUser(usernames ...string) (bool, error) {
}
// ACLList lists all the currently loaded ACL users and their rules.
-func (server *EchoVault) ACLList() ([]string, error) {
+func (server *SugarDB) ACLList() ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "LIST"}), nil, false, true)
if err != nil {
return nil, err
@@ -354,7 +354,7 @@ func (server *EchoVault) ACLList() ([]string, error) {
// `options` - ACLLoadOptions - modifies the load behaviour.
//
// Returns: true if the load is successful.
-func (server *EchoVault) ACLLoad(options ACLLoadOptions) (bool, error) {
+func (server *SugarDB) ACLLoad(options ACLLoadOptions) (bool, error) {
cmd := []string{"ACL", "LOAD"}
switch {
case options.Merge:
@@ -377,7 +377,7 @@ func (server *EchoVault) ACLLoad(options ACLLoadOptions) (bool, error) {
// ACLSave saves the current ACL configuration to the configured ACL file.
//
// Returns: true if the save is successful.
-func (server *EchoVault) ACLSave() (bool, error) {
+func (server *SugarDB) ACLSave() (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "SAVE"}), nil, false, true)
if err != nil {
return false, err
diff --git a/echovault/api_acl_test.go b/sugardb/api_acl_test.go
similarity index 95%
rename from echovault/api_acl_test.go
rename to sugardb/api_acl_test.go
index d6b0538..4d70a06 100644
--- a/echovault/api_acl_test.go
+++ b/sugardb/api_acl_test.go
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"crypto/sha256"
"encoding/hex"
"fmt"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal/constants"
"os"
"path"
"slices"
@@ -124,8 +124,8 @@ func generateSHA256Password(plain string) string {
return hex.EncodeToString(h.Sum(nil))
}
-func TestEchoVault_ACLCat(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ACLCat(t *testing.T) {
+ server := createSugarDB()
getCategoryCommands := func(category string) []string {
var commands []string
@@ -264,8 +264,8 @@ func TestEchoVault_ACLCat(t *testing.T) {
}
}
-func TestEchoVault_ACLUsers(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ACLUsers(t *testing.T) {
+ server := createSugarDB()
// Set Users
users := []User{
@@ -369,7 +369,7 @@ func TestEchoVault_ACLUsers(t *testing.T) {
}
}
-func TestEchoVault_ACLConfig(t *testing.T) {
+func TestSugarDB_ACLConfig(t *testing.T) {
t.Run("Test_HandleSave", func(t *testing.T) {
baseDir := path.Join(".", "testdata", "save")
t.Cleanup(func() {
@@ -422,7 +422,7 @@ func TestEchoVault_ACLConfig(t *testing.T) {
conf := DefaultConfig()
conf.DataDir = ""
conf.AclConfig = test.path
- server := createEchoVaultWithConfig(conf)
+ server := createSugarDBWithConfig(conf)
// Add the initial test users to the ACL module.
for _, user := range generateInitialTestUsers() {
if _, err := server.ACLSetUser(user); err != nil {
@@ -444,7 +444,7 @@ func TestEchoVault_ACLConfig(t *testing.T) {
server.ShutDown()
// Restart server
- server = createEchoVaultWithConfig(conf)
+ server = createSugarDBWithConfig(conf)
// Get users rules list.
list, err := server.ACLList()
@@ -474,8 +474,8 @@ func TestEchoVault_ACLConfig(t *testing.T) {
tests := []struct {
name string
path string
- users []User // Add users after server startup.
- loadFunc func(server *EchoVault) (bool, error) // Function to load users from ACL config.
+ users []User // Add users after server startup.
+ loadFunc func(server *SugarDB) (bool, error) // Function to load users from ACL config.
want []string
}{
{
@@ -484,7 +484,7 @@ func TestEchoVault_ACLConfig(t *testing.T) {
users: []User{
{Username: "user1", Enabled: true},
},
- loadFunc: func(server *EchoVault) (bool, error) {
+ loadFunc: func(server *SugarDB) (bool, error) {
return server.ACLLoad(ACLLoadOptions{})
},
want: []string{
@@ -502,7 +502,7 @@ func TestEchoVault_ACLConfig(t *testing.T) {
users: []User{
{Username: "user1", Enabled: true},
},
- loadFunc: func(server *EchoVault) (bool, error) {
+ loadFunc: func(server *SugarDB) (bool, error) {
return server.ACLLoad(ACLLoadOptions{})
},
want: []string{
@@ -520,7 +520,7 @@ func TestEchoVault_ACLConfig(t *testing.T) {
users: []User{
{Username: "user1", Enabled: true},
},
- loadFunc: func(server *EchoVault) (bool, error) {
+ loadFunc: func(server *SugarDB) (bool, error) {
return server.ACLLoad(ACLLoadOptions{})
},
want: []string{
@@ -550,7 +550,7 @@ func TestEchoVault_ACLConfig(t *testing.T) {
ExcludeChannels: []string{"channel[34]"},
},
},
- loadFunc: func(server *EchoVault) (bool, error) {
+ loadFunc: func(server *SugarDB) (bool, error) {
return server.ACLLoad(ACLLoadOptions{Merge: true, Replace: false})
},
want: []string{
@@ -580,7 +580,7 @@ func TestEchoVault_ACLConfig(t *testing.T) {
ExcludeChannels: []string{"channel[34]"},
},
},
- loadFunc: func(server *EchoVault) (bool, error) {
+ loadFunc: func(server *SugarDB) (bool, error) {
return server.ACLLoad(ACLLoadOptions{Replace: true, Merge: false})
},
want: []string{
@@ -600,7 +600,7 @@ func TestEchoVault_ACLConfig(t *testing.T) {
conf := DefaultConfig()
conf.DataDir = ""
conf.AclConfig = test.path
- server := createEchoVaultWithConfig(conf)
+ server := createSugarDBWithConfig(conf)
// Add the initial test users to the ACL module.
for _, user := range generateInitialTestUsers() {
if _, err := server.ACLSetUser(user); err != nil {
diff --git a/echovault/api_admin.go b/sugardb/api_admin.go
similarity index 93%
rename from echovault/api_admin.go
rename to sugardb/api_admin.go
index 1fde374..19290cf 100644
--- a/echovault/api_admin.go
+++ b/sugardb/api_admin.go
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"context"
"fmt"
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
"slices"
"strings"
)
@@ -53,7 +53,7 @@ type CommandKeyExtractionFunc func(cmd []string) (CommandKeyExtractionFuncResult
// 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.
+// CommandHandlerFuncParams contains the helper parameters passed to the command's handler by SugarDB.
//
// Command is the string slice command containing the command that triggered this handler.
//
@@ -71,7 +71,7 @@ type CommandHandlerFuncParams struct {
SetValues func(ctx context.Context, entries map[string]interface{}) error
}
-// CommandOptions provides the specification of the command to be added to the EchoVault instance.
+// CommandOptions provides the specification of the command to be added to the SugarDB instance.
//
// Command is the keyword used to trigger this command (e.g. LPUSH, ZADD, ACL ...).
//
@@ -132,14 +132,14 @@ type SubCommandOptions struct {
HandlerFunc CommandHandlerFunc
}
-// CommandList returns the list of commands currently loaded in the EchoVault instance.
+// CommandList returns the list of commands currently loaded in the SugarDB instance.
//
// Parameters:
//
// `options` - CommandListOptions.
//
// Returns: a string slice of all the loaded commands. SubCommands are represented as "command|subcommand".
-func (server *EchoVault) CommandList(options ...CommandListOptions) ([]string, error) {
+func (server *SugarDB) CommandList(options ...CommandListOptions) ([]string, error) {
cmd := []string{"COMMAND", "LIST"}
if len(options) > 0 {
@@ -161,10 +161,10 @@ func (server *EchoVault) CommandList(options ...CommandListOptions) ([]string, e
return internal.ParseStringArrayResponse(b)
}
-// CommandCount returns the number of commands currently loaded in the EchoVault instance.
+// CommandCount returns the number of commands currently loaded in the SugarDB instance.
//
// Returns: integer representing the count of all available commands.
-func (server *EchoVault) CommandCount() (int, error) {
+func (server *SugarDB) CommandCount() (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"COMMAND", "COUNT"}), nil, false, true)
if err != nil {
return 0, err
@@ -176,7 +176,7 @@ func (server *EchoVault) CommandCount() (int, error) {
//
// Returns: true if the save was started. The OK response does not confirm that the save was successfully synced to
// file. Only that the background process has started.
-func (server *EchoVault) Save() (bool, error) {
+func (server *SugarDB) Save() (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SAVE"}), nil, false, true)
if err != nil {
return false, err
@@ -186,7 +186,7 @@ func (server *EchoVault) Save() (bool, error) {
}
// LastSave returns the unix epoch milliseconds timestamp of the last save.
-func (server *EchoVault) LastSave() (int, error) {
+func (server *SugarDB) LastSave() (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LASTSAVE"}), nil, false, true)
if err != nil {
return 0, err
@@ -195,7 +195,7 @@ func (server *EchoVault) LastSave() (int, error) {
}
// RewriteAOF triggers a compaction of the AOF file.
-func (server *EchoVault) RewriteAOF() (string, error) {
+func (server *SugarDB) RewriteAOF() (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"REWRITEAOF"}), nil, false, true)
if err != nil {
return "", err
@@ -203,7 +203,7 @@ func (server *EchoVault) RewriteAOF() (string, error) {
return internal.ParseStringResponse(b)
}
-// AddCommand adds a new command to EchoVault. The added command can be executed using the ExecuteCommand method.
+// AddCommand adds a new command to SugarDB. The added command can be executed using the ExecuteCommand method.
//
// Parameters:
//
@@ -212,7 +212,7 @@ func (server *EchoVault) RewriteAOF() (string, error) {
// Errors:
//
// "command already exists" - If a command with the same command name as the passed command already exists.
-func (server *EchoVault) AddCommand(command CommandOptions) error {
+func (server *SugarDB) AddCommand(command CommandOptions) error {
server.commandsRWMut.Lock()
defer server.commandsRWMut.Unlock()
// Check if command already exists
@@ -330,8 +330,8 @@ func (server *EchoVault) AddCommand(command CommandOptions) error {
return nil
}
-// 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.
+// ExecuteCommand executes the command passed to it. If 1 string is passed, SugarDB will try to
+// execute the command. If 2 strings are passed, SugarDB 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
@@ -353,11 +353,11 @@ func (server *EchoVault) AddCommand(command CommandOptions) error {
// "command not supported" - If the command does not exist.
//
// "command not supported" - If the command exists but the subcommand does not exist for that command.
-func (server *EchoVault) ExecuteCommand(command ...string) ([]byte, error) {
+func (server *SugarDB) ExecuteCommand(command ...string) ([]byte, error) {
return server.handleCommand(server.context, internal.EncodeCommand(command), nil, false, true)
}
-// RemoveCommand removes the specified command or subcommand from EchoVault.
+// RemoveCommand removes the specified command or subcommand from SugarDB.
// 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.
@@ -371,7 +371,7 @@ func (server *EchoVault) ExecuteCommand(command ...string) ([]byte, error) {
// Parameters:
//
// `command` - ...string.
-func (server *EchoVault) RemoveCommand(command ...string) {
+func (server *SugarDB) RemoveCommand(command ...string) {
server.commandsRWMut.Lock()
defer server.commandsRWMut.Unlock()
diff --git a/echovault/api_admin_test.go b/sugardb/api_admin_test.go
similarity index 95%
rename from echovault/api_admin_test.go
rename to sugardb/api_admin_test.go
index 889bbd2..2a437fb 100644
--- a/echovault/api_admin_test.go
+++ b/sugardb/api_admin_test.go
@@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"bytes"
"errors"
"fmt"
- "github.com/echovault/echovault/internal/clock"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal/clock"
+ "github.com/echovault/sugardb/internal/constants"
"github.com/tidwall/resp"
"os"
"path"
@@ -31,7 +31,7 @@ import (
"time"
)
-func TestEchoVault_AddCommand(t *testing.T) {
+func TestSugarDB_AddCommand(t *testing.T) {
type args struct {
command CommandOptions
}
@@ -176,7 +176,7 @@ The value passed must be an integer.`,
},
}
for _, tt := range tests {
- server := createEchoVault()
+ server := createSugarDB()
t.Run(tt.name, func(t *testing.T) {
if err := server.AddCommand(tt.args.command); (err != nil) != tt.wantErr {
t.Errorf("AddCommand() error = %v, wantErr %v", err, tt.wantErr)
@@ -199,7 +199,7 @@ The value passed must be an integer.`,
}
}
-func TestEchoVault_ExecuteCommand(t *testing.T) {
+func TestSugarDB_ExecuteCommand(t *testing.T) {
type args struct {
key string
presetValue []string
@@ -233,7 +233,7 @@ func TestEchoVault_ExecuteCommand(t *testing.T) {
},
}
for _, tt := range tests {
- server := createEchoVault()
+ server := createSugarDB()
t.Run(tt.name, func(t *testing.T) {
if tt.args.presetValue != nil {
_, _ = server.LPush(tt.args.key, tt.args.presetValue...)
@@ -253,7 +253,7 @@ func TestEchoVault_ExecuteCommand(t *testing.T) {
}
}
-func TestEchoVault_RemoveCommand(t *testing.T) {
+func TestSugarDB_RemoveCommand(t *testing.T) {
type args struct {
removeCommand []string
executeCommand []string
@@ -289,7 +289,7 @@ func TestEchoVault_RemoveCommand(t *testing.T) {
},
}
for _, tt := range tests {
- server := createEchoVault()
+ server := createSugarDB()
t.Run(tt.name, func(t *testing.T) {
server.RemoveCommand(tt.args.removeCommand...)
_, err := server.ExecuteCommand(tt.args.executeCommand...)
@@ -302,12 +302,12 @@ func TestEchoVault_RemoveCommand(t *testing.T) {
}
}
-func TestEchoVault_Plugins(t *testing.T) {
+func TestSugarDB_Plugins(t *testing.T) {
t.Cleanup(func() {
_ = os.RemoveAll("./testdata/modules")
})
- server := createEchoVault()
+ server := createSugarDB()
moduleSet := path.Join(".", "testdata", "modules", "module_set", "module_set.so")
moduleGet := path.Join(".", "testdata", "modules", "module_get", "module_get.so")
@@ -378,8 +378,8 @@ func TestEchoVault_Plugins(t *testing.T) {
}
}
-func TestEchoVault_CommandList(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_CommandList(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -468,8 +468,8 @@ func TestEchoVault_CommandList(t *testing.T) {
}
}
-func TestEchoVault_CommandCount(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_CommandCount(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -508,11 +508,11 @@ func TestEchoVault_CommandCount(t *testing.T) {
}
}
-func TestEchoVault_Save(t *testing.T) {
+func TestSugarDB_Save(t *testing.T) {
conf := DefaultConfig()
conf.DataDir = path.Join(".", "testdata", "data")
conf.EvictionPolicy = constants.NoEviction
- server := createEchoVaultWithConfig(conf)
+ server := createSugarDBWithConfig(conf)
tests := []struct {
name string
@@ -539,8 +539,8 @@ func TestEchoVault_Save(t *testing.T) {
}
}
-func TestEchoVault_LastSave(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_LastSave(t *testing.T) {
+ server := createSugarDB()
server.setLatestSnapshot(clock.NewClock().Now().Add(5 * time.Minute).UnixMilli())
tests := []struct {
diff --git a/echovault/api_connection.go b/sugardb/api_connection.go
similarity index 93%
rename from echovault/api_connection.go
rename to sugardb/api_connection.go
index e3f3b03..acc789c 100644
--- a/echovault/api_connection.go
+++ b/sugardb/api_connection.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"errors"
@@ -29,7 +29,7 @@ import (
// Errors:
//
// "protocol must be either 2 or 3" - When the provided protocol is not either 2 or 3.
-func (server *EchoVault) SetProtocol(protocol int) error {
+func (server *SugarDB) SetProtocol(protocol int) error {
if !slices.Contains([]int{2, 3}, protocol) {
return errors.New("protocol must be either 2 or 3")
}
@@ -50,7 +50,7 @@ func (server *EchoVault) SetProtocol(protocol int) error {
// Errors:
//
// "database index must be 0 or higher" - When the database index is less than 0.
-func (server *EchoVault) SelectDB(database int) error {
+func (server *SugarDB) SelectDB(database int) error {
if database < 0 {
return errors.New("database index must be 0 or higher")
}
diff --git a/echovault/api_connection_test.go b/sugardb/api_connection_test.go
similarity index 92%
rename from echovault/api_connection_test.go
rename to sugardb/api_connection_test.go
index 638e2b1..d3331e6 100644
--- a/echovault/api_connection_test.go
+++ b/sugardb/api_connection_test.go
@@ -12,20 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"bufio"
"bytes"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
- "github.com/echovault/echovault/internal/modules/connection"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/internal/modules/connection"
"github.com/tidwall/resp"
"reflect"
"testing"
)
-func TestEchoVault_Hello(t *testing.T) {
+func TestSugarDB_Hello(t *testing.T) {
t.Parallel()
port, err := internal.GetFreePort()
@@ -38,7 +38,7 @@ func TestEchoVault_Hello(t *testing.T) {
conf.Port = uint16(port)
conf.RequirePass = false
- mockServer := createEchoVaultWithConfig(conf)
+ mockServer := createSugarDBWithConfig(conf)
if err != nil {
t.Error(err)
return
@@ -60,7 +60,7 @@ func TestEchoVault_Hello(t *testing.T) {
command: []resp.Value{resp.StringValue("HELLO")},
wantRes: connection.BuildHelloResponse(
internal.ServerInfo{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: "",
Mode: "standalone",
@@ -80,7 +80,7 @@ func TestEchoVault_Hello(t *testing.T) {
command: []resp.Value{resp.StringValue("HELLO"), resp.StringValue("2")},
wantRes: connection.BuildHelloResponse(
internal.ServerInfo{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: "",
Mode: "standalone",
@@ -100,7 +100,7 @@ func TestEchoVault_Hello(t *testing.T) {
command: []resp.Value{resp.StringValue("HELLO"), resp.StringValue("3")},
wantRes: connection.BuildHelloResponse(
internal.ServerInfo{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: "",
Mode: "standalone",
@@ -147,7 +147,7 @@ func TestEchoVault_Hello(t *testing.T) {
}
}
-func TestEchoVault_SelectDB(t *testing.T) {
+func TestSugarDB_SelectDB(t *testing.T) {
t.Parallel()
tests := []struct {
name string
@@ -184,7 +184,7 @@ func TestEchoVault_SelectDB(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
- server := createEchoVault()
+ server := createSugarDB()
if tt.presetValues != nil {
for db, data := range tt.presetValues {
@@ -237,9 +237,9 @@ func TestEchoVault_SelectDB(t *testing.T) {
}
}
-func TestEchoVault_SetProtocol(t *testing.T) {
+func TestSugarDB_SetProtocol(t *testing.T) {
t.Parallel()
- server := createEchoVault()
+ server := createSugarDB()
tests := []struct {
name string
protocol int
diff --git a/echovault/api_generic.go b/sugardb/api_generic.go
similarity index 90%
rename from echovault/api_generic.go
rename to sugardb/api_generic.go
index de1a9fc..354e7f5 100644
--- a/echovault/api_generic.go
+++ b/sugardb/api_generic.go
@@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"fmt"
"strconv"
"strings"
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
)
// SetWriteOption constants
@@ -74,7 +74,7 @@ func (x SetExOpt) IsSetExOpt() SetExOpt { return x }
//
// `ExpireTime` - int - Time in seconds or milliseconds depending on what ExpireOpt was provided.
//
-// `GET` - bool - Whether or not to return previous value if there was one.
+// `GET` - bool - Whether to return previous value if there was one.
type SETOptions struct {
WriteOpt SetWriteOption
ExpireOpt SetExOption
@@ -152,7 +152,7 @@ func (x GetExOpt) isGetExOpt() GetExOpt { return x }
// "key does not exist"" - when the XX flag is set to true and the key does not exist.
//
// "key does already exists" - when the NX flag is set to true and the key already exists.
-func (server *EchoVault) Set(key, value string, options SETOptions) (string, bool, error) {
+func (server *SugarDB) Set(key, value string, options SETOptions) (string, bool, error) {
cmd := []string{"SET", key, value}
if options.WriteOpt != nil {
@@ -195,7 +195,7 @@ func (server *EchoVault) Set(key, value string, options SETOptions) (string, boo
// Errors:
//
// "key already exists" - when the NX flag is set to true and the key already exists.
-func (server *EchoVault) MSet(kvPairs map[string]string) (bool, error) {
+func (server *SugarDB) MSet(kvPairs map[string]string) (bool, error) {
cmd := []string{"MSET"}
for k, v := range kvPairs {
@@ -223,7 +223,7 @@ func (server *EchoVault) MSet(kvPairs map[string]string) (bool, error) {
//
// Returns: A string representing the value at the specified key. If the value does not exist, an empty
// string is returned.
-func (server *EchoVault) Get(key string) (string, error) {
+func (server *SugarDB) Get(key string) (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"GET", key}), nil, false, true)
if err != nil {
return "", err
@@ -239,7 +239,7 @@ func (server *EchoVault) Get(key string) (string, error) {
// `keys` - []string - a string slice of all the keys.
//
// Returns: a string slice of all the values.
-func (server *EchoVault) MGet(keys ...string) ([]string, error) {
+func (server *SugarDB) MGet(keys ...string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand(append([]string{"MGET"}, keys...)), nil, false, true)
if err != nil {
return []string{}, err
@@ -254,7 +254,7 @@ func (server *EchoVault) MGet(keys ...string) ([]string, error) {
// `keys` - []string - the keys to delete from the store.
//
// Returns: The number of keys that were successfully deleted.
-func (server *EchoVault) Del(keys ...string) (int, error) {
+func (server *SugarDB) Del(keys ...string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand(append([]string{"DEL"}, keys...)), nil, false, true)
if err != nil {
return 0, err
@@ -270,7 +270,7 @@ func (server *EchoVault) Del(keys ...string) (int, error) {
// `key` - string - the key to persist.
//
// Returns: true if the keys is successfully persisted.
-func (server *EchoVault) Persist(key string) (bool, error) {
+func (server *SugarDB) Persist(key string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PERSIST", key}), nil, false, true)
if err != nil {
return false, err
@@ -285,7 +285,7 @@ func (server *EchoVault) Persist(key string) (bool, error) {
// `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 (server *EchoVault) ExpireTime(key string) (int, error) {
+func (server *SugarDB) ExpireTime(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"EXPIRETIME", key}), nil, false, true)
if err != nil {
return 0, err
@@ -300,7 +300,7 @@ func (server *EchoVault) ExpireTime(key string) (int, error) {
// `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 (server *EchoVault) PExpireTime(key string) (int, error) {
+func (server *SugarDB) PExpireTime(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PEXPIRETIME", key}), nil, false, true)
if err != nil {
return 0, err
@@ -315,7 +315,7 @@ func (server *EchoVault) PExpireTime(key string) (int, error) {
// `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 (server *EchoVault) TTL(key string) (int, error) {
+func (server *SugarDB) TTL(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"TTL", key}), nil, false, true)
if err != nil {
return 0, err
@@ -330,7 +330,7 @@ func (server *EchoVault) TTL(key string) (int, error) {
// `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 (server *EchoVault) PTTL(key string) (int, error) {
+func (server *SugarDB) PTTL(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PTTL", key}), nil, false, true)
if err != nil {
return 0, err
@@ -350,7 +350,7 @@ func (server *EchoVault) PTTL(key string) (int, error) {
// `options` - ExpireOptions - One of NX, GT, LT. XX can be passed with GT OR LT optionally.
//
// Returns: true if the key's expiry was successfully updated.
-func (server *EchoVault) Expire(key string, seconds int, options ...ExpireOptions) (bool, error) {
+func (server *SugarDB) Expire(key string, seconds int, options ...ExpireOptions) (bool, error) {
cmd := []string{"EXPIRE", key, strconv.Itoa(seconds)}
for _, opt := range options {
@@ -379,7 +379,7 @@ func (server *EchoVault) Expire(key string, seconds int, options ...ExpireOption
// `options` - PExpireOptions
//
// Returns: true if the key's expiry was successfully updated.
-func (server *EchoVault) PExpire(key string, milliseconds int, options ...ExpireOptions) (bool, error) {
+func (server *SugarDB) PExpire(key string, milliseconds int, options ...ExpireOptions) (bool, error) {
cmd := []string{"PEXPIRE", key, strconv.Itoa(milliseconds)}
for _, opt := range options {
@@ -408,7 +408,7 @@ func (server *EchoVault) PExpire(key string, milliseconds int, options ...Expire
// `options` - ExpireAtOptions
//
// Returns: true if the key's expiry was successfully updated.
-func (server *EchoVault) ExpireAt(key string, unixSeconds int, options ...ExpireOptions) (int, error) {
+func (server *SugarDB) ExpireAt(key string, unixSeconds int, options ...ExpireOptions) (int, error) {
cmd := []string{"EXPIREAT", key, strconv.Itoa(unixSeconds)}
for _, opt := range options {
@@ -437,7 +437,7 @@ func (server *EchoVault) ExpireAt(key string, unixSeconds int, options ...Expire
// `options` - PExpireAtOptions
//
// Returns: true if the key's expiry was successfully updated.
-func (server *EchoVault) PExpireAt(key string, unixMilliseconds int, options ...ExpireOptions) (int, error) {
+func (server *SugarDB) PExpireAt(key string, unixMilliseconds int, options ...ExpireOptions) (int, error) {
cmd := []string{"PEXPIREAT", key, strconv.Itoa(unixMilliseconds)}
for _, opt := range options {
@@ -462,7 +462,7 @@ func (server *EchoVault) PExpireAt(key string, unixMilliseconds int, options ...
// `key` - string
//
// Returns: The new value as an integer.
-func (server *EchoVault) Incr(key string) (int, error) {
+func (server *SugarDB) Incr(key string) (int, error) {
// Construct the command
cmd := []string{"INCR", key}
@@ -484,7 +484,7 @@ func (server *EchoVault) Incr(key string) (int, error) {
// `key` - string
//
// Returns: The new value as an integer.
-func (server *EchoVault) Decr(key string) (int, error) {
+func (server *SugarDB) Decr(key string) (int, error) {
// Construct the command
cmd := []string{"DECR", key}
@@ -509,7 +509,7 @@ func (server *EchoVault) Decr(key string) (int, error) {
// `increment` - int - The amount by which to increment the key's value. This can be a positive or negative integer.
//
// Returns: The new value of the key after the increment operation as an integer.
-func (server *EchoVault) IncrBy(key string, value string) (int, error) {
+func (server *SugarDB) IncrBy(key string, value string) (int, error) {
// Construct the command
cmd := []string{"INCRBY", key, value}
// Execute the command
@@ -532,7 +532,7 @@ func (server *EchoVault) IncrBy(key string, value string) (int, error) {
// `increment` - float64 - The amount by which to increment the key's value. This can be a positive or negative float.
//
// Returns: The new value of the key after the increment operation as a float64.
-func (server *EchoVault) IncrByFloat(key string, value string) (float64, error) {
+func (server *SugarDB) IncrByFloat(key string, value string) (float64, error) {
// Construct the command
cmd := []string{"INCRBYFLOAT", key, value}
// Execute the command
@@ -555,7 +555,7 @@ func (server *EchoVault) IncrByFloat(key string, value string) (float64, error)
// `increment` - int - The amount by which to decrement the key's value. This can be a positive or negative integer.
//
// Returns: The new value of the key after the decrement operation as an integer.
-func (server *EchoVault) DecrBy(key string, value string) (int, error) {
+func (server *SugarDB) DecrBy(key string, value string) (int, error) {
// Construct the command
cmd := []string{"DECRBY", key, value}
// Execute the command
@@ -577,7 +577,7 @@ func (server *EchoVault) DecrBy(key string, value string) (int, error) {
// `newKey` - string - The new name for the key.
//
// Returns: A string indicating the success of the operation.
-func (server *EchoVault) Rename(oldKey string, newKey string) (string, error) {
+func (server *SugarDB) Rename(oldKey string, newKey string) (string, error) {
// Construct the command
cmd := []string{"RENAME", oldKey, newKey}
// Execute the command
@@ -591,7 +591,7 @@ func (server *EchoVault) Rename(oldKey string, newKey string) (string, error) {
// RandomKey returns a random key from the current active database.
// If no keys present in db returns an empty string.
-func (server *EchoVault) RandomKey() (string, error) {
+func (server *SugarDB) RandomKey() (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"RANDOMKEY"}), nil, false, true)
if err != nil {
return "", err
@@ -607,7 +607,7 @@ func (server *EchoVault) RandomKey() (string, error) {
//
// Returns: A string representing the value at the specified key. If the value does not exist, an empty
// string is returned.
-func (server *EchoVault) GetDel(key string) (string, error) {
+func (server *SugarDB) GetDel(key string) (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"GETDEL", key}), nil, false, true)
if err != nil {
return "", err
@@ -626,7 +626,7 @@ func (server *EchoVault) GetDel(key string) (string, error) {
// `unixtime` - Number of seconds or miliseconds from now.
//
// Returns: A string representing the value at the specified key. If the value does not exist, an empty string is returned.
-func (server *EchoVault) GetEx(key string, option GetExOption, unixtime int) (string, error) {
+func (server *SugarDB) GetEx(key string, option GetExOption, unixtime int) (string, error) {
cmd := make([]string, 2)
@@ -657,7 +657,7 @@ func (server *EchoVault) GetEx(key string, option GetExOption, unixtime int) (st
// `keys` - ...string - the keys whose access time or access count should be incremented based on eviction policy.
//
// Returns: An integer representing the number of keys successfully touched. If a key doesn't exist it is simply ignored.
-func (server *EchoVault) Touch(keys ...string) (int, error) {
+func (server *SugarDB) Touch(keys ...string) (int, error) {
cmd := make([]string, len(keys)+1)
cmd[0] = "TOUCH"
for i, k := range keys {
@@ -679,7 +679,7 @@ func (server *EchoVault) Touch(keys ...string) (int, error) {
// `key` - string - the key whose access frequency should be retrieved.
//
// Returns: An integer representing the access frequency. If the key doesn't exist -1 and an error is returned.
-func (server *EchoVault) ObjectFreq(key string) (int, error) {
+func (server *SugarDB) ObjectFreq(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"OBJECTFREQ", key}), nil, false, true)
if err != nil {
return -1, err
@@ -695,7 +695,7 @@ func (server *EchoVault) ObjectFreq(key string) (int, error) {
// `key` - string - the key whose last access time should be retrieved.
//
// Returns: A float64 representing the seconds since the key was last accessed. If the key doesn't exist -1 and an error is returned.
-func (server *EchoVault) ObjectIdleTime(key string) (float64, error) {
+func (server *SugarDB) ObjectIdleTime(key string) (float64, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"OBJECTIDLETIME", key}), nil, false, true)
if err != nil {
return -1, err
diff --git a/echovault/api_generic_test.go b/sugardb/api_generic_test.go
similarity index 96%
rename from echovault/api_generic_test.go
rename to sugardb/api_generic_test.go
index e1f779c..1d20a1b 100644
--- a/echovault/api_generic_test.go
+++ b/sugardb/api_generic_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"context"
@@ -22,14 +22,14 @@ import (
"testing"
"time"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/clock"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/clock"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
)
-func TestEchoVault_DEL(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_DEL(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -70,10 +70,10 @@ func TestEchoVault_DEL(t *testing.T) {
}
}
-func TestEchoVault_EXPIRE(t *testing.T) {
+func TestSugarDB_EXPIRE(t *testing.T) {
mockClock := clock.NewClock()
- server := createEchoVault()
+ server := createSugarDB()
tests := []struct {
name string
@@ -243,10 +243,10 @@ func TestEchoVault_EXPIRE(t *testing.T) {
}
}
-func TestEchoVault_EXPIREAT(t *testing.T) {
+func TestSugarDB_EXPIREAT(t *testing.T) {
mockClock := clock.NewClock()
- server := createEchoVault()
+ server := createSugarDB()
tests := []struct {
name string
@@ -427,10 +427,10 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
}
}
-func TestEchoVault_EXPIRETIME(t *testing.T) {
+func TestSugarDB_EXPIRETIME(t *testing.T) {
mockClock := clock.NewClock()
- server := createEchoVault()
+ server := createSugarDB()
tests := []struct {
name string
@@ -497,8 +497,8 @@ func TestEchoVault_EXPIRETIME(t *testing.T) {
}
}
-func TestEchoVault_GET(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_GET(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -543,8 +543,8 @@ func TestEchoVault_GET(t *testing.T) {
}
}
-func TestEchoVault_MGET(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_MGET(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -599,10 +599,10 @@ func TestEchoVault_MGET(t *testing.T) {
}
}
-func TestEchoVault_SET(t *testing.T) {
+func TestSugarDB_SET(t *testing.T) {
mockClock := clock.NewClock()
- server := createEchoVault()
+ server := createSugarDB()
SetOptions := func(W SetWriteOption, EX SetExOption, EXTIME int, GET bool) SETOptions {
return SETOptions{
@@ -775,8 +775,8 @@ func TestEchoVault_SET(t *testing.T) {
}
}
-func TestEchoVault_MSET(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_MSET(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -805,10 +805,10 @@ func TestEchoVault_MSET(t *testing.T) {
}
}
-func TestEchoVault_PERSIST(t *testing.T) {
+func TestSugarDB_PERSIST(t *testing.T) {
mockClock := clock.NewClock()
- server := createEchoVault()
+ server := createSugarDB()
tests := []struct {
name string
@@ -862,10 +862,10 @@ func TestEchoVault_PERSIST(t *testing.T) {
}
}
-func TestEchoVault_TTL(t *testing.T) {
+func TestSugarDB_TTL(t *testing.T) {
mockClock := clock.NewClock()
- server := createEchoVault()
+ server := createSugarDB()
tests := []struct {
name string
@@ -933,8 +933,8 @@ func TestEchoVault_TTL(t *testing.T) {
}
}
-func TestEchoVault_INCR(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_INCR(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -997,8 +997,8 @@ func TestEchoVault_INCR(t *testing.T) {
}
}
-func TestEchoVault_DECR(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_DECR(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1061,8 +1061,8 @@ func TestEchoVault_DECR(t *testing.T) {
}
}
-func TestEchoVault_INCRBY(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_INCRBY(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1130,8 +1130,8 @@ func TestEchoVault_INCRBY(t *testing.T) {
}
}
-func TestEchoVault_INCRBYFLOAT(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_INCRBYFLOAT(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1199,8 +1199,8 @@ func TestEchoVault_INCRBYFLOAT(t *testing.T) {
}
}
-func TestEchoVault_DECRBY(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_DECRBY(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1267,8 +1267,8 @@ func TestEchoVault_DECRBY(t *testing.T) {
}
}
-func TestEchoVault_Rename(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_Rename(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1322,8 +1322,8 @@ func TestEchoVault_Rename(t *testing.T) {
}
}
-func TestEchoVault_RANDOMKEY(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_RANDOMKEY(t *testing.T) {
+ server := createSugarDB()
// test without keys
got, err := server.RandomKey()
@@ -1356,8 +1356,8 @@ func TestEchoVault_RANDOMKEY(t *testing.T) {
}
-func TestEchoVault_GETDEL(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_GETDEL(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1414,9 +1414,9 @@ func TestEchoVault_GETDEL(t *testing.T) {
}
}
-func TestEchoVault_GETEX(t *testing.T) {
+func TestSugarDB_GETEX(t *testing.T) {
mockClock := clock.NewClock()
- server := createEchoVault()
+ server := createSugarDB()
tests := []struct {
name string
@@ -1534,7 +1534,7 @@ func TestEchoVault_GETEX(t *testing.T) {
return
}
}
- //Check value received
+ // Check value received
got, err := server.GetEx(tt.key, tt.getExOpt, tt.getExOptTime)
if (err != nil) != tt.wantErr {
t.Errorf("GETEX() GET error = %v, wantErr %v", err, tt.wantErr)
@@ -1559,11 +1559,11 @@ func TestEchoVault_GETEX(t *testing.T) {
}
// Tests Touch and OBJECTFREQ commands
-func TestEchoVault_LFU_TOUCH(t *testing.T) {
+func TestSugarDB_LFU_TOUCH(t *testing.T) {
duration := time.Duration(30) * time.Second
- server := createEchoVaultWithConfig(config.Config{
+ server := createSugarDBWithConfig(config.Config{
DataDir: "",
EvictionPolicy: constants.AllKeysLFU,
EvictionInterval: duration,
@@ -1668,11 +1668,11 @@ func TestEchoVault_LFU_TOUCH(t *testing.T) {
}
// Tests Touch and OBJECTIDLETIME commands
-func TestEchoVault_LRU_TOUCH(t *testing.T) {
+func TestSugarDB_LRU_TOUCH(t *testing.T) {
duration := time.Duration(30) * time.Second
- server := createEchoVaultWithConfig(config.Config{
+ server := createSugarDBWithConfig(config.Config{
DataDir: "",
EvictionPolicy: constants.AllKeysLRU,
EvictionInterval: duration,
diff --git a/echovault/api_hash.go b/sugardb/api_hash.go
similarity index 89%
rename from echovault/api_hash.go
rename to sugardb/api_hash.go
index aec63fe..611bc76 100644
--- a/echovault/api_hash.go
+++ b/sugardb/api_hash.go
@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
"strconv"
)
@@ -43,7 +43,7 @@ type HRandFieldOptions struct {
// Errors:
//
// "value at is not a hash" - when the provided key exists but is not a hash.
-func (server *EchoVault) HSet(key string, fieldValuePairs map[string]string) (int, error) {
+func (server *SugarDB) HSet(key string, fieldValuePairs map[string]string) (int, error) {
cmd := []string{"HSET", key}
for k, v := range fieldValuePairs {
@@ -73,7 +73,7 @@ func (server *EchoVault) HSet(key string, fieldValuePairs map[string]string) (in
// Errors:
//
// "value at is not a hash" - when the provided key does not exist or is not a hash.
-func (server *EchoVault) HSetNX(key string, fieldValuePairs map[string]string) (int, error) {
+func (server *SugarDB) HSetNX(key string, fieldValuePairs map[string]string) (int, error) {
cmd := []string{"HSETNX", key}
for k, v := range fieldValuePairs {
@@ -101,7 +101,7 @@ func (server *EchoVault) HSetNX(key string, fieldValuePairs map[string]string) (
// Errors:
//
// "value at is not a hash" - when the provided key does not exist or is not a hash.
-func (server *EchoVault) HGet(key string, fields ...string) ([]string, error) {
+func (server *SugarDB) HGet(key string, fields ...string) ([]string, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand(append([]string{"HGET", key}, fields...)),
@@ -128,7 +128,7 @@ func (server *EchoVault) HGet(key string, fields ...string) ([]string, error) {
// Errors:
//
// "value at is not a hash" - when the provided key does not exist or is not a hash.
-func (server *EchoVault) HMGet(key string, fields ...string) ([]string, error) {
+func (server *SugarDB) HMGet(key string, fields ...string) ([]string, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand(append([]string{"HMGET", key}, fields...)),
@@ -157,7 +157,7 @@ func (server *EchoVault) HMGet(key string, fields ...string) ([]string, error) {
// Errors:
//
// "value at is not a hash" - when the provided key does not exist or is not a hash.
-func (server *EchoVault) HStrLen(key string, fields ...string) ([]int, error) {
+func (server *SugarDB) HStrLen(key string, fields ...string) ([]int, error) {
cmd := append([]string{"HSTRLEN", key}, fields...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
@@ -179,7 +179,7 @@ func (server *EchoVault) HStrLen(key string, fields ...string) ([]int, error) {
// Errors:
//
// "value at is not a hash" - when the provided key does not exist or is not a hash.
-func (server *EchoVault) HVals(key string) ([]string, error) {
+func (server *SugarDB) HVals(key string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HVALS", key}), nil, false, true)
if err != nil {
return nil, err
@@ -200,7 +200,7 @@ func (server *EchoVault) HVals(key string) ([]string, error) {
// Errors:
//
// "value at is not a hash" - when the provided key does not exist or is not a hash.
-func (server *EchoVault) HRandField(key string, options HRandFieldOptions) ([]string, error) {
+func (server *SugarDB) HRandField(key string, options HRandFieldOptions) ([]string, error) {
cmd := []string{"HRANDFIELD", key}
if options.Count == 0 {
@@ -232,7 +232,7 @@ func (server *EchoVault) HRandField(key string, options HRandFieldOptions) ([]st
// Errors:
//
// "value at is not a hash" - when the provided key does not exist or is not a hash.
-func (server *EchoVault) HLen(key string) (int, error) {
+func (server *SugarDB) HLen(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HLEN", key}), nil, false, true)
if err != nil {
return 0, err
@@ -251,7 +251,7 @@ func (server *EchoVault) HLen(key string) (int, error) {
// Errors:
//
// "value at is not a hash" - when the provided key does not exist or is not a hash.
-func (server *EchoVault) HKeys(key string) ([]string, error) {
+func (server *SugarDB) HKeys(key string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HKEYS", key}), nil, false, true)
if err != nil {
return nil, err
@@ -275,7 +275,7 @@ func (server *EchoVault) HKeys(key string) ([]string, error) {
// "value at is not a hash" - when the provided key does not exist or is not a hash.
//
// "value at field is not a number" - when the field holds a value that is not a number.
-func (server *EchoVault) HIncrBy(key, field string, increment int) (float64, error) {
+func (server *SugarDB) HIncrBy(key, field string, increment int) (float64, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HINCRBY", key, field, strconv.Itoa(increment)}), nil, false, true)
if err != nil {
return 0, err
@@ -284,7 +284,7 @@ func (server *EchoVault) HIncrBy(key, field string, increment int) (float64, err
}
// HIncrByFloat behaves like HIncrBy but with a float increment instead of an integer increment.
-func (server *EchoVault) HIncrByFloat(key, field string, increment float64) (float64, error) {
+func (server *SugarDB) HIncrByFloat(key, field string, increment float64) (float64, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HINCRBYFLOAT", key, field, strconv.FormatFloat(increment, 'f', -1, 64)}), nil, false, true)
if err != nil {
return 0, err
@@ -304,7 +304,7 @@ func (server *EchoVault) HIncrByFloat(key, field string, increment float64) (flo
// Errors:
//
// "value at is not a hash" - when the provided key does not exist or is not a hash.
-func (server *EchoVault) HGetAll(key string) ([]string, error) {
+func (server *SugarDB) HGetAll(key string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HGETALL", key}), nil, false, true)
if err != nil {
return nil, err
@@ -325,7 +325,7 @@ func (server *EchoVault) HGetAll(key string) ([]string, error) {
// Errors:
//
// "value at is not a hash" - when the provided key does not exist or is not a hash.
-func (server *EchoVault) HExists(key, field string) (bool, error) {
+func (server *SugarDB) HExists(key, field string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HEXISTS", key, field}), nil, false, true)
if err != nil {
return false, err
@@ -346,7 +346,7 @@ func (server *EchoVault) HExists(key, field string) (bool, error) {
// Errors:
//
// "value at is not a hash" - when the provided key does not exist or is not a hash.
-func (server *EchoVault) HDel(key string, fields ...string) (int, error) {
+func (server *SugarDB) HDel(key string, fields ...string) (int, error) {
cmd := append([]string{"HDEL", key}, fields...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
diff --git a/echovault/api_hash_test.go b/sugardb/api_hash_test.go
similarity index 96%
rename from echovault/api_hash_test.go
rename to sugardb/api_hash_test.go
index f23d0f3..3295bf6 100644
--- a/echovault/api_hash_test.go
+++ b/sugardb/api_hash_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"context"
@@ -21,8 +21,8 @@ import (
"testing"
)
-func TestEchoVault_HDEL(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HDEL(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -86,8 +86,8 @@ func TestEchoVault_HDEL(t *testing.T) {
}
}
-func TestEchoVault_HEXISTS(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HEXISTS(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -143,8 +143,8 @@ func TestEchoVault_HEXISTS(t *testing.T) {
}
}
-func TestEchoVault_HGETALL(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HGETALL(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -203,8 +203,8 @@ func TestEchoVault_HGETALL(t *testing.T) {
}
}
-func TestEchoVault_HINCRBY(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HINCRBY(t *testing.T) {
+ server := createSugarDB()
const (
HINCRBY = "HINCRBY"
@@ -315,8 +315,8 @@ func TestEchoVault_HINCRBY(t *testing.T) {
}
}
-func TestEchoVault_HKEYS(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HKEYS(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -373,8 +373,8 @@ func TestEchoVault_HKEYS(t *testing.T) {
}
}
-func TestEchoVault_HLEN(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HLEN(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -426,8 +426,8 @@ func TestEchoVault_HLEN(t *testing.T) {
}
}
-func TestEchoVault_HRANDFIELD(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HRANDFIELD(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -558,8 +558,8 @@ func TestEchoVault_HRANDFIELD(t *testing.T) {
}
}
-func TestEchoVault_HSET(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HSET(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -646,8 +646,8 @@ func TestEchoVault_HSET(t *testing.T) {
}
}
-func TestEchoVault_HSTRLEN(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HSTRLEN(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -713,8 +713,8 @@ func TestEchoVault_HSTRLEN(t *testing.T) {
}
}
-func TestEchoVault_HVALS(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HVALS(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -771,8 +771,8 @@ func TestEchoVault_HVALS(t *testing.T) {
}
}
-func TestEchoVault_HGet(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HGet(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
presetValue interface{}
@@ -827,8 +827,8 @@ func TestEchoVault_HGet(t *testing.T) {
}
}
-func TestEchoVault_HMGet(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_HMGet(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
presetValue interface{}
diff --git a/echovault/api_list.go b/sugardb/api_list.go
similarity index 89%
rename from echovault/api_list.go
rename to sugardb/api_list.go
index 4472293..756fa19 100644
--- a/echovault/api_list.go
+++ b/sugardb/api_list.go
@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
"strconv"
"strings"
)
@@ -31,7 +31,7 @@ import (
// Errors:
//
// "LLen command on non-list item" - when the provided key exists but is not a list.
-func (server *EchoVault) LLen(key string) (int, error) {
+func (server *SugarDB) LLen(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LLEN", key}), nil, false, true)
if err != nil {
return 0, err
@@ -55,7 +55,7 @@ func (server *EchoVault) LLen(key string) (int, error) {
// Errors:
//
// "LRange command on non-list item" - when the provided key exists but is not a list.
-func (server *EchoVault) LRange(key string, start, end int) ([]string, error) {
+func (server *SugarDB) LRange(key string, start, end int) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LRANGE", key, strconv.Itoa(start), strconv.Itoa(end)}), nil, false, true)
if err != nil {
return nil, err
@@ -76,7 +76,7 @@ func (server *EchoVault) LRange(key string, start, end int) ([]string, error) {
// Errors:
//
// "LIndex command on non-list item" - when the provided key exists but is not a list.
-func (server *EchoVault) LIndex(key string, index uint) (string, error) {
+func (server *SugarDB) LIndex(key string, index uint) (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LINDEX", key, strconv.Itoa(int(index))}), nil, false, true)
if err != nil {
return "", err
@@ -101,7 +101,7 @@ func (server *EchoVault) LIndex(key string, index uint) (string, error) {
// "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 (server *EchoVault) LSet(key string, index int, value string) (bool, error) {
+func (server *SugarDB) LSet(key string, index int, value string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LSET", key, strconv.Itoa(index), value}), nil, false, true)
if err != nil {
return false, err
@@ -114,7 +114,7 @@ func (server *EchoVault) LSet(key string, index int, value string) (bool, error)
// trimmed list.
//
// Returns: true if the trim is successful.
-func (server *EchoVault) LTrim(key string, start int, end int) (bool, error) {
+func (server *SugarDB) LTrim(key string, start int, end int) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LTRIM", key, strconv.Itoa(start), strconv.Itoa(end)}), nil, false, true)
if err != nil {
return false, err
@@ -138,7 +138,7 @@ func (server *EchoVault) LTrim(key string, start int, end int) (bool, error) {
// Errors:
//
// "LRem command on non-list item" - when the provided key exists but is not a list.
-func (server *EchoVault) LRem(key string, count int, value string) (int, error) {
+func (server *SugarDB) LRem(key string, count int, value string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{
"LREM", key, strconv.Itoa(count), value}),
nil,
@@ -172,7 +172,7 @@ func (server *EchoVault) LRem(key string, count int, value string) (int, error)
// "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 (server *EchoVault) LMove(source, destination, whereFrom, whereTo string) (bool, error) {
+func (server *SugarDB) LMove(source, destination, whereFrom, whereTo string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LMOVE", source, destination, whereFrom, whereTo}), nil, false, true)
if err != nil {
return false, err
@@ -192,7 +192,7 @@ func (server *EchoVault) LMove(source, destination, whereFrom, whereTo string) (
// Errors:
//
// "LPOP command on non-list item" - when the provided key is not a list.
-func (server *EchoVault) LPop(key string, count uint) ([]string, error) {
+func (server *SugarDB) LPop(key string, count uint) ([]string, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"LPOP", key, strconv.Itoa(int(count))}),
@@ -217,7 +217,7 @@ func (server *EchoVault) LPop(key string, count uint) ([]string, error) {
// Errors:
//
// "RPOP command on non-list item" - when the provided key is not a list.
-func (server *EchoVault) RPop(key string, count uint) ([]string, error) {
+func (server *SugarDB) RPop(key string, count uint) ([]string, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"RPOP", key, strconv.Itoa(int(count))}),
@@ -245,7 +245,7 @@ func (server *EchoVault) RPop(key string, count uint) ([]string, error) {
// Errors:
//
// "LPush command on non-list item" - when the provided key is not a list.
-func (server *EchoVault) LPush(key string, values ...string) (int, error) {
+func (server *SugarDB) LPush(key string, values ...string) (int, error) {
cmd := append([]string{"LPUSH", key}, values...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -267,7 +267,7 @@ func (server *EchoVault) LPush(key string, values ...string) (int, error) {
// Errors:
//
// "LPushX command on non-list item" - when the provided key is not a list or doesn't exist.
-func (server *EchoVault) LPushX(key string, values ...string) (int, error) {
+func (server *SugarDB) LPushX(key string, values ...string) (int, error) {
cmd := append([]string{"LPUSHX", key}, values...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -290,7 +290,7 @@ func (server *EchoVault) LPushX(key string, values ...string) (int, error) {
// Errors:
//
// "RPush command on non-list item" - when the provided key is not a list.
-func (server *EchoVault) RPush(key string, values ...string) (int, error) {
+func (server *SugarDB) RPush(key string, values ...string) (int, error) {
cmd := append([]string{"RPUSH", key}, values...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -312,7 +312,7 @@ func (server *EchoVault) RPush(key string, values ...string) (int, error) {
// Errors:
//
// "RPushX command on non-list item" - when the provided key is not a list or doesn't exist.
-func (server *EchoVault) RPushX(key string, values ...string) (int, error) {
+func (server *SugarDB) RPushX(key string, values ...string) (int, error) {
cmd := append([]string{"RPUSHX", key}, values...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
diff --git a/echovault/api_list_test.go b/sugardb/api_list_test.go
similarity index 97%
rename from echovault/api_list_test.go
rename to sugardb/api_list_test.go
index 7eb9cc8..d75d5ee 100644
--- a/echovault/api_list_test.go
+++ b/sugardb/api_list_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"context"
@@ -20,8 +20,8 @@ import (
"testing"
)
-func TestEchoVault_LLEN(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_LLEN(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
preset bool
@@ -77,8 +77,8 @@ func TestEchoVault_LLEN(t *testing.T) {
}
}
-func TestEchoVault_LINDEX(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_LINDEX(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
preset bool
@@ -165,8 +165,8 @@ func TestEchoVault_LINDEX(t *testing.T) {
}
}
-func TestEchoVault_LMOVE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_LMOVE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -335,8 +335,8 @@ func TestEchoVault_LMOVE(t *testing.T) {
}
}
-func TestEchoVault_POP(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_POP(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -410,8 +410,8 @@ func TestEchoVault_POP(t *testing.T) {
}
}
-func TestEchoVault_LPUSH(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_LPUSH(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -485,8 +485,8 @@ func TestEchoVault_LPUSH(t *testing.T) {
}
}
-func TestEchoVault_RPUSH(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_RPUSH(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -540,8 +540,8 @@ func TestEchoVault_RPUSH(t *testing.T) {
}
}
-func TestEchoVault_LRANGE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_LRANGE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -659,8 +659,8 @@ func TestEchoVault_LRANGE(t *testing.T) {
}
}
-func TestEchoVault_LREM(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_LREM(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -724,8 +724,8 @@ func TestEchoVault_LREM(t *testing.T) {
}
}
-func TestEchoVault_LSET(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_LSET(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -829,8 +829,8 @@ func TestEchoVault_LSET(t *testing.T) {
}
}
-func TestEchoVault_LTRIM(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_LTRIM(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
diff --git a/echovault/api_pubsub.go b/sugardb/api_pubsub.go
similarity index 91%
rename from echovault/api_pubsub.go
rename to sugardb/api_pubsub.go
index d8000db..5c0d452 100644
--- a/echovault/api_pubsub.go
+++ b/sugardb/api_pubsub.go
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"bytes"
"errors"
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
"github.com/tidwall/resp"
"net"
"strings"
@@ -75,7 +75,7 @@ func establishConnections(tag string) (*net.Conn, *net.Conn, error) {
//
// Returns: ReadPubSubMessage function which reads the next message sent to the subscription instance.
// This function is blocking.
-func (server *EchoVault) Subscribe(tag string, channels ...string) (ReadPubSubMessage, error) {
+func (server *SugarDB) Subscribe(tag string, channels ...string) (ReadPubSubMessage, error) {
readConn, writeConn, err := establishConnections(tag)
if err != nil {
return func() []string {
@@ -109,7 +109,7 @@ func (server *EchoVault) Subscribe(tag string, channels ...string) (ReadPubSubMe
// `tag` - string - The tag used to identify this subscription instance.
//
// `channels` - ...string - The list of channels to unsubscribe from.
-func (server *EchoVault) Unsubscribe(tag string, channels ...string) {
+func (server *SugarDB) Unsubscribe(tag string, channels ...string) {
c, ok := connections.Load(tag)
if !ok {
return
@@ -128,7 +128,7 @@ func (server *EchoVault) Unsubscribe(tag string, channels ...string) {
//
// Returns: ReadPubSubMessage function which reads the next message sent to the subscription instance.
// This function is blocking.
-func (server *EchoVault) PSubscribe(tag string, patterns ...string) (ReadPubSubMessage, error) {
+func (server *SugarDB) PSubscribe(tag string, patterns ...string) (ReadPubSubMessage, error) {
readConn, writeConn, err := establishConnections(tag)
if err != nil {
return func() []string {
@@ -162,7 +162,7 @@ func (server *EchoVault) PSubscribe(tag string, patterns ...string) (ReadPubSubM
// `tag` - string - The tag used to identify this subscription instance.
//
// `patterns` - ...string - The list of glob patterns to unsubscribe from.
-func (server *EchoVault) PUnsubscribe(tag string, patterns ...string) {
+func (server *SugarDB) PUnsubscribe(tag string, patterns ...string) {
c, ok := connections.Load(tag)
if !ok {
return
@@ -181,7 +181,7 @@ func (server *EchoVault) PUnsubscribe(tag string, patterns ...string) {
//
// 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 (server *EchoVault) Publish(channel, message string) (bool, error) {
+func (server *SugarDB) Publish(channel, message string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PUBLISH", channel, message}), nil, false, true)
if err != nil {
return false, err
@@ -197,7 +197,7 @@ func (server *EchoVault) Publish(channel, message string) (bool, error) {
// `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 (server *EchoVault) PubSubChannels(pattern string) ([]string, error) {
+func (server *SugarDB) PubSubChannels(pattern string) ([]string, error) {
cmd := []string{"PUBSUB", "CHANNELS"}
if pattern != "" {
cmd = append(cmd, pattern)
@@ -212,7 +212,7 @@ func (server *EchoVault) PubSubChannels(pattern string) ([]string, 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 (server *EchoVault) PubSubNumPat() (int, error) {
+func (server *SugarDB) PubSubNumPat() (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PUBSUB", "NUMPAT"}), nil, false, true)
if err != nil {
return 0, err
@@ -227,7 +227,7 @@ func (server *EchoVault) PubSubNumPat() (int, error) {
// `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 (server *EchoVault) PubSubNumSub(channels ...string) (map[string]int, error) {
+func (server *SugarDB) PubSubNumSub(channels ...string) (map[string]int, error) {
cmd := append([]string{"PUBSUB", "NUMSUB"}, channels...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
diff --git a/echovault/api_pubsub_test.go b/sugardb/api_pubsub_test.go
similarity index 95%
rename from echovault/api_pubsub_test.go
rename to sugardb/api_pubsub_test.go
index 355f245..10abf67 100644
--- a/echovault/api_pubsub_test.go
+++ b/sugardb/api_pubsub_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"fmt"
@@ -22,7 +22,7 @@ import (
)
func Test_Subscribe(t *testing.T) {
- server := createEchoVault()
+ server := createSugarDB()
// Subscribe to channels.
tag := "tag"
@@ -73,8 +73,8 @@ func Test_Subscribe(t *testing.T) {
server.Unsubscribe(tag, channels...)
}
-func TestEchoVault_PSubscribe(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_PSubscribe(t *testing.T) {
+ server := createSugarDB()
// Subscribe to channels.
tag := "tag"
@@ -126,8 +126,8 @@ func TestEchoVault_PSubscribe(t *testing.T) {
server.PUnsubscribe(tag, patterns...)
}
-func TestEchoVault_PubSubChannels(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_PubSubChannels(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
tag string
@@ -184,8 +184,8 @@ func TestEchoVault_PubSubChannels(t *testing.T) {
}
}
-func TestEchoVault_PubSubNumPat(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_PubSubNumPat(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
tag string
@@ -223,8 +223,8 @@ func TestEchoVault_PubSubNumPat(t *testing.T) {
}
}
-func TestEchoVault_PubSubNumSub(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_PubSubNumSub(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
subscriptions map[string]struct {
diff --git a/echovault/api_set.go b/sugardb/api_set.go
similarity index 89%
rename from echovault/api_set.go
rename to sugardb/api_set.go
index e31e4e6..346f84b 100644
--- a/echovault/api_set.go
+++ b/sugardb/api_set.go
@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
"strconv"
)
@@ -33,7 +33,7 @@ import (
// Errors:
//
// "value at is not a set" - when the provided key exists but is not a set.
-func (server *EchoVault) SAdd(key string, members ...string) (int, error) {
+func (server *SugarDB) SAdd(key string, members ...string) (int, error) {
cmd := append([]string{"SADD", key}, members...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -53,7 +53,7 @@ func (server *EchoVault) SAdd(key string, members ...string) (int, error) {
// Errors:
//
// "value at is not a set" - when the provided key exists but is not a set.
-func (server *EchoVault) SCard(key string) (int, error) {
+func (server *SugarDB) SCard(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SCARD", key}), nil, false, true)
if err != nil {
return 0, err
@@ -75,7 +75,7 @@ func (server *EchoVault) SCard(key string) (int, error) {
// "value at is not a set" - when the provided key exists but is not a set.
//
// "key for base set does not exist" - if the first key is not a set.
-func (server *EchoVault) SDiff(keys ...string) ([]string, error) {
+func (server *SugarDB) SDiff(keys ...string) ([]string, error) {
cmd := append([]string{"SDIFF"}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -88,7 +88,7 @@ func (server *EchoVault) SDiff(keys ...string) ([]string, error) {
// at the 'destination' key.
//
// Returns: an integer representing the cardinality of the new set.
-func (server *EchoVault) SDiffStore(destination string, keys ...string) (int, error) {
+func (server *SugarDB) SDiffStore(destination string, keys ...string) (int, error) {
cmd := append([]string{"SDIFFSTORE", destination}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -111,7 +111,7 @@ func (server *EchoVault) SDiffStore(destination string, keys ...string) (int, er
// "value at 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 (server *EchoVault) SInter(keys ...string) ([]string, error) {
+func (server *SugarDB) SInter(keys ...string) ([]string, error) {
cmd := append([]string{"SINTER"}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -135,7 +135,7 @@ func (server *EchoVault) SInter(keys ...string) ([]string, error) {
// "value at 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 (server *EchoVault) SInterCard(keys []string, limit uint) (int, error) {
+func (server *SugarDB) SInterCard(keys []string, limit uint) (int, error) {
cmd := append([]string{"SINTERCARD"}, keys...)
if limit > 0 {
cmd = append(cmd, []string{"LIMIT", strconv.Itoa(int(limit))}...)
@@ -149,7 +149,7 @@ func (server *EchoVault) SInterCard(keys []string, limit uint) (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 (server *EchoVault) SInterStore(destination string, keys ...string) (int, error) {
+func (server *SugarDB) SInterStore(destination string, keys ...string) (int, error) {
cmd := append([]string{"SINTERSTORE", destination}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -171,7 +171,7 @@ func (server *EchoVault) SInterStore(destination string, keys ...string) (int, e
// Errors:
//
// "value at is not a set" - when the provided key exists but is not a set.
-func (server *EchoVault) SisMember(key, member string) (bool, error) {
+func (server *SugarDB) SisMember(key, member string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SISMEMBER", key, member}), nil, false, true)
if err != nil {
return false, err
@@ -190,7 +190,7 @@ func (server *EchoVault) SisMember(key, member string) (bool, error) {
// Errors:
//
// "value at is not a set" - when the provided key exists but is not a set.
-func (server *EchoVault) SMembers(key string) ([]string, error) {
+func (server *SugarDB) SMembers(key string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SMEMBERS", key}), nil, false, true)
if err != nil {
return nil, err
@@ -212,7 +212,7 @@ func (server *EchoVault) SMembers(key string) ([]string, error) {
// Errors:
//
// "value at is not a set" - when the provided key exists but is not a set.
-func (server *EchoVault) SMisMember(key string, members ...string) ([]bool, error) {
+func (server *SugarDB) SMisMember(key string, members ...string) ([]bool, error) {
cmd := append([]string{"SMISMEMBER", key}, members...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -240,7 +240,7 @@ func (server *EchoVault) SMisMember(key string, members ...string) ([]bool, erro
// "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 (server *EchoVault) SMove(source, destination, member string) (bool, error) {
+func (server *SugarDB) SMove(source, destination, member string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SMOVE", source, destination, member}), nil, false, true)
if err != nil {
return false, err
@@ -261,7 +261,7 @@ func (server *EchoVault) SMove(source, destination, member string) (bool, error)
// Errors:
//
// "value at is not a set" - when the provided key exists but is not a set.
-func (server *EchoVault) SPop(key string, count uint) ([]string, error) {
+func (server *SugarDB) SPop(key string, count uint) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SPOP", key, strconv.Itoa(int(count))}), nil, false, true)
if err != nil {
return nil, err
@@ -283,7 +283,7 @@ func (server *EchoVault) SPop(key string, count uint) ([]string, error) {
// Errors:
//
// "value at is not a set" - when the provided key exists but is not a set.
-func (server *EchoVault) SRandMember(key string, count int) ([]string, error) {
+func (server *SugarDB) SRandMember(key string, count int) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SRANDMEMBER", key, strconv.Itoa(count)}), nil, false, true)
if err != nil {
return nil, err
@@ -304,7 +304,7 @@ func (server *EchoVault) SRandMember(key string, count int) ([]string, error) {
// Errors:
//
// "value at is not a set" - when the provided key exists but is not a set.
-func (server *EchoVault) SRem(key string, members ...string) (int, error) {
+func (server *SugarDB) SRem(key string, members ...string) (int, error) {
cmd := append([]string{"SREM", key}, members...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -325,7 +325,7 @@ func (server *EchoVault) SRem(key string, members ...string) (int, error) {
// Errors:
//
// "value at is not a set" - when the provided key exists but is not a set.
-func (server *EchoVault) SUnion(keys ...string) ([]string, error) {
+func (server *SugarDB) SUnion(keys ...string) ([]string, error) {
cmd := append([]string{"SUNION"}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -338,7 +338,7 @@ func (server *EchoVault) SUnion(keys ...string) ([]string, error) {
// 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 (server *EchoVault) SUnionStore(destination string, keys ...string) (int, error) {
+func (server *SugarDB) SUnionStore(destination string, keys ...string) (int, error) {
cmd := append([]string{"SUNIONSTORE", destination}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
diff --git a/echovault/api_set_test.go b/sugardb/api_set_test.go
similarity index 96%
rename from echovault/api_set_test.go
rename to sugardb/api_set_test.go
index a882671..679907b 100644
--- a/echovault/api_set_test.go
+++ b/sugardb/api_set_test.go
@@ -12,18 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"context"
- "github.com/echovault/echovault/internal/modules/set"
+ "github.com/echovault/sugardb/internal/modules/set"
"reflect"
"slices"
"testing"
)
-func TestEchoVault_SADD(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SADD(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -79,8 +79,8 @@ func TestEchoVault_SADD(t *testing.T) {
}
}
-func TestEchoVault_SCARD(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SCARD(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -132,8 +132,8 @@ func TestEchoVault_SCARD(t *testing.T) {
}
}
-func TestEchoVault_SDIFF(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SDIFF(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -224,8 +224,8 @@ func TestEchoVault_SDIFF(t *testing.T) {
}
}
-func TestEchoVault_SDIFFSTORE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SDIFFSTORE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -317,8 +317,8 @@ func TestEchoVault_SDIFFSTORE(t *testing.T) {
}
}
-func TestEchoVault_SINTER(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SINTER(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -409,8 +409,8 @@ func TestEchoVault_SINTER(t *testing.T) {
}
}
-func TestEchoVault_SINTERCARD(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SINTERCARD(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -512,8 +512,8 @@ func TestEchoVault_SINTERCARD(t *testing.T) {
}
}
-func TestEchoVault_SINTERSTORE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SINTERSTORE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -605,8 +605,8 @@ func TestEchoVault_SINTERSTORE(t *testing.T) {
}
}
-func TestEchoVault_SISMEMBER(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SISMEMBER(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -662,8 +662,8 @@ func TestEchoVault_SISMEMBER(t *testing.T) {
}
}
-func TestEchoVault_SMEMBERS(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SMEMBERS(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -720,8 +720,8 @@ func TestEchoVault_SMEMBERS(t *testing.T) {
}
}
-func TestEchoVault_SMISMEMBER(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SMISMEMBER(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -796,8 +796,8 @@ func TestEchoVault_SMISMEMBER(t *testing.T) {
}
}
-func TestEchoVault_SMOVE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SMOVE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -880,8 +880,8 @@ func TestEchoVault_SMOVE(t *testing.T) {
}
}
-func TestEchoVault_SPOP(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SPOP(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -931,8 +931,8 @@ func TestEchoVault_SPOP(t *testing.T) {
}
}
-func TestEchoVault_SRANDMEMBER(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SRANDMEMBER(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -998,8 +998,8 @@ func TestEchoVault_SRANDMEMBER(t *testing.T) {
}
}
-func TestEchoVault_SREM(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SREM(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1055,8 +1055,8 @@ func TestEchoVault_SREM(t *testing.T) {
}
}
-func TestEchoVault_SUNION(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SUNION(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1140,8 +1140,8 @@ func TestEchoVault_SUNION(t *testing.T) {
}
}
-func TestEchoVault_SUNIONSTORE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SUNIONSTORE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
diff --git a/echovault/api_sorted_set.go b/sugardb/api_sorted_set.go
similarity index 91%
rename from echovault/api_sorted_set.go
rename to sugardb/api_sorted_set.go
index 0357277..40c150e 100644
--- a/echovault/api_sorted_set.go
+++ b/sugardb/api_sorted_set.go
@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
"strconv"
)
@@ -68,9 +68,9 @@ type ZUnionStoreOptions ZInterOptions
// 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.
+// Min instructs SugarDB to pop the minimum score elements. Min is higher priority than Max.
//
-// Max instructs EchoVault to pop the maximum score elements.
+// Max instructs SugarDB to pop the maximum score elements.
//
// Count specifies the number of elements to pop.
type ZMPopOptions struct {
@@ -139,7 +139,7 @@ func buildMemberScoreMap(arr [][]string, withscores bool) (map[string]float64, e
// one member-score pair.
//
// "value at is not a sorted set" - when the provided key exists but is not a sorted set
-func (server *EchoVault) ZAdd(key string, members map[string]float64, options ZAddOptions) (int, error) {
+func (server *SugarDB) ZAdd(key string, members map[string]float64, options ZAddOptions) (int, error) {
cmd := []string{"ZADD", key}
switch {
@@ -187,7 +187,7 @@ func (server *EchoVault) ZAdd(key string, members map[string]float64, options ZA
// Errors:
//
// "value at is not a sorted set" - when the provided key exists but is not a sorted set
-func (server *EchoVault) ZCard(key string) (int, error) {
+func (server *SugarDB) ZCard(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ZCARD", key}), nil, false, true)
if err != nil {
return 0, err
@@ -210,7 +210,7 @@ func (server *EchoVault) ZCard(key string) (int, error) {
// Errors:
//
// "value at is not a sorted set" - when the provided key exists but is not a sorted set
-func (server *EchoVault) ZCount(key string, min, max float64) (int, error) {
+func (server *SugarDB) ZCount(key string, min, max float64) (int, error) {
cmd := []string{
"ZCOUNT",
key,
@@ -239,7 +239,7 @@ func (server *EchoVault) ZCount(key string, min, max float64) (int, error) {
// Errors:
//
// "value at is not a sorted set" - when the provided key exists but is not a sorted set.
-func (server *EchoVault) ZDiff(withscores bool, keys ...string) (map[string]float64, error) {
+func (server *SugarDB) ZDiff(withscores bool, keys ...string) (map[string]float64, error) {
cmd := append([]string{"ZDIFF"}, keys...)
if withscores {
cmd = append(cmd, "WITHSCORES")
@@ -271,7 +271,7 @@ func (server *EchoVault) ZDiff(withscores bool, keys ...string) (map[string]floa
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZDiffStore(destination string, keys ...string) (int, error) {
+func (server *SugarDB) ZDiffStore(destination string, keys ...string) (int, error) {
cmd := append([]string{"ZDIFFSTORE", destination}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -294,7 +294,7 @@ func (server *EchoVault) ZDiffStore(destination string, keys ...string) (int, er
// Errors:
//
// "value at is not a sorted set" - when the provided key exists but is not a sorted set.
-func (server *EchoVault) ZInter(keys []string, options ZInterOptions) (map[string]float64, error) {
+func (server *SugarDB) ZInter(keys []string, options ZInterOptions) (map[string]float64, error) {
cmd := append([]string{"ZINTER"}, keys...)
if len(options.Weights) > 0 {
@@ -341,7 +341,7 @@ func (server *EchoVault) ZInter(keys []string, options ZInterOptions) (map[strin
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZInterStore(destination string, keys []string, options ZInterStoreOptions) (int, error) {
+func (server *SugarDB) ZInterStore(destination string, keys []string, options ZInterStoreOptions) (int, error) {
cmd := append([]string{"ZINTERSTORE", destination}, keys...)
if len(options.Weights) > 0 {
@@ -381,7 +381,7 @@ func (server *EchoVault) ZInterStore(destination string, keys []string, options
// Errors:
//
// "value at is not a sorted set" - when the provided key exists but is not a sorted set.
-func (server *EchoVault) ZUnion(keys []string, options ZUnionOptions) (map[string]float64, error) {
+func (server *SugarDB) ZUnion(keys []string, options ZUnionOptions) (map[string]float64, error) {
cmd := append([]string{"ZUNION"}, keys...)
if len(options.Weights) > 0 {
@@ -428,7 +428,7 @@ func (server *EchoVault) ZUnion(keys []string, options ZUnionOptions) (map[strin
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZUnionStore(destination string, keys []string, options ZUnionStoreOptions) (int, error) {
+func (server *SugarDB) ZUnionStore(destination string, keys []string, options ZUnionStoreOptions) (int, error) {
cmd := append([]string{"ZUNIONSTORE", destination}, keys...)
if len(options.Weights) > 0 {
@@ -470,7 +470,7 @@ func (server *EchoVault) ZUnionStore(destination string, keys []string, options
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZIncrBy(key string, increment float64, member string) (float64, error) {
+func (server *SugarDB) ZIncrBy(key string, increment float64, member string) (float64, error) {
cmd := []string{"ZINCRBY", key, strconv.FormatFloat(increment, 'f', -1, 64), member}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -497,7 +497,7 @@ func (server *EchoVault) ZIncrBy(key string, increment float64, member string) (
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZMPop(keys []string, options ZMPopOptions) ([][]string, error) {
+func (server *SugarDB) ZMPop(keys []string, options ZMPopOptions) ([][]string, error) {
cmd := append([]string{"ZMPOP"}, keys...)
switch {
@@ -539,7 +539,7 @@ func (server *EchoVault) ZMPop(keys []string, options ZMPopOptions) ([][]string,
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZMScore(key string, members ...string) ([]interface{}, error) {
+func (server *SugarDB) ZMScore(key string, members ...string) ([]interface{}, error) {
cmd := []string{"ZMSCORE", key}
for _, member := range members {
cmd = append(cmd, member)
@@ -588,7 +588,7 @@ func (server *EchoVault) ZMScore(key string, members ...string) ([]interface{},
// Errors:
//
// "value at is not a sorted set" - when the provided key exists but is not a sorted set
-func (server *EchoVault) ZLexCount(key, min, max string) (int, error) {
+func (server *SugarDB) ZLexCount(key, min, max string) (int, error) {
cmd := []string{"ZLEXCOUNT", key, min, max}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -613,7 +613,7 @@ func (server *EchoVault) ZLexCount(key, min, max string) (int, error) {
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZPopMax(key string, count uint) ([][]string, error) {
+func (server *SugarDB) ZPopMax(key string, count uint) ([][]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ZPOPMAX", key, strconv.Itoa(int(count))}), nil, false, true)
if err != nil {
return nil, err
@@ -637,7 +637,7 @@ func (server *EchoVault) ZPopMax(key string, count uint) ([][]string, error) {
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZPopMin(key string, count uint) ([][]string, error) {
+func (server *SugarDB) ZPopMin(key string, count uint) ([][]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ZPOPMIN", key, strconv.Itoa(int(count))}), nil, false, true)
if err != nil {
return nil, err
@@ -666,7 +666,7 @@ func (server *EchoVault) ZPopMin(key string, count uint) ([][]string, error) {
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZRandMember(key string, count int, withscores bool) ([][]string, error) {
+func (server *SugarDB) ZRandMember(key string, count int, withscores bool) ([][]string, error) {
cmd := []string{"ZRANDMEMBER", key}
if count != 0 {
cmd = append(cmd, strconv.Itoa(count))
@@ -701,7 +701,7 @@ func (server *EchoVault) ZRandMember(key string, count int, withscores bool) ([]
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZRank(key string, member string, withscores bool) (map[int]float64, error) {
+func (server *SugarDB) ZRank(key string, member string, withscores bool) (map[int]float64, error) {
cmd := []string{"ZRANK", key, member}
if withscores {
cmd = append(cmd, "WITHSCORES")
@@ -738,7 +738,7 @@ func (server *EchoVault) ZRank(key string, member string, withscores bool) (map[
// ZRevRank works the same as ZRank but derives the member's rank based on ascending order of
// the members' scores.
-func (server *EchoVault) ZRevRank(key string, member string, withscores bool) (map[int]float64, error) {
+func (server *SugarDB) ZRevRank(key string, member string, withscores bool) (map[int]float64, error) {
cmd := []string{"ZREVRANK", key, member}
if withscores {
cmd = append(cmd, "WITHSCORES")
@@ -787,7 +787,7 @@ func (server *EchoVault) ZRevRank(key string, member string, withscores bool) (m
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZScore(key string, member string) (interface{}, error) {
+func (server *SugarDB) ZScore(key string, member string) (interface{}, error) {
cmd := []string{"ZSCORE", key, member}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
@@ -824,7 +824,7 @@ func (server *EchoVault) ZScore(key string, member string) (interface{}, error)
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZRem(key string, members ...string) (int, error) {
+func (server *SugarDB) ZRem(key string, members ...string) (int, error) {
cmd := []string{"ZREM", key}
for _, member := range members {
cmd = append(cmd, member)
@@ -851,7 +851,7 @@ func (server *EchoVault) ZRem(key string, members ...string) (int, error) {
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZRemRangeByScore(key string, min float64, max float64) (int, error) {
+func (server *SugarDB) ZRemRangeByScore(key string, min float64, max float64) (int, error) {
cmd := []string{
"ZREMRANGEBYSCORE",
key,
@@ -882,7 +882,7 @@ func (server *EchoVault) ZRemRangeByScore(key string, min float64, max float64)
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZRemRangeByLex(key, min, max string) (int, error) {
+func (server *SugarDB) ZRemRangeByLex(key, min, max string) (int, error) {
b, err := server.handleCommand(
server.context, internal.EncodeCommand([]string{"ZREMRANGEBYLEX", key, min, max}),
nil,
@@ -910,7 +910,7 @@ func (server *EchoVault) ZRemRangeByLex(key, min, max string) (int, error) {
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZRemRangeByRank(key string, min, max int) (int, error) {
+func (server *SugarDB) ZRemRangeByRank(key string, min, max int) (int, error) {
b, err := server.handleCommand(
server.context, internal.EncodeCommand([]string{"ZREMRANGEBYRANK", key, strconv.Itoa(min), strconv.Itoa(max)}),
nil,
@@ -940,7 +940,7 @@ func (server *EchoVault) ZRemRangeByRank(key string, min, max int) (int, error)
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZRange(key, start, stop string, options ZRangeOptions) (map[string]float64, error) {
+func (server *SugarDB) ZRange(key, start, stop string, options ZRangeOptions) (map[string]float64, error) {
cmd := []string{"ZRANGE", key, start, stop}
switch {
@@ -994,7 +994,7 @@ func (server *EchoVault) ZRange(key, start, stop string, options ZRangeOptions)
// Errors:
//
// "value at is not a sorted set" - when a key exists but is not a sorted set.
-func (server *EchoVault) ZRangeStore(destination, source, start, stop string, options ZRangeStoreOptions) (int, error) {
+func (server *SugarDB) ZRangeStore(destination, source, start, stop string, options ZRangeStoreOptions) (int, error) {
cmd := []string{"ZRANGESTORE", destination, source, start, stop}
switch {
diff --git a/echovault/api_sorted_set_test.go b/sugardb/api_sorted_set_test.go
similarity index 98%
rename from echovault/api_sorted_set_test.go
rename to sugardb/api_sorted_set_test.go
index 314e9dc..4eac747 100644
--- a/echovault/api_sorted_set_test.go
+++ b/sugardb/api_sorted_set_test.go
@@ -12,20 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"context"
- "github.com/echovault/echovault/internal"
- ss "github.com/echovault/echovault/internal/modules/sorted_set"
+ "github.com/echovault/sugardb/internal"
+ ss "github.com/echovault/sugardb/internal/modules/sorted_set"
"math"
"reflect"
"strconv"
"testing"
)
-func TestEchoVault_ZADD(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZADD(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -248,8 +248,8 @@ func TestEchoVault_ZADD(t *testing.T) {
}
}
-func TestEchoVault_ZCARD(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZCARD(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -309,8 +309,8 @@ func TestEchoVault_ZCARD(t *testing.T) {
}
}
-func TestEchoVault_ZCOUNT(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZCOUNT(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -408,8 +408,8 @@ func TestEchoVault_ZCOUNT(t *testing.T) {
}
}
-func TestEchoVault_ZDIFF(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZDIFF(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -558,8 +558,8 @@ func TestEchoVault_ZDIFF(t *testing.T) {
}
}
-func TestEchoVault_ZDIFFSTORE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZDIFFSTORE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -677,8 +677,8 @@ func TestEchoVault_ZDIFFSTORE(t *testing.T) {
}
}
-func TestEchoVault_ZINCRBY(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZINCRBY(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -825,8 +825,8 @@ func TestEchoVault_ZINCRBY(t *testing.T) {
}
}
-func TestEchoVault_ZINTER(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZINTER(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1136,8 +1136,8 @@ func TestEchoVault_ZINTER(t *testing.T) {
}
}
-func TestEchoVault_ZINTERSTORE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZINTERSTORE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1461,8 +1461,8 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}
}
-func TestEchoVault_ZLEXCOUNT(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZLEXCOUNT(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1552,8 +1552,8 @@ func TestEchoVault_ZLEXCOUNT(t *testing.T) {
}
}
-func TestEchoVault_ZMPOP(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZMPOP(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1706,8 +1706,8 @@ func TestEchoVault_ZMPOP(t *testing.T) {
}
}
-func TestEchoVault_ZMSCORE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZMSCORE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1785,8 +1785,8 @@ func TestEchoVault_ZMSCORE(t *testing.T) {
}
}
-func TestEchoVault_ZPOP(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZPOP(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1891,8 +1891,8 @@ func TestEchoVault_ZPOP(t *testing.T) {
}
}
-func TestEchoVault_ZRANDMEMBER(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZRANDMEMBER(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -1965,8 +1965,8 @@ func TestEchoVault_ZRANDMEMBER(t *testing.T) {
}
}
-func TestEchoVault_ZRANGE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZRANGE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -2128,8 +2128,8 @@ func TestEchoVault_ZRANGE(t *testing.T) {
}
}
-func TestEchoVault_ZRANGESTORE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZRANGESTORE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -2340,8 +2340,8 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
}
}
-func TestEchoVault_ZRANK(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZRANK(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -2437,8 +2437,8 @@ func TestEchoVault_ZRANK(t *testing.T) {
}
}
-func TestEchoVault_ZREM(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZREM(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -2506,8 +2506,8 @@ func TestEchoVault_ZREM(t *testing.T) {
}
}
-func TestEchoVault_ZREMRANGEBYSCORE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZREMRANGEBYSCORE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -2576,8 +2576,8 @@ func TestEchoVault_ZREMRANGEBYSCORE(t *testing.T) {
}
}
-func TestEchoVault_ZSCORE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZSCORE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -2654,8 +2654,8 @@ func TestEchoVault_ZSCORE(t *testing.T) {
}
}
-func TestEchoVault_ZUNION(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZUNION(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -2990,8 +2990,8 @@ func TestEchoVault_ZUNION(t *testing.T) {
}
}
-func TestEchoVault_ZUNIONSTORE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZUNIONSTORE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -3300,8 +3300,8 @@ func TestEchoVault_ZUNIONSTORE(t *testing.T) {
}
}
-func TestEchoVault_ZRevRank(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZRevRank(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -3397,8 +3397,8 @@ func TestEchoVault_ZRevRank(t *testing.T) {
}
}
-func TestEchoVault_ZRemRangeByLex(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZRemRangeByLex(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
key string
@@ -3478,8 +3478,8 @@ func TestEchoVault_ZRemRangeByLex(t *testing.T) {
}
}
-func TestEchoVault_ZRemRangeByRank(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_ZRemRangeByRank(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
key string
diff --git a/echovault/api_string.go b/sugardb/api_string.go
similarity index 87%
rename from echovault/api_string.go
rename to sugardb/api_string.go
index 2aaa398..0c5d082 100644
--- a/echovault/api_string.go
+++ b/sugardb/api_string.go
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"strconv"
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
)
// SetRange replaces a portion of the string at the provided key starting at the offset with a new string.
@@ -28,7 +28,7 @@ import (
// Errors:
//
// - "value at key is not a string" when the key provided does not hold a string.
-func (server *EchoVault) SetRange(key string, offset int, new string) (int, error) {
+func (server *SugarDB) SetRange(key string, offset int, new string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SETRANGE", key, strconv.Itoa(offset), new}), nil, false, true)
if err != nil {
return 0, err
@@ -43,7 +43,7 @@ func (server *EchoVault) SetRange(key string, offset int, new string) (int, erro
// Errors:
//
// - "value at key is not a string" - when the value at the keys is not a string.
-func (server *EchoVault) StrLen(key string) (int, error) {
+func (server *SugarDB) StrLen(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"STRLEN", key}), nil, false, true)
if err != nil {
return 0, err
@@ -61,7 +61,7 @@ func (server *EchoVault) StrLen(key string) (int, error) {
// - "key does not exist" - when the key does not exist.
//
// - "value at key is not a string" - when the value at the keys is not a string.
-func (server *EchoVault) SubStr(key string, start, end int) (string, error) {
+func (server *SugarDB) SubStr(key string, start, end int) (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SUBSTR", key, strconv.Itoa(start), strconv.Itoa(end)}), nil, false, true)
if err != nil {
return "", err
@@ -70,7 +70,7 @@ func (server *EchoVault) SubStr(key string, start, end int) (string, error) {
}
// GetRange works the same as SubStr.
-func (server *EchoVault) GetRange(key string, start, end int) (string, error) {
+func (server *SugarDB) GetRange(key string, start, end int) (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"GETRANGE", key, strconv.Itoa(start), strconv.Itoa(end)}), nil, false, true)
if err != nil {
return "", err
@@ -86,7 +86,7 @@ func (server *EchoVault) GetRange(key string, start, end int) (string, error) {
// Errors:
//
// - "value at key is not a string" - when the value at the keys is not a string.
-func (server *EchoVault) Append(key string, value string) (int, error) {
+func (server *SugarDB) Append(key string, value string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"APPEND", key, value}), nil, false, true)
if err != nil {
return 0, err
diff --git a/echovault/api_string_test.go b/sugardb/api_string_test.go
similarity index 96%
rename from echovault/api_string_test.go
rename to sugardb/api_string_test.go
index 2c21972..6888fad 100644
--- a/echovault/api_string_test.go
+++ b/sugardb/api_string_test.go
@@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"context"
"testing"
)
-func TestEchoVault_SUBSTR(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SUBSTR(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -178,8 +178,8 @@ func TestEchoVault_SUBSTR(t *testing.T) {
}
}
-func TestEchoVault_SETRANGE(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_SETRANGE(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -266,8 +266,8 @@ func TestEchoVault_SETRANGE(t *testing.T) {
}
}
-func TestEchoVault_STRLEN(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_STRLEN(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
@@ -312,8 +312,8 @@ func TestEchoVault_STRLEN(t *testing.T) {
}
}
-func TestEchoVault_APPEND(t *testing.T) {
- server := createEchoVault()
+func TestSugarDB_APPEND(t *testing.T) {
+ server := createSugarDB()
tests := []struct {
name string
presetValue interface{}
diff --git a/echovault/cluster.go b/sugardb/cluster.go
similarity index 89%
rename from echovault/cluster.go
rename to sugardb/cluster.go
index d1c8ca2..9ec4f02 100644
--- a/echovault/cluster.go
+++ b/sugardb/cluster.go
@@ -12,21 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"context"
"encoding/json"
"fmt"
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
"time"
)
-func (server *EchoVault) isInCluster() bool {
+func (server *SugarDB) isInCluster() bool {
return server.config.BootstrapCluster || server.config.JoinAddr != ""
}
-func (server *EchoVault) raftApplyDeleteKey(ctx context.Context, key string) error {
+func (server *SugarDB) raftApplyDeleteKey(ctx context.Context, key string) error {
serverId, _ := ctx.Value(internal.ContextServerID("ServerID")).(string)
protocol, _ := ctx.Value("Protocol").(int)
database, _ := ctx.Value("Database").(int)
@@ -64,7 +64,7 @@ func (server *EchoVault) raftApplyDeleteKey(ctx context.Context, key string) err
return nil
}
-func (server *EchoVault) raftApplyCommand(ctx context.Context, cmd []string) ([]byte, error) {
+func (server *SugarDB) raftApplyCommand(ctx context.Context, cmd []string) ([]byte, error) {
serverId, _ := ctx.Value(internal.ContextServerID("ServerID")).(string)
connectionId, _ := ctx.Value(internal.ContextConnID("ConnectionID")).(string)
protocol, _ := ctx.Value("Protocol").(int)
diff --git a/sugardb/config.go b/sugardb/config.go
new file mode 100644
index 0000000..ba99d8f
--- /dev/null
+++ b/sugardb/config.go
@@ -0,0 +1,331 @@
+// Copyright 2024 Kelvin Clement Mwinuka
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package sugardb
+
+import (
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+ "time"
+)
+
+// DefaultConfig returns the default configuration.
+// This should be used when using SugarDB as an embedded library.
+func DefaultConfig() config.Config {
+ return config.DefaultConfig()
+}
+
+func (server *SugarDB) GetServerInfo() internal.ServerInfo {
+ return internal.ServerInfo{
+ Server: "sugardb",
+ Version: constants.Version,
+ Id: server.config.ServerID,
+ Mode: func() string {
+ if server.isInCluster() {
+ return "cluster"
+ }
+ return "standalone"
+ }(),
+ Role: func() string {
+ if !server.isInCluster() {
+ return "master"
+ }
+ if server.raft.IsRaftLeader() {
+ return "master"
+ }
+ return "replica"
+ }(),
+ Modules: server.ListModules(),
+ }
+}
+
+// WithTLS is an option to the NewSugarDB function that allows you to pass a
+// custom TLS to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithTLS(b ...bool) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ if len(b) > 0 {
+ sugardb.config.TLS = b[0]
+ } else {
+ sugardb.config.TLS = true
+ }
+ }
+}
+
+// WithMTLS is an option to the NewSugarDB function that allows you to pass a
+// custom MTLS to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithMTLS(b ...bool) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ if len(b) > 0 {
+ sugardb.config.MTLS = b[0]
+ } else {
+ sugardb.config.MTLS = true
+ }
+ }
+}
+
+// CertKeyPair defines the paths to the cert and key pair files respectively.
+type CertKeyPair struct {
+ Cert string
+ Key string
+}
+
+// WithCertKeyPairs is an option to the NewSugarDB function that allows you to pass a
+// custom CertKeyPairs to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithCertKeyPairs(certKeyPairs []CertKeyPair) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ for _, pair := range certKeyPairs {
+ sugardb.config.CertKeyPairs = append(sugardb.config.CertKeyPairs, []string{pair.Cert, pair.Key})
+ }
+ }
+}
+
+// WithClientCAs is an option to the NewSugarDB function that allows you to pass a
+// custom ClientCAs to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithClientCAs(clientCAs []string) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.ClientCAs = clientCAs
+ }
+}
+
+// WithPort is an option to the NewSugarDB function that allows you to pass a
+// custom Port to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithPort(port uint16) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.Port = port
+ }
+}
+
+// WithServerID is an option to the NewSugarDB function that allows you to pass a
+// custom ServerID to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithServerID(serverID string) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.ServerID = serverID
+ }
+}
+
+// WithJoinAddr is an option to the NewSugarDB function that allows you to pass a
+// custom JoinAddr to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithJoinAddr(joinAddr string) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.JoinAddr = joinAddr
+ }
+}
+
+// WithBindAddr is an option to the NewSugarDB function that allows you to pass a
+// custom BindAddr to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithBindAddr(bindAddr string) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.BindAddr = bindAddr
+ }
+}
+
+// WithDataDir is an option to the NewSugarDB function that allows you to pass a
+// custom DataDir to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithDataDir(dataDir string) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.DataDir = dataDir
+ }
+}
+
+// WithBootstrapCluster is an option to the NewSugarDB function that allows you to pass a
+// custom BootstrapCluster to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithBootstrapCluster(b ...bool) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ if len(b) > 0 {
+ sugardb.config.BootstrapCluster = b[0]
+ } else {
+ sugardb.config.BootstrapCluster = true
+ }
+ }
+}
+
+// WithAclConfig is an option to the NewSugarDB function that allows you to pass a
+// custom AclConfig to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithAclConfig(aclConfig string) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.AclConfig = aclConfig
+ }
+}
+
+// WithForwardCommand is an option to the NewSugarDB function that allows you to pass a
+// custom ForwardCommand to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithForwardCommand(b ...bool) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ if len(b) > 0 {
+ sugardb.config.ForwardCommand = b[0]
+ } else {
+ sugardb.config.ForwardCommand = true
+ }
+ }
+}
+
+// WithRequirePass is an option to the NewSugarDB function that allows you to pass a
+// custom RequirePass to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithRequirePass(b ...bool) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ if len(b) > 0 {
+ sugardb.config.RequirePass = b[0]
+ } else {
+ sugardb.config.RequirePass = true
+ }
+ }
+}
+
+// WithPassword is an option to the NewSugarDB function that allows you to pass a
+// custom Password to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithPassword(password string) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.Password = password
+ }
+}
+
+// WithSnapShotThreshold is an option to the NewSugarDB function that allows you to pass a
+// custom SnapShotThreshold to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithSnapShotThreshold(snapShotThreshold uint64) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.SnapShotThreshold = snapShotThreshold
+ }
+}
+
+// WithSnapshotInterval is an option to the NewSugarDB function that allows you to pass a
+// custom SnapshotInterval to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithSnapshotInterval(snapshotInterval time.Duration) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.SnapshotInterval = snapshotInterval
+ }
+}
+
+// WithRestoreSnapshot is an option to the NewSugarDB function that allows you to pass a
+// custom RestoreSnapshot to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithRestoreSnapshot(b ...bool) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ if len(b) > 0 {
+ sugardb.config.RestoreSnapshot = b[0]
+ } else {
+ sugardb.config.RestoreSnapshot = true
+ }
+ }
+}
+
+// WithRestoreAOF is an option to the NewSugarDB function that allows you to pass a
+// custom RestoreAOF to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithRestoreAOF(b ...bool) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ if len(b) > 0 {
+ sugardb.config.RestoreAOF = b[0]
+ } else {
+ sugardb.config.RestoreAOF = true
+ }
+ }
+}
+
+// WithAOFSyncStrategy is an option to the NewSugarDB function that allows you to pass a
+// custom AOFSyncStrategy to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithAOFSyncStrategy(aOFSyncStrategy string) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.AOFSyncStrategy = aOFSyncStrategy
+ }
+}
+
+// WithMaxMemory is an option to the NewSugarDB function that allows you to pass a
+// custom MaxMemory to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithMaxMemory(maxMemory uint64) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.MaxMemory = maxMemory
+ }
+}
+
+// WithEvictionPolicy is an option to the NewSugarDB function that allows you to pass a
+// custom EvictionPolicy to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithEvictionPolicy(evictionPolicy string) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.EvictionPolicy = evictionPolicy
+ }
+}
+
+// WithEvictionSample is an option to the NewSugarDB function that allows you to pass a
+// custom EvictionSample to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithEvictionSample(evictionSample uint) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.EvictionSample = evictionSample
+ }
+}
+
+// WithEvictionInterval is an option to the NewSugarDB function that allows you to pass a
+// custom EvictionInterval to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithEvictionInterval(evictionInterval time.Duration) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.EvictionInterval = evictionInterval
+ }
+}
+
+// WithModules is an option to the NewSugarDB function that allows you to pass a
+// custom Modules to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithModules(modules []string) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.Modules = modules
+ }
+}
+
+// WithDiscoveryPort is an option to the NewSugarDB function that allows you to pass a
+// custom DiscoveryPort to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithDiscoveryPort(discoveryPort uint16) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.DiscoveryPort = discoveryPort
+ }
+}
+
+// WithRaftBindAddr is an option to the NewSugarDB function that allows you to pass a
+// custom RaftBindAddr to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithRaftBindAddr(raftBindAddr string) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.RaftBindAddr = raftBindAddr
+ }
+}
+
+// WithRaftBindPort is an option to the NewSugarDB function that allows you to pass a
+// custom RaftBindPort to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithRaftBindPort(raftBindPort uint16) func(sugardb *SugarDB) {
+ return func(sugardb *SugarDB) {
+ sugardb.config.RaftBindPort = raftBindPort
+ }
+}
diff --git a/echovault/keyspace.go b/sugardb/keyspace.go
similarity index 93%
rename from echovault/keyspace.go
rename to sugardb/keyspace.go
index 6ee3e5a..e214130 100644
--- a/echovault/keyspace.go
+++ b/sugardb/keyspace.go
@@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"container/heap"
"context"
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/constants"
- "github.com/echovault/echovault/internal/eviction"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/internal/eviction"
"log"
"math/rand"
"runtime"
@@ -35,7 +35,7 @@ import (
// It also swaps every TCP client connection from database2 over to database1.
// This only affects TCP connections, it does not swap the logical database currently
// being used by the embedded API.
-func (server *EchoVault) SwapDBs(database1, database2 int) {
+func (server *SugarDB) SwapDBs(database1, database2 int) {
// If the databases are the same, skip the swap.
if database1 == database2 {
return
@@ -75,7 +75,7 @@ func (server *EchoVault) SwapDBs(database1, database2 int) {
// Flush flushes all the data from the database at the specified index.
// When -1 is passed, all the logical databases are cleared.
-func (server *EchoVault) Flush(database int) {
+func (server *SugarDB) Flush(database int) {
server.storeLock.Lock()
defer server.storeLock.Unlock()
@@ -114,7 +114,7 @@ func (server *EchoVault) Flush(database int) {
server.lruCache.cache[database].Mutex.Unlock()
}
-func (server *EchoVault) keysExist(ctx context.Context, keys []string) map[string]bool {
+func (server *SugarDB) keysExist(ctx context.Context, keys []string) map[string]bool {
server.storeLock.RLock()
defer server.storeLock.RUnlock()
@@ -130,7 +130,7 @@ func (server *EchoVault) keysExist(ctx context.Context, keys []string) map[strin
return exists
}
-func (server *EchoVault) getExpiry(ctx context.Context, key string) time.Time {
+func (server *SugarDB) getExpiry(ctx context.Context, key string) time.Time {
server.storeLock.RLock()
defer server.storeLock.RUnlock()
@@ -144,7 +144,7 @@ func (server *EchoVault) getExpiry(ctx context.Context, key string) time.Time {
return entry.ExpireAt
}
-func (server *EchoVault) getValues(ctx context.Context, keys []string) map[string]interface{} {
+func (server *SugarDB) getValues(ctx context.Context, keys []string) map[string]interface{} {
server.storeLock.Lock()
defer server.storeLock.Unlock()
@@ -195,7 +195,7 @@ func (server *EchoVault) getValues(ctx context.Context, keys []string) map[strin
return values
}
-func (server *EchoVault) setValues(ctx context.Context, entries map[string]interface{}) error {
+func (server *SugarDB) setValues(ctx context.Context, entries map[string]interface{}) error {
server.storeLock.Lock()
defer server.storeLock.Unlock()
@@ -237,7 +237,7 @@ func (server *EchoVault) setValues(ctx context.Context, entries map[string]inter
return nil
}
-func (server *EchoVault) setExpiry(ctx context.Context, key string, expireAt time.Time, touch bool) {
+func (server *SugarDB) setExpiry(ctx context.Context, key string, expireAt time.Time, touch bool) {
server.storeLock.Lock()
defer server.storeLock.Unlock()
@@ -266,7 +266,7 @@ func (server *EchoVault) setExpiry(ctx context.Context, key string, expireAt tim
}
}
-func (server *EchoVault) deleteKey(ctx context.Context, key string) error {
+func (server *SugarDB) deleteKey(ctx context.Context, key string) error {
database := ctx.Value("Database").(int)
// Delete the key from keyLocks and store.
@@ -292,7 +292,7 @@ func (server *EchoVault) deleteKey(ctx context.Context, key string) error {
return nil
}
-func (server *EchoVault) createDatabase(database int) {
+func (server *SugarDB) createDatabase(database int) {
// Create database store.
server.store[database] = make(map[string]internal.KeyData)
@@ -312,7 +312,7 @@ func (server *EchoVault) createDatabase(database int) {
server.lruCache.cache[database] = eviction.NewCacheLRU()
}
-func (server *EchoVault) getState() map[int]map[string]interface{} {
+func (server *SugarDB) getState() map[int]map[string]interface{} {
// 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() {
@@ -333,7 +333,7 @@ func (server *EchoVault) getState() map[int]map[string]interface{} {
// updateKeysInCache 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 *EchoVault) updateKeysInCache(ctx context.Context, keys []string) (int64, error) {
+func (server *SugarDB) updateKeysInCache(ctx context.Context, keys []string) (int64, error) {
database := ctx.Value("Database").(int)
var touchCounter int64
@@ -411,7 +411,7 @@ func (server *EchoVault) updateKeysInCache(ctx context.Context, keys []string) (
}
// adjustMemoryUsage should only be called from standalone echovault or from raft cluster leader.
-func (server *EchoVault) adjustMemoryUsage(ctx context.Context) error {
+func (server *SugarDB) 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
@@ -583,7 +583,7 @@ func (server *EchoVault) 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 *EchoVault) evictKeysWithExpiredTTL(ctx context.Context) error {
+func (server *SugarDB) 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
@@ -653,7 +653,7 @@ func (server *EchoVault) evictKeysWithExpiredTTL(ctx context.Context) error {
return nil
}
-func (server *EchoVault) randomKey(ctx context.Context) string {
+func (server *SugarDB) randomKey(ctx context.Context) string {
server.storeLock.RLock()
defer server.storeLock.RUnlock()
@@ -681,7 +681,7 @@ func (server *EchoVault) randomKey(ctx context.Context) string {
return randkey
}
-func (server *EchoVault) getObjectFreq(ctx context.Context, key string) (int, error) {
+func (server *SugarDB) getObjectFreq(ctx context.Context, key string) (int, error) {
database := ctx.Value("Database").(int)
var freq int
@@ -701,7 +701,7 @@ func (server *EchoVault) getObjectFreq(ctx context.Context, key string) (int, er
return freq, nil
}
-func (server *EchoVault) getObjectIdleTime(ctx context.Context, key string) (float64, error) {
+func (server *SugarDB) getObjectIdleTime(ctx context.Context, key string) (float64, error) {
database := ctx.Value("Database").(int)
var accessTime int64
diff --git a/echovault/modules.go b/sugardb/modules.go
similarity index 89%
rename from echovault/modules.go
rename to sugardb/modules.go
index 1287d67..08f68be 100644
--- a/echovault/modules.go
+++ b/sugardb/modules.go
@@ -12,21 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"context"
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/clock"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/clock"
+ "github.com/echovault/sugardb/internal/constants"
"io"
"net"
"strings"
)
-func (server *EchoVault) getCommand(cmd string) (internal.Command, error) {
+func (server *SugarDB) getCommand(cmd string) (internal.Command, error) {
server.commandsRWMut.RLock()
defer server.commandsRWMut.RUnlock()
for _, command := range server.commands {
@@ -37,7 +37,7 @@ func (server *EchoVault) getCommand(cmd string) (internal.Command, error) {
return internal.Command{}, fmt.Errorf("command %s not supported", cmd)
}
-func (server *EchoVault) getHandlerFuncParams(ctx context.Context, cmd []string, conn *net.Conn) internal.HandlerFuncParams {
+func (server *SugarDB) getHandlerFuncParams(ctx context.Context, cmd []string, conn *net.Conn) internal.HandlerFuncParams {
return internal.HandlerFuncParams{
Context: ctx,
Command: cmd,
@@ -103,7 +103,7 @@ func (server *EchoVault) getHandlerFuncParams(ctx context.Context, cmd []string,
}
}
-func (server *EchoVault) handleCommand(ctx context.Context, message []byte, conn *net.Conn, replay bool, embedded bool) ([]byte, error) {
+func (server *SugarDB) handleCommand(ctx context.Context, message []byte, conn *net.Conn, replay bool, embedded bool) ([]byte, error) {
// Prepare context before processing the command.
server.connInfo.mut.RLock()
if embedded && !replay {
@@ -207,18 +207,18 @@ func (server *EchoVault) handleCommand(ctx context.Context, message []byte, conn
return nil, errors.New("not cluster leader, cannot carry out command")
}
-func (server *EchoVault) getCommands() []internal.Command {
+func (server *SugarDB) getCommands() []internal.Command {
return server.commands
}
-func (server *EchoVault) getACL() interface{} {
+func (server *SugarDB) getACL() interface{} {
return server.acl
}
-func (server *EchoVault) getPubSub() interface{} {
+func (server *SugarDB) getPubSub() interface{} {
return server.pubSub
}
-func (server *EchoVault) getClock() clock.Clock {
+func (server *SugarDB) getClock() clock.Clock {
return server.clock
}
diff --git a/echovault/plugin.go b/sugardb/plugin.go
similarity index 94%
rename from echovault/plugin.go
rename to sugardb/plugin.go
index 6ec309b..698dd93 100644
--- a/echovault/plugin.go
+++ b/sugardb/plugin.go
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"context"
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
+ "github.com/echovault/sugardb/internal"
"io/fs"
"os"
"plugin"
@@ -26,7 +26,7 @@ import (
"strings"
)
-// LoadModule loads an external module into EchoVault ar runtime.
+// LoadModule loads an external module into SugarDB ar runtime.
//
// Parameters:
//
@@ -34,7 +34,7 @@ import (
//
// `args` - ...string - A list of args that will be passed unmodified to the plugins command's
// KeyExtractionFunc and HandlerFunc
-func (server *EchoVault) LoadModule(path string, args ...string) error {
+func (server *SugarDB) LoadModule(path string, args ...string) error {
server.commandsRWMut.Lock()
defer server.commandsRWMut.Unlock()
@@ -162,7 +162,7 @@ func (server *EchoVault) LoadModule(path string, args ...string) error {
// Parameters:
//
// `module` - string - module name as displayed by the ListModules method.
-func (server *EchoVault) UnloadModule(module string) {
+func (server *SugarDB) UnloadModule(module string) {
server.commandsRWMut.Lock()
defer server.commandsRWMut.Unlock()
server.commands = slices.DeleteFunc(server.commands, func(command internal.Command) bool {
@@ -173,7 +173,7 @@ func (server *EchoVault) UnloadModule(module string) {
// ListModules lists the currently loaded modules
//
// Returns: a string slice representing all the currently loaded modules.
-func (server *EchoVault) ListModules() []string {
+func (server *SugarDB) ListModules() []string {
server.commandsRWMut.RLock()
defer server.commandsRWMut.RUnlock()
var modules []string
diff --git a/echovault/echovault.go b/sugardb/sugardb.go
similarity index 70%
rename from echovault/echovault.go
rename to sugardb/sugardb.go
index 7886de9..770a520 100644
--- a/echovault/echovault.go
+++ b/sugardb/sugardb.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"context"
@@ -20,25 +20,25 @@ import (
"crypto/x509"
"errors"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/aof"
- "github.com/echovault/echovault/internal/clock"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
- "github.com/echovault/echovault/internal/eviction"
- "github.com/echovault/echovault/internal/memberlist"
- "github.com/echovault/echovault/internal/modules/acl"
- "github.com/echovault/echovault/internal/modules/admin"
- "github.com/echovault/echovault/internal/modules/connection"
- "github.com/echovault/echovault/internal/modules/generic"
- "github.com/echovault/echovault/internal/modules/hash"
- "github.com/echovault/echovault/internal/modules/list"
- "github.com/echovault/echovault/internal/modules/pubsub"
- "github.com/echovault/echovault/internal/modules/set"
- "github.com/echovault/echovault/internal/modules/sorted_set"
- str "github.com/echovault/echovault/internal/modules/string"
- "github.com/echovault/echovault/internal/raft"
- "github.com/echovault/echovault/internal/snapshot"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/aof"
+ "github.com/echovault/sugardb/internal/clock"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+ "github.com/echovault/sugardb/internal/eviction"
+ "github.com/echovault/sugardb/internal/memberlist"
+ "github.com/echovault/sugardb/internal/modules/acl"
+ "github.com/echovault/sugardb/internal/modules/admin"
+ "github.com/echovault/sugardb/internal/modules/connection"
+ "github.com/echovault/sugardb/internal/modules/generic"
+ "github.com/echovault/sugardb/internal/modules/hash"
+ "github.com/echovault/sugardb/internal/modules/list"
+ "github.com/echovault/sugardb/internal/modules/pubsub"
+ "github.com/echovault/sugardb/internal/modules/set"
+ "github.com/echovault/sugardb/internal/modules/sorted_set"
+ str "github.com/echovault/sugardb/internal/modules/string"
+ "github.com/echovault/sugardb/internal/raft"
+ "github.com/echovault/sugardb/internal/snapshot"
"io"
"log"
"net"
@@ -48,7 +48,7 @@ import (
"time"
)
-type EchoVault struct {
+type SugarDB struct {
// clock is an implementation of a time interface that allows mocking of time functions during testing.
clock clock.Clock
@@ -122,28 +122,28 @@ type EchoVault struct {
stopTTL chan struct{} // Channel that signals the TTL sampling goroutine to stop execution.
}
-// 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.
-func WithContext(ctx context.Context) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
+// WithContext is an options that for the NewSugarDB function that allows you to
+// configure a custom context object to be used in SugarDB.
+// If you don't provide this option, SugarDB will create its own internal context object.
+func WithContext(ctx context.Context) func(echovault *SugarDB) {
+ return func(echovault *SugarDB) {
echovault.context = ctx
}
}
-// 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 WithConfig(config config.Config) func(echovault *EchoVault) {
- return func(echovault *EchoVault) {
+// WithConfig is an option for the NewSugarDB function that allows you to pass a
+// custom configuration to SugarDB.
+// If not specified, SugarDB will use the default configuration from config.DefaultConfig().
+func WithConfig(config config.Config) func(echovault *SugarDB) {
+ return func(echovault *SugarDB) {
echovault.config = config
}
}
-// NewEchoVault creates a new EchoVault instance.
+// NewSugarDB creates a new SugarDB instance.
// This functions accepts the WithContext, WithConfig and WithCommands options.
-func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
- echovault := &EchoVault{
+func NewSugarDB(options ...func(sugarDB *SugarDB)) (*SugarDB, error) {
+ sugarDB := &SugarDB{
clock: clock.NewClock(),
context: context.Background(),
config: config.DefaultConfig(),
@@ -190,17 +190,17 @@ func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
}
for _, option := range options {
- option(echovault)
+ option(sugarDB)
}
- echovault.context = context.WithValue(
- echovault.context, "ServerID",
- internal.ContextServerID(echovault.config.ServerID),
+ sugarDB.context = context.WithValue(
+ sugarDB.context, "ServerID",
+ internal.ContextServerID(sugarDB.config.ServerID),
)
// Load .so modules from config
- for _, path := range echovault.config.Modules {
- if err := echovault.LoadModule(path); err != nil {
+ for _, path := range sugarDB.config.Modules {
+ if err := sugarDB.LoadModule(path); err != nil {
log.Printf("%s %v\n", path, err)
continue
}
@@ -208,29 +208,29 @@ func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
}
// Set up ACL module
- echovault.acl = acl.NewACL(echovault.config)
+ sugarDB.acl = acl.NewACL(sugarDB.config)
// Set up Pub/Sub module
- echovault.pubSub = pubsub.NewPubSub()
+ sugarDB.pubSub = pubsub.NewPubSub()
- if echovault.isInCluster() {
- echovault.raft = raft.NewRaft(raft.Opts{
- Config: echovault.config,
- GetCommand: echovault.getCommand,
- SetValues: echovault.setValues,
- SetExpiry: echovault.setExpiry,
- StartSnapshot: echovault.startSnapshot,
- FinishSnapshot: echovault.finishSnapshot,
- SetLatestSnapshotTime: echovault.setLatestSnapshot,
- GetHandlerFuncParams: echovault.getHandlerFuncParams,
+ if sugarDB.isInCluster() {
+ sugarDB.raft = raft.NewRaft(raft.Opts{
+ Config: sugarDB.config,
+ GetCommand: sugarDB.getCommand,
+ SetValues: sugarDB.setValues,
+ SetExpiry: sugarDB.setExpiry,
+ StartSnapshot: sugarDB.startSnapshot,
+ FinishSnapshot: sugarDB.finishSnapshot,
+ SetLatestSnapshotTime: sugarDB.setLatestSnapshot,
+ GetHandlerFuncParams: sugarDB.getHandlerFuncParams,
DeleteKey: func(ctx context.Context, key string) error {
- echovault.storeLock.Lock()
- defer echovault.storeLock.Unlock()
- return echovault.deleteKey(ctx, key)
+ sugarDB.storeLock.Lock()
+ defer sugarDB.storeLock.Unlock()
+ return sugarDB.deleteKey(ctx, key)
},
GetState: func() map[int]map[string]internal.KeyData {
state := make(map[int]map[string]internal.KeyData)
- for database, store := range echovault.getState() {
+ for database, store := range sugarDB.getState() {
for k, v := range store {
if data, ok := v.(internal.KeyData); ok {
state[database][k] = data
@@ -240,29 +240,29 @@ func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
return state
},
})
- echovault.memberList = memberlist.NewMemberList(memberlist.Opts{
- Config: echovault.config,
- HasJoinedCluster: echovault.raft.HasJoinedCluster,
- AddVoter: echovault.raft.AddVoter,
- RemoveRaftServer: echovault.raft.RemoveServer,
- IsRaftLeader: echovault.raft.IsRaftLeader,
- ApplyMutate: echovault.raftApplyCommand,
- ApplyDeleteKey: echovault.raftApplyDeleteKey,
+ sugarDB.memberList = memberlist.NewMemberList(memberlist.Opts{
+ Config: sugarDB.config,
+ HasJoinedCluster: sugarDB.raft.HasJoinedCluster,
+ AddVoter: sugarDB.raft.AddVoter,
+ RemoveRaftServer: sugarDB.raft.RemoveServer,
+ IsRaftLeader: sugarDB.raft.IsRaftLeader,
+ ApplyMutate: sugarDB.raftApplyCommand,
+ ApplyDeleteKey: sugarDB.raftApplyDeleteKey,
})
} else {
// Set up standalone snapshot engine
- echovault.snapshotEngine = snapshot.NewSnapshotEngine(
- snapshot.WithClock(echovault.clock),
- snapshot.WithDirectory(echovault.config.DataDir),
- snapshot.WithThreshold(echovault.config.SnapShotThreshold),
- snapshot.WithInterval(echovault.config.SnapshotInterval),
- snapshot.WithStartSnapshotFunc(echovault.startSnapshot),
- snapshot.WithFinishSnapshotFunc(echovault.finishSnapshot),
- snapshot.WithSetLatestSnapshotTimeFunc(echovault.setLatestSnapshot),
- snapshot.WithGetLatestSnapshotTimeFunc(echovault.getLatestSnapshotTime),
+ sugarDB.snapshotEngine = snapshot.NewSnapshotEngine(
+ snapshot.WithClock(sugarDB.clock),
+ snapshot.WithDirectory(sugarDB.config.DataDir),
+ snapshot.WithThreshold(sugarDB.config.SnapShotThreshold),
+ snapshot.WithInterval(sugarDB.config.SnapshotInterval),
+ snapshot.WithStartSnapshotFunc(sugarDB.startSnapshot),
+ snapshot.WithFinishSnapshotFunc(sugarDB.finishSnapshot),
+ snapshot.WithSetLatestSnapshotTimeFunc(sugarDB.setLatestSnapshot),
+ snapshot.WithGetLatestSnapshotTimeFunc(sugarDB.getLatestSnapshotTime),
snapshot.WithGetStateFunc(func() map[int]map[string]internal.KeyData {
state := make(map[int]map[string]internal.KeyData)
- for database, data := range echovault.getState() {
+ for database, data := range sugarDB.getState() {
state[database] = make(map[string]internal.KeyData)
for key, value := range data {
if keyData, ok := value.(internal.KeyData); ok {
@@ -274,23 +274,23 @@ func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
}),
snapshot.WithSetKeyDataFunc(func(database int, key string, data internal.KeyData) {
ctx := context.WithValue(context.Background(), "Database", database)
- if err := echovault.setValues(ctx, map[string]interface{}{key: data.Value}); err != nil {
+ if err := sugarDB.setValues(ctx, map[string]interface{}{key: data.Value}); err != nil {
log.Println(err)
}
- echovault.setExpiry(ctx, key, data.ExpireAt, false)
+ sugarDB.setExpiry(ctx, key, data.ExpireAt, false)
}),
)
// Set up standalone AOF engine
aofEngine, err := aof.NewAOFEngine(
- aof.WithClock(echovault.clock),
- aof.WithDirectory(echovault.config.DataDir),
- aof.WithStrategy(echovault.config.AOFSyncStrategy),
- aof.WithStartRewriteFunc(echovault.startRewriteAOF),
- aof.WithFinishRewriteFunc(echovault.finishRewriteAOF),
+ aof.WithClock(sugarDB.clock),
+ aof.WithDirectory(sugarDB.config.DataDir),
+ aof.WithStrategy(sugarDB.config.AOFSyncStrategy),
+ aof.WithStartRewriteFunc(sugarDB.startRewriteAOF),
+ aof.WithFinishRewriteFunc(sugarDB.finishRewriteAOF),
aof.WithGetStateFunc(func() map[int]map[string]internal.KeyData {
state := make(map[int]map[string]internal.KeyData)
- for database, data := range echovault.getState() {
+ for database, data := range sugarDB.getState() {
state[database] = make(map[string]internal.KeyData)
for key, value := range data {
if keyData, ok := value.(internal.KeyData); ok {
@@ -302,15 +302,15 @@ func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
}),
aof.WithSetKeyDataFunc(func(database int, key string, value internal.KeyData) {
ctx := context.WithValue(context.Background(), "Database", database)
- if err := echovault.setValues(ctx, map[string]interface{}{key: value.Value}); err != nil {
+ if err := sugarDB.setValues(ctx, map[string]interface{}{key: value.Value}); err != nil {
log.Println(err)
}
- echovault.setExpiry(ctx, key, value.ExpireAt, false)
+ sugarDB.setExpiry(ctx, key, value.ExpireAt, false)
}),
aof.WithHandleCommandFunc(func(database int, command []byte) {
ctx := context.WithValue(context.Background(), "Protocol", 2)
ctx = context.WithValue(ctx, "Database", database)
- _, err := echovault.handleCommand(ctx, command, nil, true, false)
+ _, err := sugarDB.handleCommand(ctx, command, nil, true, false)
if err != nil {
log.Println(err)
}
@@ -319,13 +319,13 @@ func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
if err != nil {
return nil, err
}
- echovault.aofEngine = aofEngine
+ sugarDB.aofEngine = aofEngine
}
// If eviction policy is not noeviction, start a goroutine to evict keys at the configured interval.
- if echovault.config.EvictionPolicy != constants.NoEviction {
+ if sugarDB.config.EvictionPolicy != constants.NoEviction {
go func() {
- ticker := time.NewTicker(echovault.config.EvictionInterval)
+ ticker := time.NewTicker(sugarDB.config.EvictionInterval)
defer func() {
ticker.Stop()
}()
@@ -334,59 +334,59 @@ func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
case <-ticker.C:
// Run key eviction for each database that has volatile keys.
wg := sync.WaitGroup{}
- for database, _ := range echovault.keysWithExpiry.keys {
+ for database, _ := range sugarDB.keysWithExpiry.keys {
wg.Add(1)
ctx := context.WithValue(context.Background(), "Database", database)
go func(ctx context.Context, wg *sync.WaitGroup) {
- if err := echovault.evictKeysWithExpiredTTL(ctx); err != nil {
+ if err := sugarDB.evictKeysWithExpiredTTL(ctx); err != nil {
log.Printf("evict with ttl: %v\n", err)
}
wg.Done()
}(ctx, &wg)
}
wg.Wait()
- case <-echovault.stopTTL:
+ case <-sugarDB.stopTTL:
break
}
}
}()
}
- if echovault.config.TLS && len(echovault.config.CertKeyPairs) <= 0 {
+ if sugarDB.config.TLS && len(sugarDB.config.CertKeyPairs) <= 0 {
return nil, errors.New("must provide certificate and key file paths for TLS mode")
}
- if echovault.isInCluster() {
+ if sugarDB.isInCluster() {
// Initialise raft and memberlist
- echovault.raft.RaftInit(echovault.context)
- echovault.memberList.MemberListInit(echovault.context)
+ sugarDB.raft.RaftInit(sugarDB.context)
+ sugarDB.memberList.MemberListInit(sugarDB.context)
// Initialise caches
- echovault.initialiseCaches()
+ sugarDB.initialiseCaches()
}
- if !echovault.isInCluster() {
- echovault.initialiseCaches()
+ if !sugarDB.isInCluster() {
+ sugarDB.initialiseCaches()
// Restore from AOF by default if it's enabled
- if echovault.config.RestoreAOF {
- err := echovault.aofEngine.Restore()
+ if sugarDB.config.RestoreAOF {
+ err := sugarDB.aofEngine.Restore()
if err != nil {
log.Println(err)
}
}
// Restore from snapshot if snapshot restore is enabled and AOF restore is disabled
- if echovault.config.RestoreSnapshot && !echovault.config.RestoreAOF {
- err := echovault.snapshotEngine.Restore()
+ if sugarDB.config.RestoreSnapshot && !sugarDB.config.RestoreAOF {
+ err := sugarDB.snapshotEngine.Restore()
if err != nil {
log.Println(err)
}
}
}
- return echovault, nil
+ return sugarDB, nil
}
-func (server *EchoVault) startTCP() {
+func (server *SugarDB) startTCP() {
conf := server.config
listenConfig := net.ListenConfig{
@@ -473,7 +473,7 @@ func (server *EchoVault) startTCP() {
}
}
-func (server *EchoVault) handleConnection(conn net.Conn) {
+func (server *SugarDB) handleConnection(conn net.Conn) {
// If ACL module is loaded, register the connection with the ACL
if server.acl != nil {
server.acl.RegisterConnection(&conn)
@@ -561,17 +561,17 @@ func (server *EchoVault) handleConnection(conn net.Conn) {
}
}
-// Start starts the EchoVault instance's TCP listener.
+// Start starts the SugarDB 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.
+// You can still use command functions like echovault.Set if you're embedding SugarDB in your application.
// However, if you'd like to also accept TCP request on the same instance, you must call this function.
-func (server *EchoVault) Start() {
+func (server *SugarDB) Start() {
server.startTCP()
}
// takeSnapshot triggers a snapshot when called.
-func (server *EchoVault) takeSnapshot() error {
+func (server *SugarDB) takeSnapshot() error {
if server.snapshotInProgress.Load() {
return errors.New("snapshot already in progress")
}
@@ -593,33 +593,33 @@ func (server *EchoVault) takeSnapshot() error {
return nil
}
-func (server *EchoVault) startSnapshot() {
+func (server *SugarDB) startSnapshot() {
server.snapshotInProgress.Store(true)
}
-func (server *EchoVault) finishSnapshot() {
+func (server *SugarDB) finishSnapshot() {
server.snapshotInProgress.Store(false)
}
-func (server *EchoVault) setLatestSnapshot(msec int64) {
+func (server *SugarDB) setLatestSnapshot(msec int64) {
server.latestSnapshotMilliseconds.Store(msec)
}
// getLatestSnapshotTime returns the latest snapshot time in unix epoch milliseconds.
-func (server *EchoVault) getLatestSnapshotTime() int64 {
+func (server *SugarDB) getLatestSnapshotTime() int64 {
return server.latestSnapshotMilliseconds.Load()
}
-func (server *EchoVault) startRewriteAOF() {
+func (server *SugarDB) startRewriteAOF() {
server.rewriteAOFInProgress.Store(true)
}
-func (server *EchoVault) finishRewriteAOF() {
+func (server *SugarDB) finishRewriteAOF() {
server.rewriteAOFInProgress.Store(false)
}
// rewriteAOF triggers an AOF compaction when running in standalone mode.
-func (server *EchoVault) rewriteAOF() error {
+func (server *SugarDB) rewriteAOF() error {
if server.rewriteAOFInProgress.Load() {
return errors.New("aof rewrite in progress")
}
@@ -629,9 +629,9 @@ func (server *EchoVault) rewriteAOF() error {
return nil
}
-// ShutDown gracefully shuts down the EchoVault instance.
+// ShutDown gracefully shuts down the SugarDB instance.
// This function shuts down the memberlist and raft layers.
-func (server *EchoVault) ShutDown() {
+func (server *SugarDB) ShutDown() {
if server.listener.Load() != nil {
go func() { server.quit <- struct{}{} }()
go func() { server.stopTTL <- struct{}{} }()
@@ -649,7 +649,7 @@ func (server *EchoVault) ShutDown() {
}
}
-func (server *EchoVault) initialiseCaches() {
+func (server *SugarDB) initialiseCaches() {
// Set up LFU cache.
server.lfuCache = struct {
mutex *sync.Mutex
diff --git a/echovault/echovault_test.go b/sugardb/sugardb_test.go
similarity index 96%
rename from echovault/echovault_test.go
rename to sugardb/sugardb_test.go
index 3ca1a76..ba39d61 100644
--- a/echovault/echovault_test.go
+++ b/sugardb/sugardb_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package echovault
+package sugardb
import (
"bufio"
@@ -20,10 +20,10 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
- "github.com/echovault/echovault/internal"
- "github.com/echovault/echovault/internal/clock"
- "github.com/echovault/echovault/internal/config"
- "github.com/echovault/echovault/internal/constants"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/clock"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
"github.com/go-test/deep"
"github.com/tidwall/resp"
"io"
@@ -48,7 +48,7 @@ type ClientServerPair struct {
joinAddr string
raw net.Conn
client *resp.Conn
- server *EchoVault
+ server *SugarDB
}
var bindLock sync.Mutex
@@ -80,7 +80,7 @@ func setupServer(
joinAddr string,
port,
discoveryPort int,
-) (*EchoVault, error) {
+) (*SugarDB, error) {
conf := DefaultConfig()
conf.DataDir = dataDir
conf.ForwardCommand = forwardCommand
@@ -92,7 +92,7 @@ func setupServer(
conf.BootstrapCluster = bootstrapCluster
conf.EvictionPolicy = constants.NoEviction
- return NewEchoVault(
+ return NewSugarDB(
WithContext(context.Background()),
WithConfig(conf),
)
@@ -604,7 +604,7 @@ func Test_Cluster(t *testing.T) {
t.Run("Test_GetServerInfo", func(t *testing.T) {
nodeInfo := []internal.ServerInfo{
{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: nodes[0].serverId,
Mode: "cluster",
@@ -612,7 +612,7 @@ func Test_Cluster(t *testing.T) {
Modules: nodes[0].server.ListModules(),
},
{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: nodes[1].serverId,
Mode: "cluster",
@@ -620,7 +620,7 @@ func Test_Cluster(t *testing.T) {
Modules: nodes[1].server.ListModules(),
},
{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: nodes[2].serverId,
Mode: "cluster",
@@ -628,7 +628,7 @@ func Test_Cluster(t *testing.T) {
Modules: nodes[2].server.ListModules(),
},
{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: nodes[3].serverId,
Mode: "cluster",
@@ -636,7 +636,7 @@ func Test_Cluster(t *testing.T) {
Modules: nodes[3].server.ListModules(),
},
{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: nodes[4].serverId,
Mode: "cluster",
@@ -660,7 +660,7 @@ func Test_Standalone(t *testing.T) {
return
}
- mockServer, err := NewEchoVault(
+ mockServer, err := NewSugarDB(
WithConfig(config.Config{
BindAddr: "localhost",
Port: uint16(port),
@@ -732,7 +732,7 @@ func Test_Standalone(t *testing.T) {
},
}
- server, err := NewEchoVault(WithConfig(conf))
+ server, err := NewSugarDB(WithConfig(conf))
if err != nil {
t.Error(err)
return
@@ -837,7 +837,7 @@ func Test_Standalone(t *testing.T) {
},
}
- server, err := NewEchoVault(WithConfig(conf))
+ server, err := NewSugarDB(WithConfig(conf))
if err != nil {
t.Error(err)
return
@@ -945,8 +945,8 @@ func Test_Standalone(t *testing.T) {
name string
dataDir string
values map[int]map[string]string
- snapshotFunc func(mockServer *EchoVault) error
- lastSaveFunc func(mockServer *EchoVault) (int, error)
+ snapshotFunc func(mockServer *SugarDB) error
+ lastSaveFunc func(mockServer *SugarDB) (int, error)
wantLastSave int
}{
{
@@ -956,13 +956,13 @@ func Test_Standalone(t *testing.T) {
0: {"key5": "value-05", "key6": "value-06", "key7": "value-07", "key8": "value-08"},
1: {"key5": "value-15", "key6": "value-16", "key7": "value-17", "key8": "value-18"},
},
- snapshotFunc: func(mockServer *EchoVault) error {
+ snapshotFunc: func(mockServer *SugarDB) error {
if _, err := mockServer.Save(); err != nil {
return err
}
return nil
},
- lastSaveFunc: func(mockServer *EchoVault) (int, error) {
+ lastSaveFunc: func(mockServer *SugarDB) (int, error) {
return mockServer.LastSave()
},
wantLastSave: int(clock.NewClock().Now().UnixMilli()),
@@ -985,7 +985,7 @@ func Test_Standalone(t *testing.T) {
conf.Port = uint16(port)
conf.RestoreSnapshot = true
- mockServer, err := NewEchoVault(WithConfig(conf))
+ mockServer, err := NewSugarDB(WithConfig(conf))
if err != nil {
t.Error(err)
return
@@ -1017,7 +1017,7 @@ func Test_Standalone(t *testing.T) {
ticker.Stop()
// Restart server with the same config. This should restore the snapshot
- mockServer, err = NewEchoVault(WithConfig(conf))
+ mockServer, err = NewSugarDB(WithConfig(conf))
if err != nil {
t.Error(err)
return
@@ -1093,7 +1093,7 @@ func Test_Standalone(t *testing.T) {
conf.DataDir = dataDir
conf.AOFSyncStrategy = "always"
- mockServer, err := NewEchoVault(WithConfig(conf))
+ mockServer, err := NewSugarDB(WithConfig(conf))
if err != nil {
t.Error(err)
return
@@ -1127,11 +1127,11 @@ func Test_Standalone(t *testing.T) {
// Yield
<-ticker.C
- // Shutdown the EchoVault instance
+ // Shutdown the SugarDB instance
mockServer.ShutDown()
- // Start another instance of EchoVault
- mockServer, err = NewEchoVault(WithConfig(conf))
+ // Start another instance of SugarDB
+ mockServer, err = NewSugarDB(WithConfig(conf))
if err != nil {
t.Error(err)
return
@@ -1157,7 +1157,7 @@ func Test_Standalone(t *testing.T) {
t.Run("Test_GetServerInfo", func(t *testing.T) {
wantInfo := internal.ServerInfo{
- Server: "echovault",
+ Server: "sugardb",
Version: constants.Version,
Id: mockServer.config.ServerID,
Mode: "standalone",
diff --git a/sugardb/test_helpers.go b/sugardb/test_helpers.go
new file mode 100644
index 0000000..052dbde
--- /dev/null
+++ b/sugardb/test_helpers.go
@@ -0,0 +1,39 @@
+package sugardb
+
+import (
+ "context"
+ "github.com/echovault/sugardb/internal"
+ "github.com/echovault/sugardb/internal/config"
+ "github.com/echovault/sugardb/internal/constants"
+)
+
+func createSugarDB() *SugarDB {
+ ev, _ := NewSugarDB(
+ WithConfig(config.Config{
+ DataDir: "",
+ EvictionPolicy: constants.NoEviction,
+ }),
+ )
+ return ev
+}
+
+func createSugarDBWithConfig(conf config.Config) *SugarDB {
+ ev, _ := NewSugarDB(
+ WithConfig(conf),
+ )
+ return ev
+}
+
+func presetValue(server *SugarDB, ctx context.Context, key string, value interface{}) error {
+ ctx = context.WithValue(ctx, "Database", 0)
+ if err := server.setValues(ctx, map[string]interface{}{key: value}); err != nil {
+ return err
+ }
+ return nil
+}
+
+func presetKeyData(server *SugarDB, ctx context.Context, key string, data internal.KeyData) {
+ ctx = context.WithValue(ctx, "Database", 0)
+ _ = server.setValues(ctx, map[string]interface{}{key: data.Value})
+ server.setExpiry(ctx, key, data.ExpireAt, false)
+}
diff --git a/windows_test_env/docker-compose.yaml b/windows_test_env/docker-compose.yaml
index ee2a43f..3f928d8 100644
--- a/windows_test_env/docker-compose.yaml
+++ b/windows_test_env/docker-compose.yaml
@@ -4,7 +4,7 @@ services:
build:
context: ..
dockerfile: windows_test_env/Dockerfile
- container_name: EchoVault_win_test_env
+ container_name: sugardb_win_test_env
stdin_open: true
tty: true