Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1020 Migrate SADD, SREM, SCARD, SMEMBERS command to store_eval #1068

Merged
merged 44 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9ede787
initial commit
sahoss Oct 11, 2024
fba9506
fix tests
sahoss Oct 11, 2024
29f0396
add comments
sahoss Oct 11, 2024
848d1f6
Merge branch 'DiceDB:master' into sadd-command-migration
sahoss Oct 13, 2024
2452a72
code review suggestions
sahoss Oct 13, 2024
98278d0
migrate srem
sahoss Oct 13, 2024
3e9a5c2
Merge branch 'DiceDB:master' into sadd-command-migration
sahoss Oct 13, 2024
ed3576f
migrate scard
sahoss Oct 13, 2024
e8c9772
migrate smembers
sahoss Oct 13, 2024
f1a030c
Merge branch 'master' of sahoss:sahoss/dice into sadd-command-migration
sahoss Oct 15, 2024
0015e5d
lint
sahoss Oct 15, 2024
6905e6b
add comment back
sahoss Oct 15, 2024
4a30ffb
add comment back
sahoss Oct 15, 2024
0af629f
merge master
sahoss Oct 15, 2024
e77feab
add unit test for sadd
sahoss Oct 15, 2024
af774c9
add srem unit test
sahoss Oct 16, 2024
b6c11d1
unit test scard
sahoss Oct 16, 2024
adec65b
Merge branch 'master' into sadd-command-migration
sahoss Oct 16, 2024
21233c1
unit test smembers
sahoss Oct 16, 2024
ed858e4
Merge branch 'master' into sadd-command-migration
sahoss Oct 20, 2024
e90d07e
commit
sahoss Oct 20, 2024
d8a502d
migrate integ tests
sahoss Oct 20, 2024
fcb713c
fix test
sahoss Oct 20, 2024
40a4fa4
Merge branch 'master' into sadd-command-migration
sahoss Oct 22, 2024
bd29a02
fix missing import
sahoss Oct 22, 2024
849e698
lint
sahoss Oct 22, 2024
b11def2
Update internal/eval/store_eval.go
sahoss Oct 22, 2024
037ec10
Update internal/eval/store_eval.go
sahoss Oct 22, 2024
052051a
fix failing test
sahoss Oct 24, 2024
b3baf98
Merge branch 'master' into sadd-command-migration
sahoss Oct 24, 2024
94768bb
fix
sahoss Oct 24, 2024
b1e422f
Merge branch 'master' into sadd-command-migration
sahoss Oct 28, 2024
ebd9e63
fix
sahoss Oct 28, 2024
0f02583
Merge branch 'master' into sadd-command-migration
sahoss Oct 28, 2024
b0c0256
fix failing test
sahoss Oct 30, 2024
e397ab5
Merge branch 'master' into sadd-command-migration
sahoss Oct 30, 2024
9187b7c
fix
sahoss Oct 30, 2024
636a78e
Merge branch 'master' into sadd-command-migration
apoorvyadav1111 Nov 5, 2024
577c815
Merge branch 'master' into sadd-command-migration
sahoss Nov 6, 2024
ac792a4
merge
sahoss Nov 6, 2024
411a818
fix
sahoss Nov 6, 2024
3ef322e
fix
sahoss Nov 6, 2024
d7f8870
Update deque_test.go fix for assert function
apoorvyadav1111 Nov 6, 2024
184170d
Update deque_test.go
apoorvyadav1111 Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 0 additions & 109 deletions integration_tests/commands/async/set_data_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,115 +36,6 @@ func TestSetDataCommand(t *testing.T) {
assertType []string
delay []time.Duration
}{
// SADD
{
name: "SADD Simple Value",
cmd: []string{"SADD foo bar", "SMEMBERS foo"},
expected: []interface{}{int64(1), []any{"bar"}},
assertType: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "SADD Multiple Values",
cmd: []string{"SADD foo bar", "SADD foo baz", "SMEMBERS foo"},
expected: []interface{}{int64(1), int64(1), []any{"bar", "baz"}},
assertType: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "SADD Duplicate Values",
cmd: []string{"SADD foo bar", "SADD foo bar", "SMEMBERS foo"},
expected: []interface{}{int64(1), int64(0), []any{"bar"}},
assertType: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "SADD Wrong Key Value Type",
cmd: []string{"SET foo bar", "SADD foo baz"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
assertType: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "SADD Multiple add and multiple kind of values",
cmd: []string{"SADD foo bar", "SADD foo baz", "SADD foo 1", "SMEMBERS foo"},
expected: []interface{}{int64(1), int64(1), int64(1), []any{"bar", "baz", "1"}},
assertType: []string{"equal", "equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0, 0},
},
// SCARD
{
name: "SADD & SCARD",
cmd: []string{"SADD foo bar", "SADD foo baz", "SCARD foo"},
expected: []interface{}{int64(1), int64(1), int64(2)},
assertType: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "SADD & CARD with non existing key",
cmd: []string{"SADD foo bar", "SADD foo baz", "SCARD bar"},
expected: []interface{}{int64(1), int64(1), int64(0)},
assertType: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "SADD & SCARD with wrong key type",
cmd: []string{"SET foo bar", "SCARD foo"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
assertType: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
// SMEMBERS
{
name: "SADD & SMEMBERS",
cmd: []string{"SADD foo bar", "SADD foo baz", "SMEMBERS foo"},
expected: []interface{}{int64(1), int64(1), []any{"bar", "baz"}},
assertType: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "SADD & SMEMBERS with non existing key",
cmd: []string{"SMEMBERS foo"},
expected: []interface{}{[]any{}},
assertType: []string{"equal"},
delay: []time.Duration{0},
},
{
name: "SADD & SMEMBERS with wrong key type",
cmd: []string{"SET foo bar", "SMEMBERS foo"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
assertType: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
// SREM
{
name: "SADD & SREM",
cmd: []string{"SADD foo bar", "SADD foo baz", "SREM foo bar", "SMEMBERS foo"},
expected: []interface{}{int64(1), int64(1), int64(1), []any{"baz"}},
assertType: []string{"equal", "equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0, 0},
},
{
name: "SADD & SREM with non existing key",
cmd: []string{"SREM foo bar"},
expected: []interface{}{int64(0)},
assertType: []string{"equal"},
delay: []time.Duration{0},
},
{
name: "SADD & SREM with wrong key type",
cmd: []string{"SET foo bar", "SREM foo bar"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
assertType: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "SADD & SREM with non existing value",
cmd: []string{"SADD foo bar baz bax", "SMEMBERS foo", "SREM foo bat", "SMEMBERS foo"},
expected: []interface{}{int64(3), []any{"bar", "baz", "bax"}, int64(0), []any{"bar", "baz", "bax"}},
assertType: []string{"equal", "equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0, 0},
},
sahoss marked this conversation as resolved.
Show resolved Hide resolved
// SADD & SDIFF
{
name: "SADD & SDIFF",
Expand Down
164 changes: 164 additions & 0 deletions integration_tests/commands/resp/set_data_cmd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package resp

import (
sahoss marked this conversation as resolved.
Show resolved Hide resolved
"gotest.tools/v3/assert"
apoorvyadav1111 marked this conversation as resolved.
Show resolved Hide resolved
"sort"
"testing"
"time"
)

func CustomDeepEqual(t *testing.T, a, b interface{}) {
if a == nil || b == nil {
assert.DeepEqual(t, a, b)
}

switch a.(type) {
case []any:
sort.Slice(a.([]any), func(i, j int) bool {
return a.([]any)[i].(string) < a.([]any)[j].(string)
})
sort.Slice(b.([]any), func(i, j int) bool {
return b.([]any)[i].(string) < b.([]any)[j].(string)
})
}

assert.DeepEqual(t, a, b)
}

func TestSetDataCommand(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()

testCases := []struct {
name string
cmd []string
expected []interface{}
assertType []string
delay []time.Duration
}{
// SADD
{
name: "SADD Simple Value",
cmd: []string{"SADD foo bar", "SMEMBERS foo"},
expected: []interface{}{int64(1), []any{"bar"}},
assertType: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "SADD Multiple Values",
cmd: []string{"SADD foo bar", "SADD foo baz", "SMEMBERS foo"},
expected: []interface{}{int64(1), int64(1), []any{"bar", "baz"}},
assertType: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "SADD Duplicate Values",
cmd: []string{"SADD foo bar", "SADD foo bar", "SMEMBERS foo"},
expected: []interface{}{int64(1), int64(0), []any{"bar"}},
assertType: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "SADD Wrong Key Value Type",
cmd: []string{"SET foo bar", "SADD foo baz"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
assertType: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "SADD Multiple add and multiple kind of values",
cmd: []string{"SADD foo bar", "SADD foo baz", "SADD foo 1", "SMEMBERS foo"},
expected: []interface{}{int64(1), int64(1), int64(1), []any{"bar", "baz", "1"}},
assertType: []string{"equal", "equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0, 0},
},
// SCARD
{
name: "SADD & SCARD",
cmd: []string{"SADD foo bar", "SADD foo baz", "SCARD foo"},
expected: []interface{}{int64(1), int64(1), int64(2)},
assertType: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "SADD & CARD with non existing key",
cmd: []string{"SADD foo bar", "SADD foo baz", "SCARD bar"},
expected: []interface{}{int64(1), int64(1), int64(0)},
assertType: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "SADD & SCARD with wrong key type",
cmd: []string{"SET foo bar", "SCARD foo"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
assertType: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
// SMEMBERS
{
name: "SADD & SMEMBERS",
cmd: []string{"SADD foo bar", "SADD foo baz", "SMEMBERS foo"},
expected: []interface{}{int64(1), int64(1), []any{"bar", "baz"}},
assertType: []string{"equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0},
},
{
name: "SADD & SMEMBERS with non existing key",
cmd: []string{"SMEMBERS foo"},
expected: []interface{}{[]any{}},
assertType: []string{"equal"},
delay: []time.Duration{0},
},
{
name: "SADD & SMEMBERS with wrong key type",
cmd: []string{"SET foo bar", "SMEMBERS foo"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
assertType: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
// SREM
{
name: "SADD & SREM",
cmd: []string{"SADD foo bar", "SADD foo baz", "SREM foo bar", "SMEMBERS foo"},
expected: []interface{}{int64(1), int64(1), int64(1), []any{"baz"}},
assertType: []string{"equal", "equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0, 0},
},
{
name: "SADD & SREM with non existing key",
cmd: []string{"SREM foo bar"},
expected: []interface{}{int64(0)},
assertType: []string{"equal"},
delay: []time.Duration{0},
},
{
name: "SADD & SREM with wrong key type",
cmd: []string{"SET foo bar", "SREM foo bar"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
assertType: []string{"equal", "equal"},
delay: []time.Duration{0, 0},
},
{
name: "SADD & SREM with non existing value",
cmd: []string{"SADD foo bar baz bax", "SMEMBERS foo", "SREM foo bat", "SMEMBERS foo"},
expected: []interface{}{int64(3), []any{"bar", "baz", "bax"}, int64(0), []any{"bar", "baz", "bax"}},
assertType: []string{"equal", "equal", "equal", "equal"},
delay: []time.Duration{0, 0, 0, 0},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
FireCommand(conn, "DEL foo")
FireCommand(conn, "DEL foo2")
for i, cmd := range tc.cmd {
if tc.delay[i] > 0 {
time.Sleep(tc.delay[i])
}
result := FireCommand(conn, cmd)
CustomDeepEqual(t, result, tc.expected[i])
}
apoorvyadav1111 marked this conversation as resolved.
Show resolved Hide resolved
})
}

}
28 changes: 16 additions & 12 deletions internal/eval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,36 +922,40 @@ var (
Specified members that are already a member of this set are ignored
Non existing keys are treated as empty sets.
An error is returned when the value stored at key is not a set.`,
Eval: evalSADD,
Arity: -3,
KeySpecs: KeySpecs{BeginIndex: 1},
NewEval: evalSADD,
Arity: -3,
KeySpecs: KeySpecs{BeginIndex: 1},
IsMigrated: true,
}
smembersCmdMeta = DiceCmdMeta{
Name: "SMEMBERS",
Info: `SMEMBERS key
Returns all the members of the set value stored at key.`,
Eval: evalSMEMBERS,
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
IsMigrated: true,
NewEval: evalSMEMBERS,
}
sremCmdMeta = DiceCmdMeta{
Name: "SREM",
Info: `SREM key member [member ...]
Removes the specified members from the set stored at key.
Non existing keys are treated as empty sets.
An error is returned when the value stored at key is not a set.`,
Eval: evalSREM,
Arity: -3,
KeySpecs: KeySpecs{BeginIndex: 1},
Arity: -3,
KeySpecs: KeySpecs{BeginIndex: 1},
IsMigrated: true,
NewEval: evalSREM,
}
scardCmdMeta = DiceCmdMeta{
Name: "SCARD",
Info: `SCARD key
Returns the number of elements of the set stored at key.
An error is returned when the value stored at key is not a set.`,
Eval: evalSCARD,
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
IsMigrated: true,
NewEval: evalSCARD,
}
sdiffCmdMeta = DiceCmdMeta{
Name: "SDIFF",
Expand Down
3 changes: 2 additions & 1 deletion internal/eval/deque_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ func TestLRange(t *testing.T) {
tc.dq.LPush(i)
}
output, _ := tc.dq.LRange(tc.start, tc.stop)
assert.DeepEqual(t, output, tc.expectedOutput)
assert.ElementsMatch(t, output, tc.expectedOutput)

})
}
}
Expand Down
Loading