Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
iamskp11 committed Sep 18, 2024
2 parents 0cb0d31 + 9670a5a commit 9cd05ec
Show file tree
Hide file tree
Showing 33 changed files with 2,672 additions and 341 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/full-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.21.x"
go-version: "1.23.x"
- name: Install dependencies
run: go get .
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21 AS builder
FROM golang:1.23 AS builder
WORKDIR /dicedb
COPY go.mod go.sum ./
RUN go mod download -x
Expand Down
29 changes: 18 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@ const (
DefaultPort int = 7379
DefaultConfigName string = "dice.toml"
DefaultConfigFilePath string = "./"

EvictSimpleFirst = "simple-first"
EvictAllKeysRandom = "allkeys-random"
EvictAllKeysLRU = "allkeys-lru"
EvictAllKeysLFU = "allkeys-lfu"
)

var (
Host string = DefaultHost
Port int = DefaultPort

EnableHTTP bool = true
HTTPPort int = 8082
Host = DefaultHost
Port = DefaultPort

EnableHTTP = true
HTTPPort = 8082
// if RequirePass is set to an empty string, no authentication is required
RequirePass string = utils.EmptyStr
RequirePass = utils.EmptyStr

CustomConfigFilePath string = utils.EmptyStr
ConfigFileLocation string = utils.EmptyStr
CustomConfigFilePath = utils.EmptyStr
ConfigFileLocation = utils.EmptyStr

InitConfigCmd bool = false
InitConfigCmd = false
)

type Config struct {
Expand All @@ -53,6 +57,7 @@ type Config struct {
AOFFile string `mapstructure:"aoffile"`
PersistenceEnabled bool `mapstructure:"persistenceenabled"`
WriteAOFOnCleanup bool `mapstructure:"writeaofoncleanup"`
LFULogFactor int `mapstructure:"lfulogfactor"`
} `mapstructure:"server"`
Auth struct {
UserName string `mapstructure:"username"`
Expand Down Expand Up @@ -82,6 +87,7 @@ var defaultConfig = Config{
AOFFile string `mapstructure:"aoffile"`
PersistenceEnabled bool `mapstructure:"persistenceenabled"`
WriteAOFOnCleanup bool `mapstructure:"writeaofoncleanup"`
LFULogFactor int `mapstructure:"lfulogfactor"`
}{
Addr: DefaultHost,
Port: DefaultPort,
Expand All @@ -92,12 +98,13 @@ var defaultConfig = Config{
MultiplexerPollTimeout: 100 * time.Millisecond,
MaxClients: 20000,
MaxMemory: 0,
EvictionPolicy: "allkeys-lru",
EvictionPolicy: EvictAllKeysLFU,
EvictionRatio: 0.40,
KeysLimit: 10000,
AOFFile: "./dice-master.aof",
PersistenceEnabled: true,
WriteAOFOnCleanup: false,
WriteAOFOnCleanup: true,
LFULogFactor: 10,
},
Auth: struct {
UserName string `mapstructure:"username"`
Expand Down
2 changes: 1 addition & 1 deletion examples/leaderboard-go/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21 as builder
FROM golang:1.23 as builder
WORKDIR /app

COPY go.mod go.sum ./
Expand Down
1 change: 0 additions & 1 deletion examples/leaderboard-go/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
services:
dicedb:
image: dicedb/dicedb:0.0.2
platform: linux/amd64
ports:
- "7379:7379"

Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/dicedb/dice

go 1.21.0

toolchain go1.23.0
go 1.23.0

require gotest.tools/v3 v3.5.1

Expand Down Expand Up @@ -55,8 +53,9 @@ require (
github.com/cockroachdb/swiss v0.0.0-20240612210725-f4de07ae6964
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13
github.com/dicedb/go-dice v0.0.0-20240820180649-d97f15fca831
github.com/ohler55/ojg v1.23.0
github.com/ohler55/ojg v1.24.0
github.com/pelletier/go-toml/v2 v2.2.3
github.com/rs/xid v1.6.0
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/twmb/murmur3 v1.1.8
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/ohler55/ojg v1.23.0 h1:xjJasLaKf4dKkyJq0CNXQMRdL7F1172tms885aPKcS0=
github.com/ohler55/ojg v1.23.0/go.mod h1:gQhDVpQLqrmnd2eqGAvJtn+NfKoYJbe/A4Sj3/Vro4o=
github.com/ohler55/ojg v1.24.0 h1:y2AVez6fPTszK/jPhaAYMCAzAoSleConMqSDD5wJKJg=
github.com/ohler55/ojg v1.24.0/go.mod h1:gQhDVpQLqrmnd2eqGAvJtn+NfKoYJbe/A4Sj3/Vro4o=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -82,6 +82,8 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/commands/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/dicedb/dice/testutils"
testifyAssert "github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
)

Expand Down Expand Up @@ -83,7 +84,7 @@ func TestCopy(t *testing.T) {
// else compare the values as is.
// This is to handle cases where the expected value is a json string with a different key order.
if resOk && expOk && testutils.IsJSONResponse(resStr) && testutils.IsJSONResponse(expStr) {
testutils.AssertJSONEqual(t, expStr, resStr)
testifyAssert.JSONEq(t, expStr, resStr)
} else {
assert.Equal(t, tc.expected[i], result, "Value mismatch for cmd %s", cmd)
}
Expand Down
125 changes: 109 additions & 16 deletions integration_tests/commands/incr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math"
"testing"
"time"

"github.com/dicedb/dice/internal/server/utils"
"gotest.tools/v3/assert"
Expand All @@ -18,7 +19,7 @@ func TestINCR(t *testing.T) {
commands []struct {
op string
key string
val int64
val interface{}
expectedErr string
}
}{
Expand All @@ -27,32 +28,122 @@ func TestINCR(t *testing.T) {
commands: []struct {
op string
key string
val int64
val interface{}
expectedErr string
}{
{"s", "key1", 0, utils.EmptyStr},
{"i", "key1", 1, utils.EmptyStr},
{"i", "key1", 2, utils.EmptyStr},
{"i", "key2", 1, utils.EmptyStr},
{"g", "key1", 2, utils.EmptyStr},
{"g", "key2", 1, utils.EmptyStr},
{"s", "key3", math.MaxInt64 - 1, utils.EmptyStr},
{"i", "key3", math.MaxInt64, utils.EmptyStr},
{"i", "key3", math.MaxInt64, "ERR value is out of range"},
{"s", "key1", int64(0), utils.EmptyStr},
{"i", "key1", int64(1), utils.EmptyStr},
{"i", "key1", int64(2), utils.EmptyStr},
{"i", "key2", int64(1), utils.EmptyStr},
{"g", "key1", int64(2), utils.EmptyStr},
{"g", "key2", int64(1), utils.EmptyStr},
},
},
{
name: "Increment to and from max int64",
commands: []struct {
op string
key string
val interface{}
expectedErr string
}{
{"s", "max_int", int64(math.MaxInt64 - 1), utils.EmptyStr},
{"i", "max_int", int64(math.MaxInt64), utils.EmptyStr},
{"i", "max_int", nil, "ERR value is out of range"},
{"s", "max_int", int64(math.MaxInt64), utils.EmptyStr},
{"i", "max_int", nil, "ERR value is out of range"},
},
},
{
name: "Increment from min int64",
commands: []struct {
op string
key string
val interface{}
expectedErr string
}{
{"s", "min_int", int64(math.MinInt64), utils.EmptyStr},
{"i", "min_int", int64(math.MinInt64 + 1), utils.EmptyStr},
{"i", "min_int", int64(math.MinInt64 + 2), utils.EmptyStr},
},
},
{
name: "Increment non-integer values",
commands: []struct {
op string
key string
val interface{}
expectedErr string
}{
{"s", "float_key", "3.14", utils.EmptyStr},
{"i", "float_key", nil, "ERR WRONGTYPE Operation against a key holding the wrong kind of value"},
{"s", "string_key", "hello", utils.EmptyStr},
{"i", "string_key", nil, "ERR WRONGTYPE Operation against a key holding the wrong kind of value"},
{"s", "bool_key", "true", utils.EmptyStr},
{"i", "bool_key", nil, "ERR WRONGTYPE Operation against a key holding the wrong kind of value"},
},
},
{
name: "Increment non-existent key",
commands: []struct {
op string
key string
val interface{}
expectedErr string
}{
{"i", "non_existent", int64(1), utils.EmptyStr},
{"g", "non_existent", int64(1), utils.EmptyStr},
{"i", "non_existent", int64(2), utils.EmptyStr},
},
},
{
name: "Increment string representing integers",
commands: []struct {
op string
key string
val interface{}
expectedErr string
}{
{"s", "str_int1", "42", utils.EmptyStr},
{"i", "str_int1", int64(43), utils.EmptyStr},
{"s", "str_int2", "-10", utils.EmptyStr},
{"i", "str_int2", int64(-9), utils.EmptyStr},
{"s", "str_int3", "0", utils.EmptyStr},
{"i", "str_int3", int64(1), utils.EmptyStr},
},
},
{
name: "Increment with expiry",
commands: []struct {
op string
key string
val interface{}
expectedErr string
}{
{"se", "expiry_key", int64(0), utils.EmptyStr},
{"i", "expiry_key", int64(1), utils.EmptyStr},
{"i", "expiry_key", int64(2), utils.EmptyStr},
{"w", "expiry_key", nil, utils.EmptyStr},
{"i", "expiry_key", int64(1), utils.EmptyStr},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// deleteTestKeys([]string{"key1", "key2"}, store)
FireCommand(conn, "DEL key1")
FireCommand(conn, "DEL key2")
// Clean up keys before each test case
keys := []string{"key1", "key2", "max_int", "min_int", "float_key", "string_key", "bool_key",
"non_existent", "str_int1", "str_int2", "str_int3", "expiry_key"}
for _, key := range keys {
FireCommand(conn, fmt.Sprintf("DEL %s", key))
}

for _, cmd := range tc.commands {
switch cmd.op {
case "s":
FireCommand(conn, fmt.Sprintf("SET %s %d", cmd.key, cmd.val))
FireCommand(conn, fmt.Sprintf("SET %s %v", cmd.key, cmd.val))
case "se":
FireCommand(conn, fmt.Sprintf("SET %s %v EX 1", cmd.key, cmd.val))
case "i":
result := FireCommand(conn, fmt.Sprintf("INCR %s", cmd.key))
switch v := result.(type) {
Expand All @@ -64,8 +155,10 @@ func TestINCR(t *testing.T) {
case "g":
result := FireCommand(conn, fmt.Sprintf("GET %s", cmd.key))
assert.Equal(t, cmd.val, result)
case "w":
time.Sleep(1100 * time.Millisecond)
}
}
})
}
}
}
64 changes: 64 additions & 0 deletions integration_tests/commands/json_arrpop_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package commands

import (
"testing"

"github.com/dicedb/dice/testutils"
testifyAssert "github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
)

func TestJSONARRPOP(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
FireCommand(conn, "DEL key")

arrayAtRoot := `[0,1,2,3]`
nestedArray := `{"a":2,"b":[0,1,2,3]}`

testCases := []struct {
name string
commands []string
expected []interface{}
assert_type []string
jsonResp []bool
nestedArray bool
path string
}{
{
name: "update array at root path",
commands: []string{"json.set key $ " + arrayAtRoot, "json.arrpop key $ 2", "json.get key"},
expected: []interface{}{"OK", int64(2), "[0,1,3]"},
assert_type: []string{"equal", "equal", "deep_equal"},
},
{
name: "update nested array",
commands: []string{"json.set key $ " + nestedArray, "json.arrpop key $.b 2", "json.get key"},
expected: []interface{}{"OK", []interface{}{int64(2)}, `{"a":2,"b":[0,1,3]}`},
assert_type: []string{"equal", "deep_equal", "na"},
},
}

for _, tcase := range testCases {
t.Run(tcase.name, func(t *testing.T) {
for i := 0; i < len(tcase.commands); i++ {
cmd := tcase.commands[i]
out := tcase.expected[i]
result := FireCommand(conn, cmd)

jsonResult, isString := result.(string)

if isString && testutils.IsJSONResponse(jsonResult) {
testifyAssert.JSONEq(t, out.(string), jsonResult)
continue
}

if tcase.assert_type[i] == "equal" {
assert.Equal(t, out, result)
} else if tcase.assert_type[i] == "deep_equal" {
assert.Assert(t, arraysArePermutations(out.([]interface{}), result.([]interface{})))
}
}
})
}
}
Loading

0 comments on commit 9cd05ec

Please sign in to comment.