before_code stringlengths 30 149k | reviewer_comment stringlengths 16 20.6k | after_code stringlengths 30 163k | diff_context stringlengths 0 22.4k | file_path stringlengths 6 155 | comment_line int64 0 26 | language stringclasses 19
values | quality_score float64 0.07 1 | comment_type stringclasses 9
values | comment_length int64 16 20.6k | before_lines int64 2 4.61k | after_lines int64 2 4.4k | is_negative bool 2
classes | pr_title stringlengths 7 140 | pr_number int64 18 61.2k | repo_name stringclasses 29
values | repo_stars int64 321 56k | repo_language stringclasses 14
values | reviewer_username stringclasses 378
values | author_username stringclasses 739
values | user stringlengths 361 200k | assistant stringlengths 16 20.6k | system stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
expected: "WRONGTYPE Operation against a key holding the wrong kind of value",
},
{
name: "Set Empty JSON Object",
setCmd: `JSON.SET empty $ {}`,
getCmd: `JSON.GET empty`,
expected: `{}`,
},
{
name: "Set Empty JSON Array",
setCmd: `JSON.SET emptyArray $ []`,
getCmd: `JSON... | Add a new test function that validates error messages we are getting with the unsupported JSONPath patterns that you have mentioned in the PR description.
This would allow us to easily test if those patterns can be supported using some other library in the future. | },
{
name: "Set Empty JSON Object",
setCmd: `JSON.SET empty $ {}`,
getCmd: `JSON.GET empty`,
expected: `{}`,
},
{
name: "Set Empty JSON Array",
setCmd: `JSON.SET emptyArray $ []`,
getCmd: `JSON.GET emptyArray`,
expected: `[]`,
},
{
name: "Set JSON with Unicode"... | @@ -112,6 +115,42 @@ func TestJSONOperations(t *testing.T) {
getCmd: `JSON.GET escaped`,
expected: escapedCharsJSON,
},
+ { | tests/json_test.go | 26 | Go | 0.571 | suggestion | 265 | 51 | 51 | false | #166: Adds JSONPath Support | 235 | DiceDB/dice | 10,326 | C | JyotinderSingh | Maveric-k07 | Review this pull request change.
Language: Go
File: tests/json_test.go
PR Title: #166: Adds JSONPath Support
BEFORE CODE: expected: "WRONGTYPE Operation against a key holding the wrong kind of value",
},
{
name: "Set Empty JSON Object",
setCmd: `JSON.SET empty $ {}`,
getCmd: `JSON.GET empty`... | Add a new test function that validates error messages we are getting with the unsupported JSONPath patterns that you have mentioned in the PR description.
This would allow us to easily test if those patterns can be supported using some other library in the future. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// args must contain key and value.
// args can also contain multiple options -
//
// EX or ex which will set the expiry time(in secs) for the key
// PX or px which will set the expiry time(in milliseconds) for the key
//
// Returns encoded error response if at least a <key, value> pair is not part of args
// Returns e... | nit: This is a nice catch.
I was thinking if we can make the code a little more readable.
For example, we can have a exDurationState type as below with initial value set to `Uninitialized`. The rest of the logic remains the same. i.e. we change the value to Initialized when the first time exDurationMs is set. For ... |
if len(args) == 0 {
b = Encode("PONG", true)
} else {
b = Encode(args[0], false)
}
return b
}
// evalAUTH returns with an encoded "OK" if the user is authenticated
// If the user is not authenticated, it returns with an encoded error message
func evalAUTH(args []string, c *Client) []byte {
var (
b []byt... | @@ -77,6 +79,9 @@ func evalSET(args []string) []byte {
for i := 2; i < len(args); i++ {
switch args[i] {
case "EX", "ex":
+ if exDurationMs != -1 { | core/eval.go | 26 | Go | 1 | question | 506 | 51 | 51 | false | adding px option for SET command | 236 | DiceDB/dice | 10,326 | C | soumya-codes | SyedMa3 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: adding px option for SET command
BEFORE CODE: // args must contain key and value.
// args can also contain multiple options -
//
// EX or ex which will set the expiry time(in secs) for the key
// PX or px which will set the expiry time(in mi... | nit: This is a nice catch.
I was thinking if we can make the code a little more readable.
For example, we can have a exDurationState type as below with initial value set to `Uninitialized`. The rest of the logic remains the same. i.e. we change the value to Initialized when the first time exDurationMs is set. For ... | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
for i := 2; i < len(args); i++ {
switch args[i] {
case "EX", "ex":
if exDurationMs != -1 {
return Encode(errors.New("ERR syntax error"), false)
}
i++
if i == len(args) {
return Encode(errors.New("ERR syntax error"), false)
}
exDurationSec, err := strconv.ParseInt(args[i], 10, 64)
if e... | 1. It appears REDIS returns a different error if the expiry time is set to a value `<= 0`. Can you please check the same?
```
redis:6379> set a B PX -1
(error) ERR invalid expire time in 'set' command
redis:6379> set a B EX -1
(error) ERR invalid expire time in 'set' command
```
2. Can we directly assign the o... | if len(args) == 1 {
if err = c.Session.Validate(DefaultUserName, args[0]); err != nil {
log.Println("AUTH failed: ", err)
return Encode(errors.New("AUTH failed"), false)
}
return RESP_OK
}
if len(args) == 2 {
if err = c.Session.Validate(args[0], args[1]); err != nil {
log.Println("AUTH failed: ", e... | @@ -87,6 +92,20 @@ func evalSET(args []string) []byte {
return Encode(errors.New("ERR value is not an integer or out of range"), false)
}
exDurationMs = exDurationSec * 1000
+ case "PX", "px":
+ if exDurationMs != -1 {
+ return Encode(errors.New("ERR syntax error"), false)
+ }
+ i++
+ if i == l... | core/eval.go | 26 | Go | 0.929 | question | 367 | 51 | 51 | false | adding px option for SET command | 236 | DiceDB/dice | 10,326 | C | soumya-codes | SyedMa3 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: adding px option for SET command
BEFORE CODE: for i := 2; i < len(args); i++ {
switch args[i] {
case "EX", "ex":
if exDurationMs != -1 {
return Encode(errors.New("ERR syntax error"), false)
}
i++
if i == len(args) {
... | 1. It appears REDIS returns a different error if the expiry time is set to a value `<= 0`. Can you please check the same?
```
redis:6379> set a B PX -1
(error) ERR invalid expire time in 'set' command
redis:6379> set a B EX -1
(error) ERR invalid expire time in 'set' command
```
2. Can we directly assign the o... | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
import (
"errors"
"testing"
"github.com/dicedb/dice/testutils"
"gotest.tools/v3/assert"
)
func TestEvalSET(t *testing.T) {
tests := []struct {
name string
args []string
want []byte
}{
{
name: "sanity check",
args: testutils.ParseCommand("SET k v")[1:],
want: RESP_OK,
},
{
n... | These tests have been recently updated. Please consolidate your tests against [https://github.com/DiceDB/dice/blob/f4b56e52b0ba5a13ac43ffe2f1e8bc259813dbb7/core/eval_test.go#L25](this) | package core
import (
"strconv"
"testing"
"time"
"gotest.tools/v3/assert"
)
type testCase struct {
input []string
output []byte
}
func TestEval(t *testing.T) {
testCases := map[string]func(*testing.T){
"SET": testEvalSET,
}
for name, testFunc := range testCases {
t.Run(name, testFunc)
}
}
func test... | @@ -0,0 +1,50 @@
+package core
+
+import (
+ "errors"
+ "testing"
+
+ "github.com/dicedb/dice/testutils"
+ "gotest.tools/v3/assert"
+)
+
+func TestEvalSET(t *testing.T) { | core/eval_test.go | 11 | Go | 0.357 | suggestion | 185 | 36 | 36 | false | adding px option for SET command | 236 | DiceDB/dice | 10,326 | C | soumya-codes | SyedMa3 | Review this pull request change.
Language: Go
File: core/eval_test.go
PR Title: adding px option for SET command
BEFORE CODE: package core
import (
"errors"
"testing"
"github.com/dicedb/dice/testutils"
"gotest.tools/v3/assert"
)
func TestEvalSET(t *testing.T) {
tests := []struct {
name string
args []str... | These tests have been recently updated. Please consolidate your tests against [https://github.com/DiceDB/dice/blob/f4b56e52b0ba5a13ac43ffe2f1e8bc259813dbb7/core/eval_test.go#L25](this) | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
if i == len(args) {
return Encode(errors.New("ERR syntax error"), false)
}
exDurationSec, err := strconv.ParseInt(args[i], 10, 64)
if err != nil {
return Encode(errors.New("ERR value is not an integer or out of range"), false)
}
if exDurationSec < 0 {
return Encode(errors.New("ERR invalid... | Should it be `<= 0` instead?
```
redis:6379> set a B PX 0
(error) ERR invalid expire time in 'set' command
redis:6379> set a B EX 0
(error) ERR invalid expire time in 'set' command
``` | if err = c.Session.Validate(args[0], args[1]); err != nil {
log.Println("AUTH failed: ", err)
return Encode(errors.New("AUTH failed"), false)
}
return RESP_OK
}
return b
}
// evalSET puts a new <key, value> pair in db as in the args
// args must contain key and value.
// args can also contain multiple o... | @@ -89,8 +93,27 @@ func evalSET(args []string) []byte {
if err != nil {
return Encode(errors.New("ERR value is not an integer or out of range"), false)
}
+ if exDurationSec < 0 {
+ return Encode(errors.New("ERR invalid expire time in 'set' command"), false)
+ }
exDurationMs = exDurationSec * 100... | core/eval.go | 26 | Go | 0.929 | suggestion | 190 | 51 | 51 | false | adding px option for SET command | 236 | DiceDB/dice | 10,326 | C | soumya-codes | SyedMa3 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: adding px option for SET command
BEFORE CODE: if i == len(args) {
return Encode(errors.New("ERR syntax error"), false)
}
exDurationSec, err := strconv.ParseInt(args[i], 10, 64)
if err != nil {
return Encode(errors.New("E... | Should it be `<= 0` instead?
```
redis:6379> set a B PX 0
(error) ERR invalid expire time in 'set' command
redis:6379> set a B EX 0
(error) ERR invalid expire time in 'set' command
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
var key, value string
var exDurationMs int64 = -1
key, value = args[0], args[1]
oType, oEnc := deduceTypeEncoding(value)
for i := 2; i < len(args); i++ {
switch args[i] {
case "EX", "ex":
if exDurationMs != -1 {
return Encode(errors.New("ERR syntax error"), false)
}
i++
if i == len(args) {
... | The PX and EX options are same except for the conversion part in EX and the code is part of the same file. Should we combine them? | if len(args) < 1 || len(args) > 2 {
return Encode(errors.New("ERR wrong number of arguments for 'AUTH' command"), false)
}
if len(args) == 1 {
if err = c.Session.Validate(DefaultUserName, args[0]); err != nil {
log.Println("AUTH failed: ", err)
return Encode(errors.New("AUTH failed"), false)
}
return ... | @@ -89,8 +93,27 @@ func evalSET(args []string) []byte {
if err != nil {
return Encode(errors.New("ERR value is not an integer or out of range"), false)
}
+ if exDurationSec < 0 {
+ return Encode(errors.New("ERR invalid expire time in 'set' command"), false)
+ }
exDurationMs = exDurationSec * 100... | core/eval.go | 26 | Go | 0.429 | question | 130 | 51 | 51 | false | adding px option for SET command | 236 | DiceDB/dice | 10,326 | C | soumya-codes | SyedMa3 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: adding px option for SET command
BEFORE CODE: var key, value string
var exDurationMs int64 = -1
key, value = args[0], args[1]
oType, oEnc := deduceTypeEncoding(value)
for i := 2; i < len(args); i++ {
switch args[i] {
case "EX", "e... | The PX and EX options are same except for the conversion part in EX and the code is part of the same file. Should we combine them? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
for i := 2; i < len(args); i++ {
switch args[i] {
case "EX", "ex":
i++
if i == len(args) {
return Encode(errors.New("ERR syntax error"), false)
}
exDurationSec, err := strconv.ParseInt(args[i], 10, 64)
if err != nil {
return Encode(errors.New("ERR value is not an integer or out of range"),... | Not a requirement for this PR, but it may be a good time to start consolidating/reusing the error messages for easier maintainability and ensuring that the error messages are exactly as that of REDIS.
@arpitbbhayani @JyotinderSingh if you guys feel there is a need i can open a PR. | key, value = args[0], args[1]
oType, oEnc := deduceTypeEncoding(value)
for i := 2; i < len(args); i++ {
switch args[i] {
case "EX", "ex":
i++
if i == len(args) {
return Encode(errors.New("ERR syntax error"), false)
}
exDurationSec, err := strconv.ParseInt(args[i], 10, 64)
if err != nil {
... | @@ -87,6 +89,29 @@ func evalSET(args []string) []byte {
return Encode(errors.New("ERR value is not an integer or out of range"), false)
}
exDurationMs = exDurationSec * 1000
+
+ case "PXAT", "pxat":
+ i++
+ if i == len(args) {
+ return Encode(errors.New("ERR syntax error"), false)
+ }
+
+ exDur... | core/eval.go | 26 | Go | 0.571 | suggestion | 284 | 51 | 51 | false | feat: [GH-203] Add support for PXAT in SET command | 237 | DiceDB/dice | 10,326 | C | soumya-codes | lucifercr07 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: feat: [GH-203] Add support for PXAT in SET command
BEFORE CODE:
for i := 2; i < len(args); i++ {
switch args[i] {
case "EX", "ex":
i++
if i == len(args) {
return Encode(errors.New("ERR syntax error"), false)
}
exDurati... | Not a requirement for this PR, but it may be a good time to start consolidating/reusing the error messages for easier maintainability and ensuring that the error messages are exactly as that of REDIS.
@arpitbbhayani @JyotinderSingh if you guys feel there is a need i can open a PR. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
exDurationSec, err := strconv.ParseInt(args[i], 10, 64)
if err != nil {
return Encode(errors.New("ERR value is not an integer or out of range"), false)
}
exDurationMs = exDurationSec * 1000
case "XX", "xx":
// Get the key from the hash table
obj := Get(key)
// if key does not exist, return R... | nit: Instead of creating a new object with expiry time set to zero, should we delete the key instead? How is it handled in Redis? | }
exDurationSec, err := strconv.ParseInt(args[i], 10, 64)
if err != nil {
return Encode(errors.New("ERR value is not an integer or out of range"), false)
}
exDurationMs = exDurationSec * 1000
case "PXAT", "pxat":
i++
if i == len(args) {
return Encode(errors.New("ERR syntax error"), fals... | @@ -87,6 +89,29 @@ func evalSET(args []string) []byte {
return Encode(errors.New("ERR value is not an integer or out of range"), false)
}
exDurationMs = exDurationSec * 1000
+
+ case "PXAT", "pxat":
+ i++
+ if i == len(args) {
+ return Encode(errors.New("ERR syntax error"), false)
+ }
+
+ exDur... | core/eval.go | 26 | Go | 0.571 | question | 129 | 51 | 51 | false | feat: [GH-203] Add support for PXAT in SET command | 237 | DiceDB/dice | 10,326 | C | soumya-codes | lucifercr07 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: feat: [GH-203] Add support for PXAT in SET command
BEFORE CODE: exDurationSec, err := strconv.ParseInt(args[i], 10, 64)
if err != nil {
return Encode(errors.New("ERR value is not an integer or out of range"), false)
}
exDurat... | nit: Instead of creating a new object with expiry time set to zero, should we delete the key instead? How is it handled in Redis? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
import (
"path"
"sync"
"time"
"unsafe"
"github.com/dicedb/dice/config"
)
type WatchEvent struct {
Key string
Operation string
Value *Obj
}
var (
store map[unsafe.Pointer]*Obj
expires map[*Obj]uint64 // Does not need to be thread-safe as it is only accessed by a single thread.
... | The function is very similar to `Get` except that we don't update the `v.LastAccessedAt` in this function. I would prefer to add `touch/no touch` feature to the existing `Get` function by adding another parameter to the `Get` function or via variadic arguments.
@soumya-codes what do you think? | clients, _ := WatchList.LoadOrStore(query, &sync.Map{})
clients.(*sync.Map).Store(clientFd, struct{}{})
}
// Function to remove a watcher from a query.
func RemoveWatcher(query DSQLQuery, clientFd int) {
if clients, ok := WatchList.Load(query); ok {
clients.(*sync.Map).Delete(clientFd)
// If no more clients for... | @@ -197,3 +197,28 @@ func countClients(clients *sync.Map) int {
})
return count
}
+
+func GetNoTouch(k string) *Obj { | core/store.go | 26 | Go | 0.643 | question | 295 | 225 | 45 | false | New feature: EXISTS k1, k2..Kn | 245 | DiceDB/dice | 10,326 | C | gsarmaonline | apoorvyadav1111 | Review this pull request change.
Language: Go
File: core/store.go
PR Title: New feature: EXISTS k1, k2..Kn
BEFORE CODE: package core
import (
"path"
"sync"
"time"
"unsafe"
"github.com/dicedb/dice/config"
)
type WatchEvent struct {
Key string
Operation string
Value *Obj
}
var (
store map[u... | The function is very similar to `Get` except that we don't update the `v.LastAccessedAt` in this function. I would prefer to add `touch/no touch` feature to the existing `Get` function by adding another parameter to the `Get` function or via variadic arguments.
@soumya-codes what do you think? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package tests
import (
"testing"
"time"
"gotest.tools/v3/assert"
)
func TestExists(t *testing.T) {
conn := getLocalConnection()
testCases := []struct {
command []string
expected []interface{}
delay []time.Duration
}{
{
command: []string{"SET key value", "EXISTS key", "EXISTS key2", "EXISTS key ... | Let's break down the function into multiple lines for better readability. | package tests
import (
"testing"
"time"
"gotest.tools/v3/assert"
)
func TestExists(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
testCases := []struct {
name string
command []string
expected []interface{}
delay []time.Duration
}{
{
name: "Test EXISTS command",
co... | @@ -0,0 +1,33 @@
+package tests
+
+import (
+ "testing"
+ "time"
+
+ "gotest.tools/v3/assert"
+)
+
+func TestExists(t *testing.T) {
+ conn := getLocalConnection()
+ testCases := []struct {
+ command []string
+ expected []interface{}
+ delay []time.Duration
+ }{
+ {
+ command: []string{"SET key value", "EXIST... | tests/exists_test.go | 18 | Go | 0.286 | suggestion | 73 | 34 | 43 | false | New feature: EXISTS k1, k2..Kn | 245 | DiceDB/dice | 10,326 | C | gsarmaonline | apoorvyadav1111 | Review this pull request change.
Language: Go
File: tests/exists_test.go
PR Title: New feature: EXISTS k1, k2..Kn
BEFORE CODE: package tests
import (
"testing"
"time"
"gotest.tools/v3/assert"
)
func TestExists(t *testing.T) {
conn := getLocalConnection()
testCases := []struct {
command []string
expecte... | Let's break down the function into multiple lines for better readability. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package tests
import (
"testing"
"time"
"gotest.tools/v3/assert"
)
func TestExists(t *testing.T) {
conn := getLocalConnection()
testCases := []struct {
command []string
expected []interface{}
delay []time.Duration
}{
{
command: []string{"SET key value", "EXISTS key", "EXISTS key2", "EXISTS key ... | We should add a test case where we are calling `Exists` on an expired key. | package tests
import (
"testing"
"time"
"gotest.tools/v3/assert"
)
func TestExists(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
testCases := []struct {
name string
command []string
expected []interface{}
delay []time.Duration
}{
{
name: "Test EXISTS command",
co... | @@ -0,0 +1,33 @@
+package tests
+
+import (
+ "testing"
+ "time"
+
+ "gotest.tools/v3/assert"
+)
+
+func TestExists(t *testing.T) { | tests/exists_test.go | 10 | Go | 0.429 | suggestion | 74 | 34 | 35 | false | New feature: EXISTS k1, k2..Kn | 245 | DiceDB/dice | 10,326 | C | gsarmaonline | apoorvyadav1111 | Review this pull request change.
Language: Go
File: tests/exists_test.go
PR Title: New feature: EXISTS k1, k2..Kn
BEFORE CODE: package tests
import (
"testing"
"time"
"gotest.tools/v3/assert"
)
func TestExists(t *testing.T) {
conn := getLocalConnection()
testCases := []struct {
command []string
expecte... | We should add a test case where we are calling `Exists` on an expired key. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
if exDurationUnixMs < 0 {
return Encode(errors.New("ERR invalid expire time in 'set' command"), false)
}
exDurationMs = exDurationUnixMs - time.Now().UnixMilli()
// If the expiry time is in the past, set exDurationMs to 0
// This will be used to signal immediate expiration
if exDurationMs < 0 {
... | Can we implementation for EXAT/PXAT inline with EX/PX, i.e. consolidate the code and handle validate that only one of the options among EXAT/PXAT/EX/PX is provided in input. If more than one of the options are provided we should return error.
I also have a minor suggestion to make the existing code a little more cl... |
if exDuration < 0 {
return Encode(errors.New("ERR invalid expire time in 'set' command"), false)
}
if arg == "EXAT" {
exDuration = exDuration * 1000
}
exDurationMs = exDuration - time.Now().UnixMilli()
// If the expiry time is in the past, set exDurationMs to 0
// This will be used to... | @@ -187,6 +187,23 @@ func evalSET(args []string) []byte {
if obj != nil {
return RESP_NIL
}
+ case "EXAT", "exat": | core/eval.go | 26 | Go | 0.786 | suggestion | 778 | 51 | 51 | false | FIX: Removed old cases -> Added EXAT + new tests | 247 | DiceDB/dice | 10,326 | C | soumya-codes | apoorvyadav1111 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: FIX: Removed old cases -> Added EXAT + new tests
BEFORE CODE: if exDurationUnixMs < 0 {
return Encode(errors.New("ERR invalid expire time in 'set' command"), false)
}
exDurationMs = exDurationUnixMs - time.Now().UnixMilli()
... | Can we implementation for EXAT/PXAT inline with EX/PX, i.e. consolidate the code and handle validate that only one of the options among EXAT/PXAT/EX/PX is provided in input. If more than one of the options are provided we should return error.
I also have a minor suggestion to make the existing code a little more cl... | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
expected: []interface{}{"OK", "v", "OK", "(nil)"},
},
{
name: "XX option",
commands: []string{"SET k v XX EX 1", "GET k", "SLEEP 2", "GET k", "SET k v XX EX 1", "GET k"},
expected: []interface{}{"(nil)", "(nil)", "OK", "(nil)", "(nil)", "(nil)"},
},
}
for _, tc := range testCases {
t.Run(tc.n... | Add test for the negative condition where user can provide `EXAT` and `PXAT` in the same command. | expected: []interface{}{"OK", "v", "OK", "(nil)"},
},
{
name: "XX option",
commands: []string{"SET k v XX EX 1", "GET k", "SLEEP 2", "GET k", "SET k v XX EX 1", "GET k"},
expected: []interface{}{"(nil)", "(nil)", "OK", "(nil)", "(nil)", "(nil)"},
},
}
for _, tc := range testCases {
t.Run(tc.n... | @@ -127,3 +127,18 @@ func TestSetWithOptions(t *testing.T) {
})
}
}
+
+func TestSetWithExat(t *testing.T) {
+ conn := getLocalConnection()
+ defer conn.Close()
+ Etime := strconv.FormatInt(time.Now().Unix()+10, 10)
+
+ assert.Equal(t, "OK", fireCommand(conn, "SET k v EXAT "+Etime), "Value mismatch for cmd SET k v... | tests/set_test.go | 26 | Go | 0.429 | suggestion | 97 | 35 | 51 | false | FIX: Removed old cases -> Added EXAT + new tests | 247 | DiceDB/dice | 10,326 | C | soumya-codes | apoorvyadav1111 | Review this pull request change.
Language: Go
File: tests/set_test.go
PR Title: FIX: Removed old cases -> Added EXAT + new tests
BEFORE CODE: expected: []interface{}{"OK", "v", "OK", "(nil)"},
},
{
name: "XX option",
commands: []string{"SET k v XX EX 1", "GET k", "SLEEP 2", "GET k", "SET k v XX EX ... | Add test for the negative condition where user can provide `EXAT` and `PXAT` in the same command. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package tests
import (
"strconv"
"testing"
"time"
"gotest.tools/v3/assert"
)
func TestSet(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
testCases := []struct {
name string
commands []string
expected []interface{}
}{
{
name: "Set and Get Simple Value",
commands: []stri... | nit: We can likely use smaller expiry time (and accordingly update the test case) so that the overall test runs faster :) | name: "EX option",
commands: []string{"SET k v EX 1", "GET k", "SLEEP 2", "GET k"},
expected: []interface{}{"OK", "v", "OK", "(nil)"},
},
{
name: "XX option",
commands: []string{"SET k v XX EX 1", "GET k", "SLEEP 2", "GET k", "SET k v XX EX 1", "GET k"},
expected: []interface{}{"(nil)", "(... | @@ -127,3 +127,38 @@ func TestSetWithOptions(t *testing.T) {
})
}
}
+
+func TestSetWithExat(t *testing.T) {
+ conn := getLocalConnection()
+ defer conn.Close()
+ Etime := strconv.FormatInt(time.Now().Unix()+10, 10) | tests/set_test.go | 26 | Go | 0.429 | nitpick | 121 | 130 | 51 | false | FIX: Removed old cases -> Added EXAT + new tests | 247 | DiceDB/dice | 10,326 | C | JyotinderSingh | apoorvyadav1111 | Review this pull request change.
Language: Go
File: tests/set_test.go
PR Title: FIX: Removed old cases -> Added EXAT + new tests
BEFORE CODE: package tests
import (
"strconv"
"testing"
"time"
"gotest.tools/v3/assert"
)
func TestSet(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
testCases... | nit: We can likely use smaller expiry time (and accordingly update the test case) so that the overall test runs faster :) | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
case "NX", "nx":
obj := Get(key)
if obj != nil {
return RESP_NIL
}
default:
return Encode(errors.New("ERR syntax error"), false)
}
}
// putting the k and value in a Hash Table
Put(key, NewObj(value, exDurationMs, oType, oEnc))
return RESP_OK
}
// evalMSET puts multiple <key, value> pairs in ... | nit: since there is no expiry, we can remove `expiry will be discarded` | // if key does not exist, return RESP encoded nil
if obj == nil {
return RESP_NIL
}
case "NX":
obj := Get(key)
if obj != nil {
return RESP_NIL
}
default:
return Encode(errors.New("ERR syntax error"), false)
}
}
// putting the k and value in a Hash Table
Put(key, NewObj(value, exDu... | @@ -197,6 +197,29 @@ func evalSET(args []string) []byte {
return RESP_OK
}
+// evalMSET puts multiple <key, value> pairs in db as in the args
+// args must contain key and value pairs.
+
+// Returns encoded error response if at least a <key, value> pair is not part of args
+// Returns encoded OK RESP once new entr... | core/eval.go | 26 | Go | 0.429 | nitpick | 71 | 51 | 51 | false | added mset command | 261 | DiceDB/dice | 10,326 | C | soumya-codes | SyedMa3 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: added mset command
BEFORE CODE: case "NX", "nx":
obj := Get(key)
if obj != nil {
return RESP_NIL
}
default:
return Encode(errors.New("ERR syntax error"), false)
}
}
// putting the k and value in a Hash Table
Put(key... | nit: since there is no expiry, we can remove `expiry will be discarded` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
return RESP_OK
}
// evalMSET puts multiple <key, value> pairs in db as in the args
// args must contain key and value pairs.
// Returns encoded error response if at least a <key, value> pair is not part of args
// Returns encoded OK RESP once new entries are added
// If the key already exists then the value will be ... | @soumya-codes do you think we should call `evalSET` instead of calling `Put` multiple times to the store directly? Using `evalSET` will ensure that any further changes to the `SET` command implementation would benefit this function as well. | }
// putting the k and value in a Hash Table
Put(key, NewObj(value, exDurationMs, oType, oEnc))
return RESP_OK
}
// evalMSET puts multiple <key, value> pairs in db as in the args
// MSET is atomic, so all given keys are set at once.
// args must contain key and value pairs.
// Returns encoded error response if a... | @@ -197,6 +197,29 @@ func evalSET(args []string) []byte {
return RESP_OK
}
+// evalMSET puts multiple <key, value> pairs in db as in the args
+// args must contain key and value pairs.
+
+// Returns encoded error response if at least a <key, value> pair is not part of args
+// Returns encoded OK RESP once new entr... | core/eval.go | 26 | Go | 0.643 | suggestion | 240 | 51 | 51 | false | added mset command | 261 | DiceDB/dice | 10,326 | C | gsarmaonline | SyedMa3 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: added mset command
BEFORE CODE: return RESP_OK
}
// evalMSET puts multiple <key, value> pairs in db as in the args
// args must contain key and value pairs.
// Returns encoded error response if at least a <key, value> pair is not part of ... | @soumya-codes do you think we should call `evalSET` instead of calling `Put` multiple times to the store directly? Using `evalSET` will ensure that any further changes to the `SET` command implementation would benefit this function as well. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
lastIdx = len(args) + keySpecs.LastKey
}
for i := keySpecs.BeginIndex; i <= lastIdx; i += step {
keys = append(keys, args[i])
}
return Encode(keys, false)
}
func evalRename(args []string) []byte {
if len(args) != 2 {
return Encode(errors.New("ERR wrong number of arguments for 'RENAME' command"), false)
}
... | ```suggestion
return Encode("ERR no such key", false)
``` | }
}
// initialize result with byteArray
operationResult := NewByteArray(len(result))
operationResult.data = result
operationResult.Length = int64(len(result))
// resize the byte array if necessary
operationResult.ResizeIfNecessary()
// create object related to result
operationResultObject := New... | @@ -1526,6 +1526,42 @@ func evalCommandGetKeys(args []string) []byte {
return Encode(keys, false)
}
+func evalRename(args []string) []byte {
+
+ if len(args) != 2 {
+ return Encode(errors.New("ERR wrong number of arguments for 'RENAME' command"), false)
+ }
+ sourceKey := args[0]
+ destKey := args[1]
+
+ //if Sou... | core/eval.go | 26 | Go | 0.571 | suggestion | 61 | 51 | 51 | false | #253: added RENAME Command | 262 | DiceDB/dice | 10,326 | C | JyotinderSingh | rkarthick15 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #253: added RENAME Command
BEFORE CODE: lastIdx = len(args) + keySpecs.LastKey
}
for i := keySpecs.BeginIndex; i <= lastIdx; i += step {
keys = append(keys, args[i])
}
return Encode(keys, false)
}
func evalRename(args []string) []by... | ```suggestion
return Encode("ERR no such key", false)
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
destKey := args[1]
//if Source and Destination Keys are same return RESP encoded ok
if sourceKey == destKey {
return RESP_OK
}
sourceObj := Get(sourceKey)
// if Source key does not exist, return RESP encoded nil
if sourceObj == nil {
return Encode("(error) ERR no such key", false)
}
destObj := Get(dest... | This operation needs to be atomic, which may not be easily possible in the current locking approach. Please add a TODO here so we can look at it later.
@soumya-codes I was wondering if you have any suggestions to handling such cases? | // store the result in destKey
Put(destKey, operationResultObject)
return Encode(len(result), true)
}
}
// evalCommand evaluates COMMAND <subcommand> command based on subcommand
// COUNT: return total count of commands in Dice.
func evalCommand(args []string) []byte {
if len(args) == 0 {
return Encode(error... | @@ -1526,6 +1526,42 @@ func evalCommandGetKeys(args []string) []byte {
return Encode(keys, false)
}
+func evalRename(args []string) []byte {
+
+ if len(args) != 2 {
+ return Encode(errors.New("ERR wrong number of arguments for 'RENAME' command"), false)
+ }
+ sourceKey := args[0]
+ destKey := args[1]
+
+ //if Sou... | core/eval.go | 26 | Go | 0.429 | question | 234 | 51 | 51 | false | #253: added RENAME Command | 262 | DiceDB/dice | 10,326 | C | JyotinderSingh | rkarthick15 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #253: added RENAME Command
BEFORE CODE: destKey := args[1]
//if Source and Destination Keys are same return RESP encoded ok
if sourceKey == destKey {
return RESP_OK
}
sourceObj := Get(sourceKey)
// if Source key does not exist, re... | This operation needs to be atomic, which may not be easily possible in the current locking approach. Please add a TODO here so we can look at it later.
@soumya-codes I was wondering if you have any suggestions to handling such cases? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package tests
import (
"testing"
"gotest.tools/v3/assert"
)
var renameKeysTestCases = []struct {
name string
inCmd []string
expected []interface{}
}{
{"Set key and Rename key", []string{"set sourceKey hello", "get sourceKey", "rename sourceKey destKey", "get destKey", "get sourceKey"}, []interface{}{"OK... | nit: please format it such that each test case is in its own line, it improves the readability. | package tests
import (
"testing"
"gotest.tools/v3/assert"
)
var renameKeysTestCases = []struct {
name string
inCmd []string
expected []interface{}
}{
{
name: "Set key and Rename key",
inCmd: []string{"set sourceKey hello", "get sourceKey", "rename sourceKey destKey", "get destKey", "get sourc... | @@ -0,0 +1,33 @@
+package tests
+
+import (
+ "testing"
+
+ "gotest.tools/v3/assert"
+)
+
+var renameKeysTestCases = []struct {
+ name string
+ inCmd []string
+ expected []interface{}
+}{
+ {"Set key and Rename key", []string{"set sourceKey hello", "get sourceKey", "rename sourceKey destKey", "get destKey", "get... | tests/command_rename_test.go | 18 | Go | 0.214 | nitpick | 95 | 34 | 43 | false | #253: added RENAME Command | 262 | DiceDB/dice | 10,326 | C | JyotinderSingh | rkarthick15 | Review this pull request change.
Language: Go
File: tests/command_rename_test.go
PR Title: #253: added RENAME Command
BEFORE CODE: package tests
import (
"testing"
"gotest.tools/v3/assert"
)
var renameKeysTestCases = []struct {
name string
inCmd []string
expected []interface{}
}{
{"Set key and Renam... | nit: please format it such that each test case is in its own line, it improves the readability. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core_test
import (
"fmt"
"strconv"
"testing"
"github.com/dicedb/dice/core"
"github.com/dicedb/dice/testutils"
)
func createAndPushKey(sr *core.StackRef, key string, value int, expDurationMs int64) {
obj := core.NewObj(value, expDurationMs, core.OBJ_TYPE_STRING, core.OBJ_ENCODING_INT)
core.Put(key, obj... | Rename this to CreateAndPushKeyToStack | package core_test
import (
"fmt"
"strconv"
"testing"
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/core"
"github.com/dicedb/dice/testutils"
)
func CreateAndPushKeyToStack(sr *core.StackRef, key string, value int, expDurationMs int64) {
obj := core.NewObj(value, expDurationMs, core.OBJ_TYPE_STRING, c... | @@ -1,12 +1,20 @@
package core_test
import (
+ "fmt"
+ "strconv"
"testing"
"github.com/dicedb/dice/core"
"github.com/dicedb/dice/testutils"
)
+func createAndPushKey(sr *core.StackRef, key string, value int, expDurationMs int64) { | core/stackref_test.go | 12 | Go | 0.143 | suggestion | 38 | 37 | 37 | false | #185: Added test cases for expired keys in StackRef.Pop() method | 273 | DiceDB/dice | 10,326 | C | JyotinderSingh | kushal0511-not | Review this pull request change.
Language: Go
File: core/stackref_test.go
PR Title: #185: Added test cases for expired keys in StackRef.Pop() method
BEFORE CODE: package core_test
import (
"fmt"
"strconv"
"testing"
"github.com/dicedb/dice/core"
"github.com/dicedb/dice/testutils"
)
func createAndPushKey(sr *... | Rename this to CreateAndPushKeyToStack | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
if key, err := sr2.Pop(); err != nil || int64(key.Obj.Value.(int)) != 20 {
t.Errorf("popping multiple expired keys followed by a non-expired key should work")
}
if _, err := sr2.Pop(); err != core.ErrStackEmpty {
t.Errorf("popping all expired keys till stack becomes empty should work")
}
}
func BenchmarkRemo... | Why are we only popping one key in the benchmark? |
if key, err := sr2.Pop(); err != nil || int64(key.Obj.Value.(int)) != 20 {
t.Errorf("popping multiple expired keys followed by a non-expired key should work")
}
if _, err := sr2.Pop(); err != core.ErrStackEmpty {
t.Errorf("popping all expired keys till stack becomes empty should work")
}
}
func BenchmarkRem... | @@ -55,4 +63,90 @@ func TestStackRef(t *testing.T) {
if !testutils.EqualInt64Slice(observedVals, expectedVals) {
t.Error("iterating through the stackref should return the elements in the order they were pushed. Expected:", expectedVals, ", got: ", observedVals)
}
+
+ sr2 := core.NewStackRef()
+ obj1 := core.NewO... | core/stackref_test.go | 26 | Go | 0.071 | question | 49 | 32 | 33 | false | #185: Added test cases for expired keys in StackRef.Pop() method | 273 | DiceDB/dice | 10,326 | C | JyotinderSingh | kushal0511-not | Review this pull request change.
Language: Go
File: core/stackref_test.go
PR Title: #185: Added test cases for expired keys in StackRef.Pop() method
BEFORE CODE: if key, err := sr2.Pop(); err != nil || int64(key.Obj.Value.(int)) != 20 {
t.Errorf("popping multiple expired keys followed by a non-expired key should... | Why are we only popping one key in the benchmark? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
observedVals = append(observedVals, int64(key.Obj.Value.(int)))
}
}
if !testutils.EqualInt64Slice(observedVals, expectedVals) {
t.Errorf("expected %v, got %v", expectedVals, observedVals)
}
if key, err := sr2.Pop(); err != nil || int64(key.Obj.Value.(int)) != 60 {
t.Errorf("popping an expired key followe... | Why are we populating the data here when the benchmark function is also adding more keys. | } else {
observedVals = append(observedVals, int64(key.Obj.Value.(int)))
}
}
if !testutils.EqualInt64Slice(observedVals, expectedVals) {
t.Errorf("expected %v, got %v", expectedVals, observedVals)
}
if key, err := sr2.Pop(); err != nil || int64(key.Obj.Value.(int)) != 60 {
t.Errorf("popping an expired ... | @@ -55,4 +63,90 @@ func TestStackRef(t *testing.T) {
if !testutils.EqualInt64Slice(observedVals, expectedVals) {
t.Error("iterating through the stackref should return the elements in the order they were pushed. Expected:", expectedVals, ", got: ", observedVals)
}
+
+ sr2 := core.NewStackRef()
+ obj1 := core.NewO... | core/stackref_test.go | 26 | Go | 0.214 | suggestion | 89 | 44 | 45 | false | #185: Added test cases for expired keys in StackRef.Pop() method | 273 | DiceDB/dice | 10,326 | C | JyotinderSingh | kushal0511-not | Review this pull request change.
Language: Go
File: core/stackref_test.go
PR Title: #185: Added test cases for expired keys in StackRef.Pop() method
BEFORE CODE: observedVals = append(observedVals, int64(key.Obj.Value.(int)))
}
}
if !testutils.EqualInt64Slice(observedVals, expectedVals) {
t.Errorf("expect... | Why are we populating the data here when the benchmark function is also adding more keys. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
if key, err := sr2.Pop(); err != nil || int64(key.Obj.Value.(int)) != 20 {
t.Errorf("popping multiple expired keys followed by a non-expired key should work")
}
if _, err := sr2.Pop(); err != core.ErrStackEmpty {
t.Errorf("popping all expired keys till stack becomes empty should work")
}
}
func BenchmarkRem... | Ideally we shouldn't ever hit the StackEmpty error, right? Since we only pop once we should pop the non-expired key.
In what case will we run into the ErrStackEmpty condition? |
if key, err := sr2.Pop(); err != nil || int64(key.Obj.Value.(int)) != 20 {
t.Errorf("popping multiple expired keys followed by a non-expired key should work")
}
if _, err := sr2.Pop(); err != core.ErrStackEmpty {
t.Errorf("popping all expired keys till stack becomes empty should work")
}
}
func BenchmarkRem... | @@ -55,4 +64,90 @@ func TestStackRef(t *testing.T) {
if !testutils.EqualInt64Slice(observedVals, expectedVals) {
t.Error("iterating through the stackref should return the elements in the order they were pushed. Expected:", expectedVals, ", got: ", observedVals)
}
+
+ sr2 := core.NewStackRef()
+ obj1 := core.NewO... | core/stackref_test.go | 26 | Go | 0.571 | question | 178 | 33 | 33 | false | #185: Added test cases for expired keys in StackRef.Pop() method | 273 | DiceDB/dice | 10,326 | C | JyotinderSingh | kushal0511-not | Review this pull request change.
Language: Go
File: core/stackref_test.go
PR Title: #185: Added test cases for expired keys in StackRef.Pop() method
BEFORE CODE:
if key, err := sr2.Pop(); err != nil || int64(key.Obj.Value.(int)) != 20 {
t.Errorf("popping multiple expired keys followed by a non-expired key shoul... | Ideally we shouldn't ever hit the StackEmpty error, right? Since we only pop once we should pop the non-expired key.
In what case will we run into the ErrStackEmpty condition? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
SameObjectErr = "ERR source and destination objects are the same"
OutOfRangeErr = "ERR index out of range"
NoScriptErr = "NOSCRIPT No matching script. Please use EVAL."
LoadingErr = "LOADING Redis is loading the dataset in memory"
SlowEvalErr = "BUSY Redis is busy running a script. You can only call SCRIPT ... | Instead of an additional field `encodedMessage` can we have a toEncodedMessage() method instead? | IntOrOutOfRangeErr = "value is not an integer or out of range"
ValOutOfRangeErr = "value is out of range"
ElementPeekErr = "number of elements to peek should be a positive number less than %d"
NoKeyErr = "no such key"
ErrDefault = "ERR %s"
)
type DiceError struct {
message error
}
func n... | @@ -0,0 +1,56 @@
+package DiceErrors
+
+import (
+ "fmt"
+ "strings"
+)
+
+const (
+ ErrArity = "ERR wrong number of arguments for '%s' command"
+ SyntaxErr = "ERR syntax error"
+ ExpiryErr = "ERR invalid expire time in '%s' command"
+ WrongTypeErr = "WRONGTYPE Operation against a key holding the wrong ki... | core/diceerrors/diceerrors.go | 26 | Go | 0.429 | question | 96 | 44 | 51 | false | #248: Standardize error messages across codebase | 288 | DiceDB/dice | 10,326 | C | soumya-codes | lucifercr07 | Review this pull request change.
Language: Go
File: core/diceerrors/diceerrors.go
PR Title: #248: Standardize error messages across codebase
BEFORE CODE: SameObjectErr = "ERR source and destination objects are the same"
OutOfRangeErr = "ERR index out of range"
NoScriptErr = "NOSCRIPT No matching script. Please... | Instead of an additional field `encodedMessage` can we have a toEncodedMessage() method instead? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
type DiceCmdMeta struct {
Name string
Info string
Eval func([]string) []byte
Arity int // number of arguments, it is possible to use -N to say >= N
KeySpecs
}
type KeySpecs struct {
BeginIndex int
Step int
LastKey int
}
const (
PING = "PING"
AUTH = "AUTH"
SET ... | I think we can avoid this atm. wdyt? The complexity of hardcoding the command is not much atm. wdyt? | package core
type DiceCmdMeta struct {
Name string
Info string
Eval func([]string, *Store) []byte
Arity int // number of arguments, it is possible to use -N to say >= N
KeySpecs
}
type KeySpecs struct {
BeginIndex int
Step int
LastKey int
}
var (
diceCmds = map[string]DiceCmdMeta{}
pingCmdMeta... | @@ -14,23 +14,77 @@ type KeySpecs struct {
LastKey int
}
+const (
+ PING = "PING" | core/commands.go | 18 | Go | 0.429 | performance | 100 | 43 | 43 | false | #248: Standardize error messages across codebase | 288 | DiceDB/dice | 10,326 | C | soumya-codes | lucifercr07 | Review this pull request change.
Language: Go
File: core/commands.go
PR Title: #248: Standardize error messages across codebase
BEFORE CODE: package core
type DiceCmdMeta struct {
Name string
Info string
Eval func([]string) []byte
Arity int // number of arguments, it is possible to use -N to say >= N
KeySp... | I think we can avoid this atm. wdyt? The complexity of hardcoding the command is not much atm. wdyt? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
SlowEvalErr = "BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE."
SlowScriptErr = "BUSY Redis is busy running a script. You can only call FUNCTION KILL or SHUTDOWN NOSAVE."
SlowModuleErr = "BUSY Redis is busy running a module command."
MasterDownErr = "MASTERDOWN Link with MAS... | unless we are using these methods outside of the package, let us have them scoped to the package. We need to enforce this across the project cc @JyotinderSingh | ErrDefault = "ERR %s"
)
type DiceError struct {
message error
}
func newDiceErr(message string) *DiceError {
return &DiceError{
message: errors.New(message),
}
}
func (d *DiceError) toEncodedMessage() []byte {
return []byte(fmt.Sprintf("-%s\r\n", d.message.Error()))
}
func NewErr(message string) erro... | @@ -0,0 +1,56 @@
+package DiceErrors
+
+import (
+ "fmt"
+ "strings"
+)
+
+const (
+ ErrArity = "ERR wrong number of arguments for '%s' command"
+ SyntaxErr = "ERR syntax error"
+ ExpiryErr = "ERR invalid expire time in '%s' command"
+ WrongTypeErr = "WRONGTYPE Operation against a key holding the wrong ki... | core/diceerrors/diceerrors.go | 26 | Go | 0.357 | suggestion | 160 | 40 | 50 | false | #248: Standardize error messages across codebase | 288 | DiceDB/dice | 10,326 | C | soumya-codes | lucifercr07 | Review this pull request change.
Language: Go
File: core/diceerrors/diceerrors.go
PR Title: #248: Standardize error messages across codebase
BEFORE CODE: SlowEvalErr = "BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE."
SlowScriptErr = "BUSY Redis is busy running a script. Y... | unless we are using these methods outside of the package, let us have them scoped to the package. We need to enforce this across the project cc @JyotinderSingh | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
import (
"fmt"
"hash"
"math"
"math/rand"
"strconv"
DiceErrors "github.com/dicedb/dice/core/diceerrors"
"github.com/dicedb/dice/internal/constants"
"github.com/twmb/murmur3"
)
const (
defaultErrorRate float64 = 0.01
defaultCapacity uint64 = 1024
)
var (
ln2 float64 = math.Log(2)
ln2P... | nit: the package alias seems redundant | package core
import (
"fmt"
"hash"
"math"
"math/rand"
"strconv"
"github.com/dicedb/dice/core/diceerrors"
"github.com/dicedb/dice/internal/constants"
"github.com/twmb/murmur3"
)
const (
defaultErrorRate float64 = 0.01
defaultCapacity uint64 = 1024
)
var (
ln2 float64 = math.Log(2)
ln2Power float64... | @@ -1,13 +1,14 @@
package core
import (
- "errors"
"fmt"
"hash"
"math"
"math/rand"
"strconv"
+ DiceErrors "github.com/dicedb/dice/core/diceerrors" | core/bloom.go | 10 | Go | 0.071 | nitpick | 38 | 35 | 35 | false | #248: Standardize error messages across codebase | 288 | DiceDB/dice | 10,326 | C | soumya-codes | lucifercr07 | Review this pull request change.
Language: Go
File: core/bloom.go
PR Title: #248: Standardize error messages across codebase
BEFORE CODE: package core
import (
"fmt"
"hash"
"math"
"math/rand"
"strconv"
DiceErrors "github.com/dicedb/dice/core/diceerrors"
"github.com/dicedb/dice/internal/constants"
"github... | nit: the package alias seems redundant | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
import (
"bytes"
"fmt"
"log"
"math"
"strconv"
"strings"
"syscall"
"time"
DiceErrors "github.com/dicedb/dice/core/diceerrors"
"github.com/bytedance/sonic"
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/core/bit"
"github.com/dicedb/dice/internal/constants"
"github.com/ohler55/ojg/j... | nit: the package alias seems redundant | package core
import (
"bytes"
"errors"
"fmt"
"math"
"strconv"
"strings"
"syscall"
"time"
"github.com/bytedance/sonic"
"github.com/charmbracelet/log"
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/core/bit"
"github.com/dicedb/dice/core/diceerrors"
"github.com/dicedb/dice/internal/constants"
"gi... | @@ -11,6 +10,8 @@ import (
"syscall"
"time"
+ DiceErrors "github.com/dicedb/dice/core/diceerrors" | core/eval.go | 13 | Go | 0.071 | nitpick | 38 | 38 | 38 | false | #248: Standardize error messages across codebase | 288 | DiceDB/dice | 10,326 | C | soumya-codes | lucifercr07 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #248: Standardize error messages across codebase
BEFORE CODE: package core
import (
"bytes"
"fmt"
"log"
"math"
"strconv"
"strings"
"syscall"
"time"
DiceErrors "github.com/dicedb/dice/core/diceerrors"
"github.com/bytedance/sonic"... | nit: the package alias seems redundant | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
if (arity < 0 && len(args) < -arity) ||
(arity >= 0 && len(args) != arity) {
return Encode(errors.New("ERR invalid number of arguments specified for command"), false)
}
keys := make([]string, 0)
step := max(keySpecs.Step, 1)
lastIdx := keySpecs.BeginIndex
if keySpecs.LastKey != 0 {
lastIdx = len(args) + key... | Preallocate the capacity here to the size of the values array. | if (arity < 0 && len(args) < -arity) ||
(arity >= 0 && len(args) != arity) {
return Encode(errors.New("ERR invalid number of arguments specified for command"), false)
}
keys := make([]string, 0)
step := max(keySpecs.Step, 1)
lastIdx := keySpecs.BeginIndex
if keySpecs.LastKey != 0 {
lastIdx = len(args) + key... | @@ -1584,10 +1583,29 @@ func evalCommandGetKeys(args []string) []byte {
for i := keySpecs.BeginIndex; i <= lastIdx; i += step {
keys = append(keys, args[i])
}
-
return Encode(keys, false)
}
+//The MGET command returns an array of RESP values corresponding to the provided keys.
+//For each key, if the key is... | core/eval.go | 26 | Go | 0.214 | performance | 62 | 51 | 51 | false | #251: Added support for MGET command. | 292 | DiceDB/dice | 10,326 | C | JyotinderSingh | chanducheryala | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #251: Added support for MGET command.
BEFORE CODE: if (arity < 0 && len(args) < -arity) ||
(arity >= 0 && len(args) != arity) {
return Encode(errors.New("ERR invalid number of arguments specified for command"), false)
}
keys := make([... | Preallocate the capacity here to the size of the values array. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
Del(k)
storeMutex.RLock()
keypoolMutex.RLock()
return nil
}
v.LastAccessedAt = getCurrentClock()
}
return v
}
func GetDel(k string) *Obj {
storeMutex.RLock()
defer storeMutex.RUnlock()
keypoolMutex.RLock()
defer keypoolMutex.RUnlock()
ptr, ok := keypool[k]
if !ok {
return nil
}
v := store[... | Releasing the lock here takes away the atomicity guarantee. A better way to do this might be to define a helper method which both GetDel and Del depend upon:
```go
// Helper function to delete an object and return it (if it existed)
func deleteAndGet(k string) *Obj {
storeMutex.Lock()
defer storeMutex.Unlo... | return delByPtr(ptr)
}, WithStoreLock(), WithKeypoolLock())
}
// List all keys in the store by given pattern
func Keys(p string) ([]string, error) {
var keys []string
var err error
withLocks(func() {
keys = make([]string, 0, len(keypool))
for k := range keypool {
if found, e := path.Match(p, k); e != nil... | @@ -151,6 +151,31 @@ func Get(k string) *Obj {
return v
}
+func GetDel(k string) *Obj {
+ storeMutex.RLock()
+ defer storeMutex.RUnlock()
+ keypoolMutex.RLock()
+ defer keypoolMutex.RUnlock()
+ ptr, ok := keypool[k]
+ if !ok {
+ return nil
+ }
+
+ v := store[ptr]
+ if v != nil {
+ expired := hasExpired(v)
+ key... | core/store.go | 26 | Go | 0.857 | refactor | 1,112 | 51 | 51 | false | #274: Added support for GETDEL command. | 293 | DiceDB/dice | 10,326 | C | JyotinderSingh | raghavbabbar | Review this pull request change.
Language: Go
File: core/store.go
PR Title: #274: Added support for GETDEL command.
BEFORE CODE: Del(k)
storeMutex.RLock()
keypoolMutex.RLock()
return nil
}
v.LastAccessedAt = getCurrentClock()
}
return v
}
func GetDel(k string) *Obj {
storeMutex.RLock()
defer st... | Releasing the lock here takes away the atomicity guarantee. A better way to do this might be to define a helper method which both GetDel and Del depend upon:
```go
// Helper function to delete an object and return it (if it existed)
func deleteAndGet(k string) *Obj {
storeMutex.Lock()
defer storeMutex.Unlo... | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
}{
{
name: "GetDel",
cmds: []string{"SET k v", "GETDEL k", "GETDEL k", "GET k"},
expect: []interface{}{"OK", "v", "(nil)", "(nil)"},
delays: []time.Duration{0, 0, 0, 0},
},
{
name: "GetDel with expiration, checking if key exist and is already expired, then it should return null",
cmds: ... | Please use shorter expiration times and delays (1-2 seconds), this will help the test suite run faster. | }{
{
name: "GetDel",
cmds: []string{"SET k v", "GETDEL k", "GETDEL k", "GET k"},
expect: []interface{}{"OK", "v", "(nil)", "(nil)"},
delays: []time.Duration{0, 0, 0, 0},
},
{
name: "GetDel with expiration, checking if key exist and is already expired, then it should return null",
cmds: ... | @@ -0,0 +1,59 @@
+package tests
+
+import (
+ "gotest.tools/v3/assert"
+ "testing"
+ "time"
+)
+
+func TestGetDel(t *testing.T) {
+ conn := getLocalConnection()
+ defer conn.Close()
+
+ testCases := []struct {
+ name string
+ cmds []string
+ expect []interface{}
+ delays []time.Duration
+ }{
+ {
+ name: "G... | tests/getdel_test.go | 26 | Go | 0.429 | suggestion | 103 | 43 | 43 | false | #274: Added support for GETDEL command. | 293 | DiceDB/dice | 10,326 | C | JyotinderSingh | raghavbabbar | Review this pull request change.
Language: Go
File: tests/getdel_test.go
PR Title: #274: Added support for GETDEL command.
BEFORE CODE: }{
{
name: "GetDel",
cmds: []string{"SET k v", "GETDEL k", "GETDEL k", "GET k"},
expect: []interface{}{"OK", "v", "(nil)", "(nil)"},
delays: []time.Duration{0, 0... | Please use shorter expiration times and delays (1-2 seconds), this will help the test suite run faster. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
args must contain key and value.
args can also contain multiple options -
EX or ex which will set the expiry time(in secs) for the key
Returns encoded error response if at least a <key, value> pair is not part of args
Returns encoded error response if expiry tme value in not integer
Returns encoded OK RESP ... | nit: Can you fix this indentation? | args must contain key and value.
args can also contain multiple options -
EX or ex which will set the expiry time(in secs) for the key
Returns encoded error response if at least a <key, value> pair is not part of args
Returns encoded error response if expiry tme value in not integer
Returns encoded OK RESP ... | @@ -53,6 +53,17 @@ var (
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
}
+ getDelCmdMeta = DiceCmdMeta{
+ Name: "GETDEL",
+ Info: `GETDEL returns the value for the queried key in args
+ The key should be the only param in args
+ If the key exists, it will be deleted before its value is returned. | core/commands.go | 26 | Go | 0.071 | question | 34 | 51 | 51 | false | #274: Added support for GETDEL command. | 293 | DiceDB/dice | 10,326 | C | gsarmaonline | raghavbabbar | Review this pull request change.
Language: Go
File: core/commands.go
PR Title: #274: Added support for GETDEL command.
BEFORE CODE: args must contain key and value.
args can also contain multiple options -
EX or ex which will set the expiry time(in secs) for the key
Returns encoded error response if at leas... | nit: Can you fix this indentation? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
return nil
}
return obj
}
func GetDel(k string) *Obj {
storeMutex.Lock()
defer storeMutex.Unlock()
keypoolMutex.Lock()
defer keypoolMutex.Unlock()
ptr, ok := keypool[k]
if !ok {
return nil
}
obj, exists := store[ptr]
if !exists {
return nil
}
expired := hasExpired(obj)
executeDelete(ptr, obj, k... | If both `Del` and `GetDel` call `WatchChannel <- WatchEvent{k, "GETDEL", obj}`, can we move this into the function and pass the type of operation being performed to `executeDelete` so that it can distinguish between the source of the event and pass it accordingly into the channel. | err = e
return
} else if found {
keys = append(keys, k)
}
}
}, WithStoreRLock(), WithKeypoolRLock())
return keys, err
}
// Function to add a new watcher to a query.
func AddWatcher(query DSQLQuery, clientFd int) {
clients, _ := WatchList.LoadOrStore(query, &sync.Map{})
clients.(*sync.Map).Stor... | @@ -160,6 +160,32 @@ func Get(k string) *Obj {
return obj
}
+func GetDel(k string) *Obj {
+ storeMutex.Lock()
+ defer storeMutex.Unlock()
+ keypoolMutex.Lock()
+ defer keypoolMutex.Unlock()
+
+ ptr, ok := keypool[k]
+ if !ok {
+ return nil
+ }
+
+ obj, exists := store[ptr]
+ if !exists {
+ return nil
+ }
+
+ exp... | core/store.go | 26 | Go | 0.786 | refactor | 281 | 51 | 51 | false | #274: Added support for GETDEL command. | 293 | DiceDB/dice | 10,326 | C | gsarmaonline | raghavbabbar | Review this pull request change.
Language: Go
File: core/store.go
PR Title: #274: Added support for GETDEL command.
BEFORE CODE: return nil
}
return obj
}
func GetDel(k string) *Obj {
storeMutex.Lock()
defer storeMutex.Unlock()
keypoolMutex.Lock()
defer keypoolMutex.Unlock()
ptr, ok := keypool[k]
if !o... | If both `Del` and `GetDel` call `WatchChannel <- WatchEvent{k, "GETDEL", obj}`, can we move this into the function and pass the type of operation being performed to `executeDelete` so that it can distinguish between the source of the event and pass it accordingly into the channel. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
}
// Helper function for Delete operations
func delOperation(k string) bool {
ptr, ok := keypool[k]
if !ok {
return false
}
if obj, ok := store[ptr]; ok {
if success := executeDelete(ptr, obj, k); success {
WatchChannel <- WatchEvent{k, "DEL", obj}
return true
}
}
return false
}
func executeDelete(... | @JyotinderSingh Do we need a lock for `KeyspaceStat`? It's being used without a lock in other places as well. | package core
import (
"path"
"sync"
"time"
"unsafe"
"github.com/dicedb/dice/config"
)
type WatchEvent struct {
Key string
Operation string
Value *Obj
}
var (
store map[unsafe.Pointer]*Obj
expires map[*Obj]uint64 // Does not need to be thread-safe as it is only accessed by a single thread.
... | @@ -315,17 +341,25 @@ func delOperation(k string) bool {
}
if obj, ok := store[ptr]; ok {
- delete(store, ptr)
- delete(expires, obj)
- delete(keypool, k)
- KeyspaceStat[0]["keys"]--
-
- WatchChannel <- WatchEvent{k, "DEL", obj}
- return true
+ if success := executeDelete(ptr, obj, k); success {
+ WatchC... | core/store.go | 26 | Go | 0.571 | suggestion | 109 | 46 | 331 | false | #274: Added support for GETDEL command. | 293 | DiceDB/dice | 10,326 | C | gsarmaonline | raghavbabbar | Review this pull request change.
Language: Go
File: core/store.go
PR Title: #274: Added support for GETDEL command.
BEFORE CODE: }
// Helper function for Delete operations
func delOperation(k string) bool {
ptr, ok := keypool[k]
if !ok {
return false
}
if obj, ok := store[ptr]; ok {
if success := executeD... | @JyotinderSingh Do we need a lock for `KeyspaceStat`? It's being used without a lock in other places as well. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
}
obj.LastAccessedAt = getCurrentClock()
ptr := ensureKeyInPool(k)
store[ptr] = obj
incrementKeyCount()
notifyWatchers(k, "SET", obj)
}
func Get(k string) *Obj {
return getHelper(k, true)
}
func GetDel(k string) *Obj {
var v *Obj
withLocks(func() {
ptr, ok := keypool[k]
if !ok {
return
}
v = st... | retaining `DEL` is fine as an operation name, the name of the operation should just signify the core operation that caused a change in the keyset - `DEL` is enough for that. | }
obj.LastAccessedAt = getCurrentClock()
ptr := ensureKeyInPool(k)
store[ptr] = obj
incrementKeyCount()
notifyWatchers(k, "SET", obj)
}
func Get(k string) *Obj {
return getHelper(k, true)
}
func GetDel(k string) *Obj {
var v *Obj
withLocks(func() {
ptr, ok := keypool[k]
if !ok {
return
}
v = st... | @@ -242,6 +242,26 @@ func Get(k string) *Obj {
return getHelper(k, true)
}
+func GetDel(k string) *Obj {
+ var v *Obj
+ withLocks(func() {
+ ptr, ok := keypool[k]
+ if !ok {
+ return
+ }
+
+ v = store[ptr]
+ if v != nil {
+ expired := hasExpired(v)
+ deleteKeyWithOperationName(k, ptr, v, "GETDEL") | core/store.go | 26 | Go | 0.571 | suggestion | 173 | 51 | 51 | false | #274: Added support for GETDEL command. | 293 | DiceDB/dice | 10,326 | C | JyotinderSingh | raghavbabbar | Review this pull request change.
Language: Go
File: core/store.go
PR Title: #274: Added support for GETDEL command.
BEFORE CODE: }
obj.LastAccessedAt = getCurrentClock()
ptr := ensureKeyInPool(k)
store[ptr] = obj
incrementKeyCount()
notifyWatchers(k, "SET", obj)
}
func Get(k string) *Obj {
return getHelpe... | retaining `DEL` is fine as an operation name, the name of the operation should just signify the core operation that caused a change in the keyset - `DEL` is enough for that. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
incrementKeyCount()
notifyWatchers(k, "SET", obj)
}
func Get(k string) *Obj {
return getHelper(k, true)
}
func GetDel(k string) *Obj {
var v *Obj
withLocks(func() {
ptr, ok := keypool[k]
if !ok {
return
}
v = store[ptr]
if v != nil {
expired := hasExpired(v)
deleteKeyWithOperationName(k, ptr... | Since there is a possibility of a write operation (Deletion), we should be taking Write locks instead of Read locks. |
incrementKeyCount()
notifyWatchers(k, "SET", obj)
}
func Get(k string) *Obj {
return getHelper(k, true)
}
func GetDel(k string) *Obj {
var v *Obj
withLocks(func() {
ptr, ok := keypool[k]
if !ok {
return
}
v = store[ptr]
if v != nil {
expired := hasExpired(v)
deleteKey(k, ptr, v)
if expire... | @@ -242,6 +242,26 @@ func Get(k string) *Obj {
return getHelper(k, true)
}
+func GetDel(k string) *Obj {
+ var v *Obj
+ withLocks(func() {
+ ptr, ok := keypool[k]
+ if !ok {
+ return
+ }
+
+ v = store[ptr]
+ if v != nil {
+ expired := hasExpired(v)
+ deleteKeyWithOperationName(k, ptr, v, "GETDEL")
+ i... | core/store.go | 26 | Go | 0.429 | suggestion | 116 | 51 | 51 | false | #274: Added support for GETDEL command. | 293 | DiceDB/dice | 10,326 | C | JyotinderSingh | raghavbabbar | Review this pull request change.
Language: Go
File: core/store.go
PR Title: #274: Added support for GETDEL command.
BEFORE CODE:
incrementKeyCount()
notifyWatchers(k, "SET", obj)
}
func Get(k string) *Obj {
return getHelper(k, true)
}
func GetDel(k string) *Obj {
var v *Obj
withLocks(func() {
ptr, ok := k... | Since there is a possibility of a write operation (Deletion), we should be taking Write locks instead of Read locks. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
}
// incrementKeyCount increments the key count in the KeyspaceStat map.
// This method is not thread-safe. It should be called within a lock.
func incrementKeyCount() {
if KeyspaceStat[0] == nil {
KeyspaceStat[0] = make(map[string]int)
}
KeyspaceStat[0]["keys"]++
}
// notifyWatchers sends a WatchEvent to the Wa... | As discussed in the other comment, we can stick to the original deleteKey implementation with `DEL` as the operation name being sent to the WatchChannel. | }
// incrementKeyCount increments the key count in the KeyspaceStat map.
// This method is not thread-safe. It should be called within a lock.
func incrementKeyCount() {
if KeyspaceStat[0] == nil {
KeyspaceStat[0] = make(map[string]int)
}
KeyspaceStat[0]["keys"]++
}
// notifyWatchers sends a WatchEvent to the Wa... | @@ -288,12 +308,16 @@ func notifyWatchers(k string, operation string, obj *Obj) {
// the deletion of the key.
// This method is not thread-safe. It should be called within a lock.
func deleteKey(k string, ptr unsafe.Pointer, obj *Obj) bool {
+ return deleteKeyWithOperationName(k, ptr, obj, "DEL")
+}
+
+func deleteKe... | core/store.go | 26 | Go | 0.5 | suggestion | 153 | 47 | 43 | false | #274: Added support for GETDEL command. | 293 | DiceDB/dice | 10,326 | C | JyotinderSingh | raghavbabbar | Review this pull request change.
Language: Go
File: core/store.go
PR Title: #274: Added support for GETDEL command.
BEFORE CODE: }
// incrementKeyCount increments the key count in the KeyspaceStat map.
// This method is not thread-safe. It should be called within a lock.
func incrementKeyCount() {
if KeyspaceStat... | As discussed in the other comment, we can stick to the original deleteKey implementation with `DEL` as the operation name being sent to the WatchChannel. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
switch leftType {
case "string":
return compareStrings(left.(string), right.(string), expr.Operator)
case "int":
return compareInts(left.(int), right.(int), expr.Operator)
case "float":
return compareFloats(left.(float64), right.(float64), expr.Operator)
default:
return false, fmt.Errorf("unsupported type ... | You can probably add a comment explaining why we're checking for an underscore prefix here. | return false, fmt.Errorf("unsupported expression type: %T", expr)
}
}
func evaluateComparison(expr *sqlparser.ComparisonExpr, row DSQLQueryResultRow) (b bool, e error) {
left, leftType, err := getExprValueAndType(expr.Left, row)
if err != nil {
return false, err
}
right, rightType, err := getExprValueAndType(... | @@ -215,12 +219,69 @@ func getExprValueAndType(expr sqlparser.Expr, row DSQLQueryResultRow) (interface
return nil, "", fmt.Errorf("unknown column: %s", expr.Name.String())
}
case *sqlparser.SQLVal:
+ // we currently treat JSON query expression as a string value so we will need to differentiate between JSON an... | core/executor.go | 26 | Go | 0.214 | suggestion | 91 | 51 | 51 | false | #189 Add JSON Support to where clause | 300 | DiceDB/dice | 10,326 | C | JyotinderSingh | YahyaHaq | Review this pull request change.
Language: Go
File: core/executor.go
PR Title: #189 Add JSON Support to where clause
BEFORE CODE: switch leftType {
case "string":
return compareStrings(left.(string), right.(string), expr.Operator)
case "int":
return compareInts(left.(int), right.(int), expr.Operator)
case "... | You can probably add a comment explaining why we're checking for an underscore prefix here. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package tests
import (
"testing"
"gotest.tools/v3/assert"
)
func TestDel(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
testCases := []struct {
name string
commands []string
expected []interface{}
}{
{
name: "DEL with set key",
commands: []string{"SET k1 v1", "DEL k1"},
... | Please also validate that the get call returns nil for deleted keys | package tests
import (
"testing"
"gotest.tools/v3/assert"
)
func TestDel(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
testCases := []struct {
name string
commands []string
expected []interface{}
}{
{
name: "DEL with set key",
commands: []string{"SET k1 v1", "DEL k1", "... | @@ -0,0 +1,45 @@
+package tests
+
+import (
+ "testing"
+
+ "gotest.tools/v3/assert"
+)
+
+func TestDel(t *testing.T) {
+ conn := getLocalConnection()
+ defer conn.Close()
+
+ testCases := []struct {
+ name string
+ commands []string
+ expected []interface{}
+ }{
+ {
+ name: "DEL with set key",
+ comman... | tests/del_test.go | 25 | Go | 0.214 | suggestion | 67 | 46 | 45 | false | #73: testcase for DEL command | 302 | DiceDB/dice | 10,326 | C | JyotinderSingh | Rits1272 | Review this pull request change.
Language: Go
File: tests/del_test.go
PR Title: #73: testcase for DEL command
BEFORE CODE: package tests
import (
"testing"
"gotest.tools/v3/assert"
)
func TestDel(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
testCases := []struct {
name string
com... | Please also validate that the get call returns nil for deleted keys | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
switch arg {
case "REPLACE":
isReplace = true
}
}
if isReplace == true {
Del(destinationKey)
}
destinationObj := Get(destinationKey)
if destinationObj != nil {
return RESP_ZERO
}
sourceType, sourceEncoding := ExtractTypeEncoding(sourceObj)
var value interface{}
switch sourceType {
case OBJ_TY... | The object doesn't need to be a map of strings if it's a JSON. It could just be an array as well. There are a few such possibilities so please ensure we are testing all possible kinds of JSON values (you can refer to the JSON tests for this). |
if isReplace {
Del(destinationKey)
}
destinationObj := Get(destinationKey)
if destinationObj != nil {
return RespZero
}
copyObj := sourceObj.DeepCopy()
if copyObj == nil {
return RespZero
}
exp, ok := getExpiry(sourceObj)
var exDurationMs int64 = -1
if ok {
exDurationMs = int64(exp - uint64(time.... | @@ -1793,6 +1793,95 @@ func evalPersist(args []string) []byte {
return RESP_ONE
}
+func evalCOPY(args []string) []byte {
+ if len(args) < 2 {
+ return Encode(errors.New("ERR wrong number of arguments for 'copy' command"), false)
+ }
+
+ isReplace := false
+
+ sourceKey := args[0]
+ destinationKey := args[1]
+
+ s... | core/eval.go | 26 | Go | 0.5 | suggestion | 242 | 51 | 51 | false | Closes #277 Support for COPY command | 305 | DiceDB/dice | 10,326 | C | JyotinderSingh | srivastava-yash | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: Closes #277 Support for COPY command
BEFORE CODE: switch arg {
case "REPLACE":
isReplace = true
}
}
if isReplace == true {
Del(destinationKey)
}
destinationObj := Get(destinationKey)
if destinationObj != nil {
return RESP... | The object doesn't need to be a map of strings if it's a JSON. It could just be an array as well. There are a few such possibilities so please ensure we are testing all possible kinds of JSON values (you can refer to the JSON tests for this). | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
}, WithStoreLock(), WithKeypoolLock())
}
func NewObj(value interface{}, expDurationMs int64, oType, oEnc uint8) *Obj {
obj := &Obj{
Value: value,
TypeEncoding: oType | oEnc,
LastAccessedAt: getCurrentClock(),
}
if expDurationMs >= 0 {
setExpiry(obj, expDurationMs)
}
return obj
}
type PutOptio... | Do you think it will be better if we do this inside the putHelper (and simply pass the opts directly to it)?
That way we can probably get rid of the nil params being passed to putHelper in a few other places. Additionally, we won't need to do an `opts != nil` check inside the helper. | }, WithStoreLock(), WithKeypoolLock())
}
func NewObj(value interface{}, expDurationMs int64, oType, oEnc uint8) *Obj {
obj := &Obj{
Value: value,
TypeEncoding: oType | oEnc,
LastAccessedAt: getCurrentClock(),
}
if expDurationMs >= 0 {
setExpiry(obj, expDurationMs)
}
return obj
}
type PutOptio... | @@ -58,18 +58,42 @@ func NewObj(value interface{}, expDurationMs int64, oType, oEnc uint8) *Obj {
return obj
}
-func Put(k string, obj *Obj) {
+type PutOptions struct {
+ KeepTTL bool
+}
+
+func Put(k string, obj *Obj, opts ...PutOption) {
+ options := getDefaultOptions()
+
+ for _, optApplier := range opts {
+ o... | core/store.go | 26 | Go | 0.643 | refactor | 285 | 51 | 51 | false | [Dice-206]: support `KEEPTTL` option for `SET` command | 318 | DiceDB/dice | 10,326 | C | JyotinderSingh | kolharsam | Review this pull request change.
Language: Go
File: core/store.go
PR Title: [Dice-206]: support `KEEPTTL` option for `SET` command
BEFORE CODE: }, WithStoreLock(), WithKeypoolLock())
}
func NewObj(value interface{}, expDurationMs int64, oType, oEnc uint8) *Obj {
obj := &Obj{
Value: value,
TypeEncodi... | Do you think it will be better if we do this inside the putHelper (and simply pass the opts directly to it)?
That way we can probably get rid of the nil params being passed to putHelper in a few other places. Additionally, we won't need to do an `opts != nil` check inside the helper. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
RESP encoded -2 stating key doesn't exist or key is expired
RESP encoded -1 in case no expiration is set on the key`,
Eval: evalTTL,
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
}
delCmdMeta = DiceCmdMeta{
Name: "DEL",
Info: `DEL deletes all the specified keys in args list
returns the count o... | nit: Please add the metadata for new commands at the bottom of the list, this helps us with certain documentation related automation that we run. | RESP encoded -2 stating key doesn't exist or key is expired
RESP encoded -1 in case no expiration is set on the key`,
Eval: evalTTL,
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
}
delCmdMeta = DiceCmdMeta{
Name: "DEL",
Info: `DEL deletes all the specified keys in args list
returns the count o... | @@ -125,6 +125,14 @@ var (
Arity: -3,
KeySpecs: KeySpecs{BeginIndex: 1, Step: 1},
}
+ expiretimeCmdMeta = DiceCmdMeta{ | core/commands.go | 26 | Go | 0.357 | nitpick | 145 | 51 | 51 | false | #284: Add support for command `EXPIRETIME` | 325 | DiceDB/dice | 10,326 | C | JyotinderSingh | raknay | Review this pull request change.
Language: Go
File: core/commands.go
PR Title: #284: Add support for command `EXPIRETIME`
BEFORE CODE: RESP encoded -2 stating key doesn't exist or key is expired
RESP encoded -1 in case no expiration is set on the key`,
Eval: evalTTL,
Arity: 2,
KeySpecs: KeySpecs{... | nit: Please add the metadata for new commands at the bottom of the list, this helps us with certain documentation related automation that we run. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
}
setExpiry(obj, exDurationSec*1000)
// 1 if the timeout was set.
return RespOne
}
// evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire
// args should contain only 1 value, the key
// Returns expiration Unix timestamp in seconds.
// Returns -... | Use RESP_MINUS_2 defined in eval.go | return RespZero
}
setExpiry(obj, exDurationSec*1000)
// 1 if the timeout was set.
return RespOne
}
// evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire
// args should contain only 1 value, the key
// Returns expiration Unix timestamp in sec... | @@ -514,6 +514,34 @@ func evalEXPIRE(args []string) []byte {
return RespOne
}
+// evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire
+// args should contain only 1 value, the key
+// Returns expiration Unix timestamp in seconds.
+// Returns -1 i... | core/eval.go | 26 | Go | 0.143 | suggestion | 35 | 51 | 51 | false | #284: Add support for command `EXPIRETIME` | 325 | DiceDB/dice | 10,326 | C | JyotinderSingh | raknay | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #284: Add support for command `EXPIRETIME`
BEFORE CODE: }
setExpiry(obj, exDurationSec*1000)
// 1 if the timeout was set.
return RespOne
}
// evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at whi... | Use RESP_MINUS_2 defined in eval.go | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
}
// evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire
// args should contain only 1 value, the key
// Returns expiration Unix timestamp in seconds.
// Returns -1 if the key exists but has no associated expiration time.
// Returns -2 if the key doe... | Use RESP_MINUS_1 defined in eval.go | return RespOne
}
// evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire
// args should contain only 1 value, the key
// Returns expiration Unix timestamp in seconds.
// Returns -1 if the key exists but has no associated expiration time.
// Returns -... | @@ -514,6 +514,34 @@ func evalEXPIRE(args []string) []byte {
return RespOne
}
+// evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire
+// args should contain only 1 value, the key
+// Returns expiration Unix timestamp in seconds.
+// Returns -1 i... | core/eval.go | 26 | Go | 0.143 | suggestion | 35 | 51 | 51 | false | #284: Add support for command `EXPIRETIME` | 325 | DiceDB/dice | 10,326 | C | JyotinderSingh | raknay | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #284: Add support for command `EXPIRETIME`
BEFORE CODE: }
// evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire
// args should contain only 1 value, the key
// Returns ex... | Use RESP_MINUS_1 defined in eval.go | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
key := "EXISTING_KEY"
value := "mock_value"
obj := &Obj{
Value: value,
LastAccessedAt: uint32(time.Now().Unix()),
}
store[unsafe.Pointer(obj)] = obj
keypool[key] = unsafe.Pointer(obj)
expires[obj] = uint64(time.Now().Add(-2 * time.Minute).Unix())
},
input: []string{... | ```suggestion
"key exists without expiry": {
``` | setup: func() {
key := "EXISTING_KEY"
value := "mock_value"
obj := &Obj{
Value: value,
LastAccessedAt: uint32(time.Now().Unix()),
}
store[unsafe.Pointer(obj)] = obj
keypool[key] = unsafe.Pointer(obj)
expires[obj] = uint64(time.Now().Add(-2 * time.Minute).Unix())
},
... | @@ -177,6 +178,32 @@ func testEvalGET(t *testing.T) {
runEvalTests(t, tests, evalGET)
}
+func testEvalEXPIRETIME(t *testing.T) {
+ tests := map[string]evalTestCase{
+ "key does not exist": {
+ setup: func() {},
+ input: []string{"NONEXISTENT_KEY"},
+ output: RespMinusTwo,
+ },
+ "key exists without expa... | core/eval_test.go | 26 | Go | 0.571 | suggestion | 52 | 51 | 51 | false | #284: Add support for command `EXPIRETIME` | 325 | DiceDB/dice | 10,326 | C | JyotinderSingh | raknay | Review this pull request change.
Language: Go
File: core/eval_test.go
PR Title: #284: Add support for command `EXPIRETIME`
BEFORE CODE: key := "EXISTING_KEY"
value := "mock_value"
obj := &Obj{
Value: value,
LastAccessedAt: uint32(time.Now().Unix()),
}
store[unsafe.Pointer(obj)... | ```suggestion
"key exists without expiry": {
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
},
input: []string{"EXISTING_KEY"},
output: Encode("mock_value", false),
},
"key exists but expired": {
setup: func() {
key := "EXISTING_KEY"
value := "mock_value"
obj := &Obj{
Value: value,
LastAccessedAt: uint32(time.Now().Unix()),
}
store[unsafe.Pointer(obj)] =... | Add a test case for the happy path too, where the expiry time is returned. | keypool[key] = unsafe.Pointer(obj)
},
input: []string{"EXISTING_KEY"},
output: Encode("mock_value", false),
},
"key exists but expired": {
setup: func() {
key := "EXISTING_KEY"
value := "mock_value"
obj := &Obj{
Value: value,
LastAccessedAt: uint32(time.Now().Unix()),... | @@ -177,6 +178,32 @@ func testEvalGET(t *testing.T) {
runEvalTests(t, tests, evalGET)
}
+func testEvalEXPIRETIME(t *testing.T) { | core/eval_test.go | 26 | Go | 0.214 | suggestion | 74 | 51 | 51 | false | #284: Add support for command `EXPIRETIME` | 325 | DiceDB/dice | 10,326 | C | JyotinderSingh | raknay | Review this pull request change.
Language: Go
File: core/eval_test.go
PR Title: #284: Add support for command `EXPIRETIME`
BEFORE CODE: },
input: []string{"EXISTING_KEY"},
output: Encode("mock_value", false),
},
"key exists but expired": {
setup: func() {
key := "EXISTING_KEY"
value := "moc... | Add a test case for the happy path too, where the expiry time is returned. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire
// args should contain only 1 value, the key
// Returns expiration Unix timestamp in seconds.
// Returns -1 if the key exists but has no associated expiration time.
// Returns -2 if the key does n... | ```suggestion
return Encode(int(exTimeMili/1000), false)
```
We don't need to encode this as bulk string | // evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire
// args should contain only 1 value, the key
// Returns expiration Unix timestamp in seconds.
// Returns -1 if the key exists but has no associated expiration time.
// Returns -2 if the key does n... | @@ -515,6 +515,34 @@ func evalEXPIRE(args []string) []byte {
return RespOne
}
+// evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire
+// args should contain only 1 value, the key
+// Returns expiration Unix timestamp in seconds.
+// Returns -1 i... | core/eval.go | 26 | Go | 0.714 | suggestion | 110 | 51 | 51 | false | #284: Add support for command `EXPIRETIME` | 325 | DiceDB/dice | 10,326 | C | JyotinderSingh | raknay | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #284: Add support for command `EXPIRETIME`
BEFORE CODE: // evalEXPIRETIME returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire
// args should contain only 1 value, the key
// Returns expir... | ```suggestion
return Encode(int(exTimeMili/1000), false)
```
We don't need to encode this as bulk string | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// The key should be the only param in args
// The RESP value of the key is encoded and then returned
// evalGET returns RespNIL if key is expired or it does not exist
func evalGET(args []string) []byte {
if len(args) != 1 {
return Encode(errors.New("ERR wrong number of arguments for 'get' command"), false)
}
var... | shouldn't it be 'dbsize' instead of 'hello' ?
| // The RESP value of the key is encoded and then returned
// evalGET returns RespNIL if key is expired or it does not exist
func evalGET(args []string) []byte {
if len(args) != 1 {
return Encode(errors.New("ERR wrong number of arguments for 'get' command"), false)
}
var key string = args[0]
// Get the key from ... | @@ -254,6 +254,16 @@ func evalGET(args []string) []byte {
return Encode(obj.Value, false)
}
+// evalDBSIZE returns the number of keys in the database.
+func evalDBSIZE(args []string) []byte {
+ if len(args) > 1 {
+ return Encode(errors.New("ERR wrong number of arguments for 'hello' command"), false) | core/eval.go | 26 | Go | 0.143 | question | 49 | 51 | 51 | false | #278: Add support for command `DBSIZE` | 328 | DiceDB/dice | 10,326 | C | kushal0511-not | raknay | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #278: Add support for command `DBSIZE`
BEFORE CODE: // The key should be the only param in args
// The RESP value of the key is encoded and then returned
// evalGET returns RespNIL if key is expired or it does not exist
func evalGET(args []s... | shouldn't it be 'dbsize' instead of 'hello' ?
| You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// evalGET returns the value for the queried key in args
// The key should be the only param in args
// The RESP value of the key is encoded and then returned
// evalGET returns RespNIL if key is expired or it does not exist
func evalGET(args []string) []byte {
if len(args) != 1 {
return Encode(errors.New("ERR wrong... | condition should be '**len(args) > 0'** as DBSIZE does not accepts any args. | // The key should be the only param in args
// The RESP value of the key is encoded and then returned
// evalGET returns RespNIL if key is expired or it does not exist
func evalGET(args []string) []byte {
if len(args) != 1 {
return Encode(errors.New("ERR wrong number of arguments for 'get' command"), false)
}
var... | @@ -254,6 +254,16 @@ func evalGET(args []string) []byte {
return Encode(obj.Value, false)
}
+// evalDBSIZE returns the number of keys in the database.
+func evalDBSIZE(args []string) []byte {
+ if len(args) > 1 { | core/eval.go | 26 | Go | 0.286 | suggestion | 77 | 51 | 51 | false | #278: Add support for command `DBSIZE` | 328 | DiceDB/dice | 10,326 | C | kushal0511-not | raknay | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #278: Add support for command `DBSIZE`
BEFORE CODE: // evalGET returns the value for the queried key in args
// The key should be the only param in args
// The RESP value of the key is encoded and then returned
// evalGET returns RespNIL if ... | condition should be '**len(args) > 0'** as DBSIZE does not accepts any args. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
Eval: evalPTTL,
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
}
objectCmdMeta = DiceCmdMeta{
Name: "OBJECT",
Info: `OBJECT subcommand [arguments [arguments ...]]
OBJECT command is used to inspect the internals of the Redis objects.`,
Eval: evalOBJECT,
Arity: -2,
KeySpecs: KeySpecs{Begin... | Arity should be 1 .
you can check that in [Redis](https://github.com/redis/redis/blob/2b88db90aad82574541edae6329ef24053fb4188/src/commands/dbsize.json#L7) | Eval: evalPTTL,
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
}
objectCmdMeta = DiceCmdMeta{
Name: "OBJECT",
Info: `OBJECT subcommand [arguments [arguments ...]]
OBJECT command is used to inspect the internals of the Redis objects.`,
Eval: evalOBJECT,
Arity: -2,
KeySpecs: KeySpecs{Begin... | @@ -552,6 +552,12 @@ var (
Arity: -2,
KeySpecs: KeySpecs{BeginIndex: 1},
}
+ dbSizeCmdMeta = DiceCmdMeta{
+ Name: "DBSIZE",
+ Info: `DBSIZE Return the number of keys in the currently-selected database`,
+ Eval: evalDBSIZE,
+ Arity: -1, | core/commands.go | 26 | Go | 0.429 | suggestion | 157 | 51 | 51 | false | #278: Add support for command `DBSIZE` | 328 | DiceDB/dice | 10,326 | C | kushal0511-not | raknay | Review this pull request change.
Language: Go
File: core/commands.go
PR Title: #278: Add support for command `DBSIZE`
BEFORE CODE: Eval: evalPTTL,
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
}
objectCmdMeta = DiceCmdMeta{
Name: "OBJECT",
Info: `OBJECT subcommand [arguments [arguments ...]]
OBJ... | Arity should be 1 .
you can check that in [Redis](https://github.com/redis/redis/blob/2b88db90aad82574541edae6329ef24053fb4188/src/commands/dbsize.json#L7) | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// List all keys in the store by given pattern
func Keys(p string) ([]string, error) {
var keys []string
var err error
withLocks(func() {
keys = make([]string, 0, len(keypool))
for k := range keypool {
if found, e := path.Match(p, k); e != nil {
err = e
return
} else if found {
keys = append(k... | No need to take a lock on the store since we don't access it. Also, use `WithKeypoolRLock()` (read-lock for keypool instead of write lock) | // List all keys in the store by given pattern
func Keys(p string) ([]string, error) {
var keys []string
var err error
withLocks(func() {
keys = make([]string, 0, len(keypool))
for k := range keypool {
if found, e := path.Match(p, k); e != nil {
err = e
return
} else if found {
keys = append(k... | @@ -183,6 +183,15 @@ func Keys(p string) ([]string, error) {
return keys, err
}
+// GetDbSize returns all the keys present in the db
+func GetDBSize() uint64 {
+ var noOfKeys uint64
+ withLocks(func() {
+ noOfKeys = uint64(len(keypool))
+ }, WithStoreRLock(), WithKeypoolLock()) | core/store.go | 26 | Go | 0.571 | suggestion | 138 | 51 | 51 | false | #278: Add support for command `DBSIZE` | 328 | DiceDB/dice | 10,326 | C | JyotinderSingh | raknay | Review this pull request change.
Language: Go
File: core/store.go
PR Title: #278: Add support for command `DBSIZE`
BEFORE CODE: // List all keys in the store by given pattern
func Keys(p string) ([]string, error) {
var keys []string
var err error
withLocks(func() {
keys = make([]string, 0, len(keypool))
for... | No need to take a lock on the store since we don't access it. Also, use `WithKeypoolRLock()` (read-lock for keypool instead of write lock) | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
return withLocksReturn(func() bool {
return delByPtr(ptr)
}, WithStoreLock(), WithKeypoolLock())
}
// List all keys in the store by given pattern
func Keys(p string) ([]string, error) {
var keys []string
var err error
withLocks(func() {
keys = make([]string, 0, len(keypool))
for k := range keypool {
if ... | we can change the comment to this
// GetDbSize returns the number of keys in the currently-selected database | return withLocksReturn(func() bool {
return delByPtr(ptr)
}, WithStoreLock(), WithKeypoolLock())
}
// List all keys in the store by given pattern
func Keys(p string) ([]string, error) {
var keys []string
var err error
withLocks(func() {
keys = make([]string, 0, len(keypool))
for k := range keypool {
if ... | @@ -183,6 +183,15 @@ func Keys(p string) ([]string, error) {
return keys, err
}
+// GetDbSize returns all the keys present in the db | core/store.go | 26 | Go | 0.429 | suggestion | 109 | 51 | 51 | false | #278: Add support for command `DBSIZE` | 328 | DiceDB/dice | 10,326 | C | ashwaniYDV | raknay | Review this pull request change.
Language: Go
File: core/store.go
PR Title: #278: Add support for command `DBSIZE`
BEFORE CODE: return withLocksReturn(func() bool {
return delByPtr(ptr)
}, WithStoreLock(), WithKeypoolLock())
}
// List all keys in the store by given pattern
func Keys(p string) ([]string, error)... | we can change the comment to this
// GetDbSize returns the number of keys in the currently-selected database | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
Info: `TOUCH key1 key2 ... key_N
Alters the last access time of a key(s).
A key is ignored if it does not exist.`,
Eval: evalTOUCH,
Arity: -2,
KeySpecs: KeySpecs{BeginIndex: 1},
}
expiretimeCmdMeta = DiceCmdMeta{
Name: "EXPIRETIME",
Info: `EXPIRETIME returns the absolute Unix timestamp (since J... | nit: could you reposition this block to the end of the initialiser list | Info: `TOUCH key1 key2 ... key_N
Alters the last access time of a key(s).
A key is ignored if it does not exist.`,
Eval: evalTOUCH,
Arity: -2,
KeySpecs: KeySpecs{BeginIndex: 1},
}
expiretimeCmdMeta = DiceCmdMeta{
Name: "EXPIRETIME",
Info: `EXPIRETIME returns the absolute Unix timestamp (since J... | @@ -570,6 +570,17 @@ var (
Arity: -2,
KeySpecs: KeySpecs{BeginIndex: 1, Step: 1},
}
+ expireatCmdMeta = DiceCmdMeta{
+ Name: "EXPIREAT",
+ Info: `EXPIREAT sets a expiry time(in unix-time-seconds) on the specified key in args
+ args should contain 2 values, key and the expiry time to be set for the key
+ ... | core/commands.go | 26 | Go | 0.286 | nitpick | 71 | 51 | 51 | false | #283: Add support for command EXPIREAT | 338 | DiceDB/dice | 10,326 | C | JyotinderSingh | ashwaniYDV | Review this pull request change.
Language: Go
File: core/commands.go
PR Title: #283: Add support for command EXPIREAT
BEFORE CODE: Info: `TOUCH key1 key2 ... key_N
Alters the last access time of a key(s).
A key is ignored if it does not exist.`,
Eval: evalTOUCH,
Arity: -2,
KeySpecs: KeySpecs{Begi... | nit: could you reposition this block to the end of the initialiser list | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
}
func evalHELLO(args []string) []byte {
if len(args) > 1 {
return Encode(errors.New("ERR wrong number of arguments for 'hello' command"), false)
}
var response []interface{}
response = append(response,
"proto", 2,
"id", serverID,
"mode", "standalone",
"role", "master",
"modules", []interface{}{})
r... | An expiry in the past should immediately delete the key.
| }
// evalEXPIREAT sets a expiry time(in unix-time-seconds) on the specified key in args
// args should contain 2 values, key and the expiry time to be set for the key
// The expiry time should be in integer format; if not, it returns encoded error response
// Returns RespOne if expiry was set on the key successfully.
... | @@ -616,6 +616,35 @@ func evalEXPIRETIME(args []string) []byte {
return Encode(int(exTimeMili/1000), false)
}
+// evalEXPIREAT sets a expiry time(in unix-time-seconds) on the specified key in args
+// args should contain 2 values, key and the expiry time to be set for the key
+// The expiry time should be in integ... | core/eval.go | 26 | Go | 0.286 | suggestion | 58 | 51 | 51 | false | #283: Add support for command EXPIREAT | 338 | DiceDB/dice | 10,326 | C | JyotinderSingh | ashwaniYDV | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #283: Add support for command EXPIREAT
BEFORE CODE: }
func evalHELLO(args []string) []byte {
if len(args) > 1 {
return Encode(errors.New("ERR wrong number of arguments for 'hello' command"), false)
}
var response []interface{}
respon... | An expiry in the past should immediately delete the key.
| You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
var key string = args[0]
obj := Get(key)
// -2 if key doesn't exist
if obj == nil {
return RespMinusTwo
}
exTimeMili, ok := getExpiry(obj)
// -1 if key doesn't have expiration time set
if !ok {
return RespMinusOne
}
return Encode(int(exTimeMili/1000), false)
}
func evalHELLO(args []string) []byte {
... | From redis docs,
> The EXPIREAT command supports a set of options:
NX -- Set expiry only when the key has no expiry
XX -- Set expiry only when the key has an existing expiry
GT -- Set expiry only when the new expiry is greater than current one
LT -- Set expiry only when the new expiry is less than current one
A non-vo... |
var key string = args[0]
obj := Get(key)
// -2 if key doesn't exist
if obj == nil {
return RespMinusTwo
}
exTimeMili, ok := getExpiry(obj)
// -1 if key doesn't have expiration time set
if !ok {
return RespMinusOne
}
return Encode(int(exTimeMili/1000), false)
}
// evalEXPIREAT sets a expiry time(in u... | @@ -616,6 +616,35 @@ func evalEXPIRETIME(args []string) []byte {
return Encode(int(exTimeMili/1000), false)
}
+// evalEXPIREAT sets a expiry time(in unix-time-seconds) on the specified key in args
+// args should contain 2 values, key and the expiry time to be set for the key
+// The expiry time should be in integ... | core/eval.go | 26 | Go | 0.5 | question | 549 | 51 | 51 | false | #283: Add support for command EXPIREAT | 338 | DiceDB/dice | 10,326 | C | JyotinderSingh | ashwaniYDV | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #283: Add support for command EXPIREAT
BEFORE CODE:
var key string = args[0]
obj := Get(key)
// -2 if key doesn't exist
if obj == nil {
return RespMinusTwo
}
exTimeMili, ok := getExpiry(obj)
// -1 if key doesn't have expiration ... | From redis docs,
> The EXPIREAT command supports a set of options:
NX -- Set expiry only when the key has no expiry
XX -- Set expiry only when the key has an existing expiry
GT -- Set expiry only when the new expiry is greater than current one
LT -- Set expiry only when the new expiry is less than current one
A non-vo... | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
return
}
v = store[ptr]
if v != nil {
expired := hasExpired(v)
deleteKey(k, ptr, v)
if expired {
v = nil
}
}
}, WithStoreLock(), WithKeypoolLock())
return v
}
// setExpiry sets the expiry time for an object.
// This method is not thread-safe. It should be called within a lock.
func setExp... | Acquire a lock on the expires map when modifying it. | return
}
v = store[ptr]
if v != nil {
expired := hasExpired(v)
deleteKey(k, ptr, v)
if expired {
v = nil
}
}
}, WithStoreLock(), WithKeypoolLock())
return v
}
// setExpiry sets the expiry time for an object.
// This method is not thread-safe. It should be called within a lock.
func setExp... | @@ -316,6 +316,13 @@ func setExpiry(obj *Obj, expDurationMs int64) {
expires[obj] = uint64(utils.GetCurrentTime().UnixMilli()) + uint64(expDurationMs)
}
+// setUnixTimeExpiry sets the expiry time for an object.
+// This method is not thread-safe. It should be called within a lock.
+func setUnixTimeExpiry(obj *Obj,... | core/store.go | 26 | Go | 0.214 | suggestion | 52 | 51 | 51 | false | #283: Add support for command EXPIREAT | 338 | DiceDB/dice | 10,326 | C | JyotinderSingh | ashwaniYDV | Review this pull request change.
Language: Go
File: core/store.go
PR Title: #283: Add support for command EXPIREAT
BEFORE CODE: return
}
v = store[ptr]
if v != nil {
expired := hasExpired(v)
deleteKey(k, ptr, v)
if expired {
v = nil
}
}
}, WithStoreLock(), WithKeypoolLock())
return v
}... | Acquire a lock on the expires map when modifying it. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package utils
const (
ObjectType string = "object"
ArrayType string = "array"
StringType string = "string"
IntegerType string = "integer"
NumberType string = "number"
BooleanType string = "boolean"
NullType string = "null"
UnknownType string = "unknown"
)
func GetJSONFieldType(v interface{}) string {
... | Please use `internal/constants/constants.go` for defining constants. | package utils
import (
"github.com/dicedb/dice/internal/constants"
)
func GetJSONFieldType(v interface{}) string {
switch v.(type) {
case map[string]interface{}:
return constants.ObjectType
case []interface{}:
return constants.ArrayType
case string:
return constants.StringType
case int, int8, int16, int32... | @@ -0,0 +1,33 @@
+package utils
+
+const (
+ ObjectType string = "object"
+ ArrayType string = "array"
+ StringType string = "string"
+ IntegerType string = "integer"
+ NumberType string = "number"
+ BooleanType string = "boolean"
+ NullType string = "null"
+ UnknownType string = "unknown" | server/utils/jsontype.go | 11 | Go | 0.429 | suggestion | 68 | 34 | 27 | false | #342: feat: add support for json.type command | 344 | DiceDB/dice | 10,326 | C | JyotinderSingh | jujiale | Review this pull request change.
Language: Go
File: server/utils/jsontype.go
PR Title: #342: feat: add support for json.type command
BEFORE CODE: package utils
const (
ObjectType string = "object"
ArrayType string = "array"
StringType string = "string"
IntegerType string = "integer"
NumberType string = "... | Please use `internal/constants/constants.go` for defining constants. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
name: "nil test",
input: nil,
wantType: "null",
},
{
name: "array test",
input: []interface{}{"string"},
wantType: "array",
},
{
name: "object test",
input: map[string]interface{}{},
wantType: "object",
},
{
name: "unknown test",
input: struct{}{}... | nit: Please use the assert library for assertions | {
name: "nil test",
input: nil,
wantType: "null",
},
{
name: "array test",
input: []interface{}{"string"},
wantType: "array",
},
{
name: "object test",
input: map[string]interface{}{},
wantType: "object",
},
{
name: "unknown test",
input: struct... | @@ -0,0 +1,63 @@
+package utils
+
+import (
+ "testing"
+)
+
+func TestGetJsonFieldType(t *testing.T) {
+ tests := []struct {
+ name string
+ input interface{}
+ wantType string
+ }{
+ {
+ name: "string test",
+ input: "123",
+ wantType: "string",
+ },
+ {
+ name: "integer test",
+ inp... | server/utils/jsontype_test.go | 26 | Go | 0.143 | nitpick | 49 | 31 | 30 | false | #342: feat: add support for json.type command | 344 | DiceDB/dice | 10,326 | C | JyotinderSingh | jujiale | Review this pull request change.
Language: Go
File: server/utils/jsontype_test.go
PR Title: #342: feat: add support for json.type command
BEFORE CODE: name: "nil test",
input: nil,
wantType: "null",
},
{
name: "array test",
input: []interface{}{"string"},
wantType: "array",
},
... | nit: Please use the assert library for assertions | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// return the RESP encoded value
return Encode(obj.Value, false)
}
// evalJSONTYPE retrieves a JSON value type stored at the specified key
// args must contain at least the key; (path unused in this implementation)
// Returns RespNIL if key is expired or it does not exist
// Returns encoded error response if incor... | Please use `assertType` and `assertEncoding` methods to validate the retrieved object's type and encoding.
Return error if the object doesn't have JSON type and encoding. |
// return the RESP encoded value
return Encode(obj.Value, false)
}
// evalJSONTYPE retrieves a JSON value type stored at the specified key
// args must contain at least the key; (path unused in this implementation)
// Returns RespNIL if key is expired or it does not exist
// Returns encoded error response if incor... | @@ -287,6 +287,61 @@ func evalGETDEL(args []string) []byte {
return Encode(obj.Value, false)
}
+// evalJSONTYPE retrieves a JSON value type stored at the specified key
+// args must contain at least the key; (path unused in this implementation)
+// Returns RespNIL if key is expired or it does not exist
+// Return... | core/eval.go | 26 | Go | 0.714 | suggestion | 170 | 51 | 51 | false | #342: feat: add support for json.type command | 344 | DiceDB/dice | 10,326 | C | JyotinderSingh | jujiale | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #342: feat: add support for json.type command
BEFORE CODE:
// return the RESP encoded value
return Encode(obj.Value, false)
}
// evalJSONTYPE retrieves a JSON value type stored at the specified key
// args must contain at least the key; ... | Please use `assertType` and `assertEncoding` methods to validate the retrieved object's type and encoding.
Return error if the object doesn't have JSON type and encoding. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
Returns OK if successful.
Returns encoded error message if the number of arguments is incorrect or the JSON string is invalid.`,
Eval: evalJSONSET,
Arity: -3,
KeySpecs: KeySpecs{BeginIndex: 1},
}
jsongetCmdMeta = DiceCmdMeta{
Name: "JSON.GET",
Info: `JSON.GET key [path]
Returns the encoded RESP... | Arity will be -2, right?
Also please add this new object to the bottom of the list (we run an automated script to generate docs and it requires new objects to be added to the bottom of the list) | Returns OK if successful.
Returns encoded error message if the number of arguments is incorrect or the JSON string is invalid.`,
Eval: evalJSONSET,
Arity: -3,
KeySpecs: KeySpecs{BeginIndex: 1},
}
jsongetCmdMeta = DiceCmdMeta{
Name: "JSON.GET",
Info: `JSON.GET key [path]
Returns the encoded RESP... | @@ -94,6 +94,16 @@ var (
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
}
+ jsontypeCmdMeta = DiceCmdMeta{
+ Name: "JSON.TYPE",
+ Info: `JSON.TYPE key [path]
+ Returns string reply for each path, specified as the value's type.
+ Returns RespNIL If the key doesn't exist.
+ Error reply: If the number of arg... | core/commands.go | 26 | Go | 0.357 | suggestion | 195 | 51 | 51 | false | #342: feat: add support for json.type command | 344 | DiceDB/dice | 10,326 | C | JyotinderSingh | jujiale | Review this pull request change.
Language: Go
File: core/commands.go
PR Title: #342: feat: add support for json.type command
BEFORE CODE: Returns OK if successful.
Returns encoded error message if the number of arguments is incorrect or the JSON string is invalid.`,
Eval: evalJSONSET,
Arity: -3,
Ke... | Arity will be -2, right?
Also please add this new object to the bottom of the list (we run an automated script to generate docs and it requires new objects to be added to the bottom of the list) | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
input: []string{"KEY1", "KEY2"},
output: []byte("-ERR wrong number of arguments for 'expire' command\r\n"),
},
"key does not exist": {
input: []string{"NONEXISTENT_KEY"},
output: RespMinusTwo,
},
"key exists without expiry": {
setup: func() {
key := "EXISTING_KEY"
value := "mock_value"
... | https://github.com/DiceDB/dice/pull/370
unsafe.Pointer is going to be removed. | tests := map[string]evalTestCase{
"nil value": {
input: nil,
output: []byte("-ERR wrong number of arguments for 'expire' command\r\n"),
},
"empty args": {
input: []string{},
output: []byte("-ERR wrong number of arguments for 'expire' command\r\n"),
},
"wrong number of args": {
input: []stri... | @@ -178,11 +179,49 @@ func testEvalGET(t *testing.T, store *Store) {
runEvalTests(t, tests, evalGET, store)
}
+
+func testEvalEXPIRE(t *testing.T, store *Store) {
+ tests := map[string]evalTestCase{
+ "nil value": {
+ input: nil,
+ output: []byte("-ERR wrong number of arguments for 'expire' command\r\n"),
+ ... | core/eval_test.go | 26 | Go | 0.286 | suggestion | 79 | 51 | 51 | false | #361: Added unit test and integration test for EXPIRE, EXPIRETIME commands | 362 | DiceDB/dice | 10,326 | C | Rajan-226 | ashwaniYDV | Review this pull request change.
Language: Go
File: core/eval_test.go
PR Title: #361: Added unit test and integration test for EXPIRE, EXPIRETIME commands
BEFORE CODE: input: []string{"KEY1", "KEY2"},
output: []byte("-ERR wrong number of arguments for 'expire' command\r\n"),
},
"key does not exist": {
... | https://github.com/DiceDB/dice/pull/370
unsafe.Pointer is going to be removed. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
name: "Get Nested Array",
setCmd: `JSON.SET inventory $ ` + complexJSON,
getCmd: `JSON.GET inventory $.inventory.mountain_bikes[*].model`,
expected: `["Phoebe","Quaoar","Weywot"]`,
},
{
name: "Get Nested Object",
setCmd: `JSON.SET inventory $ ` + complexJSON,
getCmd: `JSON.GET i... | ```suggestion
// - Cases where the possible order of the resultant array is multiple permutations
// ref: https://github.com/DiceDB/dice/pull/365
``` | {
name: "Get Nested Array",
setCmd: `JSON.SET inventory $ ` + complexJSON,
getCmd: `JSON.GET inventory $.inventory.mountain_bikes[*].model`,
expected: `["Phoebe","Quaoar","Weywot"]`,
},
{
name: "Get Nested Object",
setCmd: `JSON.SET inventory $ ` + complexJSON,
getCmd: `JSON.G... | @@ -123,27 +134,41 @@ func TestJSONOperations(t *testing.T) {
getCmd: `JSON.GET inventory $.inventory.mountain_bikes[0].specs`,
expected: `{"material":"carbon","weight":13.1}`,
},
- {
- name: "Get All Prices",
- setCmd: `JSON.SET inventory $ ` + complexJSON,
- getCmd: `JSON.GET inventory $..... | tests/json_test.go | 26 | Go | 0.714 | suggestion | 154 | 51 | 51 | false | Fixed flaky tests due to json ordering | 365 | DiceDB/dice | 10,326 | C | JyotinderSingh | VedWhat | Review this pull request change.
Language: Go
File: tests/json_test.go
PR Title: Fixed flaky tests due to json ordering
BEFORE CODE: name: "Get Nested Array",
setCmd: `JSON.SET inventory $ ` + complexJSON,
getCmd: `JSON.GET inventory $.inventory.mountain_bikes[*].model`,
expected: `["Phoebe","Qu... | ```suggestion
// - Cases where the possible order of the resultant array is multiple permutations
// ref: https://github.com/DiceDB/dice/pull/365
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
"github.com/dicedb/dice/testutils"
"gotest.tools/v3/assert"
)
func TestJSONOperations(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
simpleJSON := `{"name":"John","age":30}`
nestedJSON := `{"name":"Alice","address":{"city":"New York","zip":"10001"},"array":[1,2,3,4,5]}`
specialCharsJSON := `{"... | ```suggestion
// - JSON Objects (key ordering is taken care of)
// ref: https://github.com/DiceDB/dice/pull/365
``` | "github.com/dicedb/dice/testutils"
"gotest.tools/v3/assert"
)
func TestJSONOperations(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
simpleJSON := `{"name":"John","age":30}`
nestedJSON := `{"name":"Alice","address":{"city":"New York","zip":"10001"},"array":[1,2,3,4,5]}`
specialCharsJSON := `{"... | @@ -21,7 +21,18 @@ func TestJSONOperations(t *testing.T) {
escapedCharsJSON := `{"escaped":"\"quoted\", \\backslash\\ and /forward/slash"}`
complexJSON := `{"inventory":{"mountain_bikes":[{"id":"bike:1","model":"Phoebe","price":1920,"specs":{"material":"carbon","weight":13.1},"colors":["black","silver"]},{"id":"bik... | tests/json_test.go | 26 | Go | 0.714 | suggestion | 122 | 51 | 51 | false | Fixed flaky tests due to json ordering | 365 | DiceDB/dice | 10,326 | C | JyotinderSingh | VedWhat | Review this pull request change.
Language: Go
File: tests/json_test.go
PR Title: Fixed flaky tests due to json ordering
BEFORE CODE: "github.com/dicedb/dice/testutils"
"gotest.tools/v3/assert"
)
func TestJSONOperations(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
simpleJSON := `{"name":"Jo... | ```suggestion
// - JSON Objects (key ordering is taken care of)
// ref: https://github.com/DiceDB/dice/pull/365
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
type HMap = *orderedmap.OrderedMap[string, string]
func hashMapBuilder(args []string, currentHashMap HMap) (HMap, int64, error) {
var hmap HMap
var numKeysNewlySet int64
if currentHashMap == nil {
hmap = orderedmap.New[string, string]()
} else {
hmap = currentHashMap
}
iter := 1 // NOTE: to move past args[... | you can use diceerrors.NewErr here
Pls refer this PR https://github.com/DiceDB/dice/pull/288 | type HashMap map[string]string
func (h HashMap) Get(k string) (*string, bool) {
value, ok := h[k]
if !ok {
return nil, false
}
return &value, true
}
func (h HashMap) Set(k, v string) (*string, bool) {
value, ok := h[k]
if ok {
oldValue := value
h[k] = v
return &oldValue, true
}
h[k] = v
return nil, ... | @@ -0,0 +1,39 @@
+package core
+
+import (
+ "errors"
+
+ orderedmap "github.com/wk8/go-ordered-map/v2"
+)
+
+type HMap = *orderedmap.OrderedMap[string, string]
+
+func hashMapBuilder(args []string, currentHashMap HMap) (HMap, int64, error) {
+ var hmap HMap
+ var numKeysNewlySet int64
+
+ if currentHashMap == nil {
+ ... | core/hmap.go | 26 | Go | 0.429 | suggestion | 93 | 32 | 51 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | ashwaniYDV | kolharsam | Review this pull request change.
Language: Go
File: core/hmap.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: type HMap = *orderedmap.OrderedMap[string, string]
func hashMapBuilder(args []string, currentHashMap HMap) (HMap, int64, error) {
var hmap HMap
var numKeysNewlySet int64
if currentHashMap == n... | you can use diceerrors.NewErr here
Pls refer this PR https://github.com/DiceDB/dice/pull/288 | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
import (
"errors"
orderedmap "github.com/wk8/go-ordered-map/v2"
)
type HMap = *orderedmap.OrderedMap[string, string]
func hashMapBuilder(args []string, currentHashMap HMap) (HMap, int64, error) {
var hmap HMap
var numKeysNewlySet int64
if currentHashMap == nil {
hmap = orderedmap.New[string, st... | Any specific reasons for using `orderedMap`? Asking as Redis doesn't [preserve order](https://stackoverflow.com/questions/40643482/redis-inserting-out-of-order-or-sorting-oddly) in case of `HSET` | package core
import (
"fmt"
"github.com/dicedb/dice/core/diceerrors"
)
type HashMap map[string]string
func (h HashMap) Get(k string) (*string, bool) {
value, ok := h[k]
if !ok {
return nil, false
}
return &value, true
}
func (h HashMap) Set(k, v string) (*string, bool) {
value, ok := h[k]
if ok {
oldVa... | @@ -0,0 +1,39 @@
+package core
+
+import (
+ "errors"
+
+ orderedmap "github.com/wk8/go-ordered-map/v2"
+)
+
+type HMap = *orderedmap.OrderedMap[string, string] | core/hmap.go | 9 | Go | 0.643 | bug | 195 | 34 | 34 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | lucifercr07 | kolharsam | Review this pull request change.
Language: Go
File: core/hmap.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: package core
import (
"errors"
orderedmap "github.com/wk8/go-ordered-map/v2"
)
type HMap = *orderedmap.OrderedMap[string, string]
func hashMapBuilder(args []string, currentHashMap HMap) (HMap... | Any specific reasons for using `orderedMap`? Asking as Redis doesn't [preserve order](https://stackoverflow.com/questions/40643482/redis-inserting-out-of-order-or-sorting-oddly) in case of `HSET` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// respective values in an hashmap stored at key
//
// This command overwrites the values of specified
// fields that exist in the hash.
//
// If key doesn't exist, a new key holding a hash is created.
//
// Usage: HSET key field value [field value ...]
func evalHSET(args []string, store *Store) []byte {
if len(args) ... | Can we simplify L2165-L2170 as?
```
hashMap, numKeys, err := hashMapBuilder(args, currentVal)
if err != nil {
return Encode(err, false)
}
``` | _, isExpirySet := getExpiry(obj, store)
if !isExpirySet {
return RespMinusOne
}
// If the object exists, remove the expiration time
delExpiry(obj, store)
return RespOne
}
func evalCOPY(args []string, store *Store) []byte {
if len(args) < 2 {
return diceerrors.NewErrArity("COPY")
}
isReplace := false
... | @@ -2136,6 +2136,89 @@ func evalPTTL(args []string, store *Store) []byte {
return Encode(int64(durationMs), false)
}
+// evalHSET sets the specified fields to their
+// respective values in an hashmap stored at key
+//
+// This command overwrites the values of specified
+// fields that exist in the hash.
+//
+// I... | core/eval.go | 26 | Go | 0.786 | refactor | 153 | 51 | 51 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | lucifercr07 | kolharsam | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: // respective values in an hashmap stored at key
//
// This command overwrites the values of specified
// fields that exist in the hash.
//
// If key doesn't exist, a new key holding a hash is crea... | Can we simplify L2165-L2170 as?
```
hashMap, numKeys, err := hashMapBuilder(args, currentVal)
if err != nil {
return Encode(err, false)
}
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
import (
"errors"
orderedmap "github.com/wk8/go-ordered-map/v2"
)
type HMap = *orderedmap.OrderedMap[string, string]
func hashMapBuilder(args []string, currentHashMap HMap) (HMap, int64, error) {
var hmap HMap
var numKeysNewlySet int64
if currentHashMap == nil {
hmap = orderedmap.New[string, st... | Is passing `args[]` required here? Asking as we're any ways doing `iter := 1`
Instead of passing the entire args slice, shall we pass only pass key-value pairs?
With call as `keyValuePairs := args[1:]`. | package core
import (
"fmt"
"github.com/dicedb/dice/core/diceerrors"
)
type HashMap map[string]string
func (h HashMap) Get(k string) (*string, bool) {
value, ok := h[k]
if !ok {
return nil, false
}
return &value, true
}
func (h HashMap) Set(k, v string) (*string, bool) {
value, ok := h[k]
if ok {
oldVa... | @@ -0,0 +1,39 @@
+package core
+
+import (
+ "errors"
+
+ orderedmap "github.com/wk8/go-ordered-map/v2"
+)
+
+type HMap = *orderedmap.OrderedMap[string, string]
+
+func hashMapBuilder(args []string, currentHashMap HMap) (HMap, int64, error) { | core/hmap.go | 11 | Go | 0.643 | suggestion | 204 | 36 | 36 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | lucifercr07 | kolharsam | Review this pull request change.
Language: Go
File: core/hmap.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: package core
import (
"errors"
orderedmap "github.com/wk8/go-ordered-map/v2"
)
type HMap = *orderedmap.OrderedMap[string, string]
func hashMapBuilder(args []string, currentHashMap HMap) (HMap... | Is passing `args[]` required here? Asking as we're any ways doing `iter := 1`
Instead of passing the entire args slice, shall we pass only pass key-value pairs?
With call as `keyValuePairs := args[1:]`. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
numKeys = lengthKeys
}
default:
return Encode(errors.New("ERR key provided does not store a hashmap"), false)
}
} else {
newMap, keysInMap, err := hashMapBuilder(args, nil)
if err != nil {
return Encode(err, false)
}
hashMap = newMap
numKeys = keysInMap
}
hValue := string(Encode(hashMap, ... | We shall use `diceerrors` package for standardization. | }
if isReplace {
store.Del(destinationKey)
}
destinationObj := store.Get(destinationKey)
if destinationObj != nil {
return RespZero
}
copyObj := sourceObj.DeepCopy()
if copyObj == nil {
return RespZero
}
exp, ok := getExpiry(sourceObj, store)
var exDurationMs int64 = -1
if ok {
exDurationMs = in... | @@ -2136,6 +2136,89 @@ func evalPTTL(args []string, store *Store) []byte {
return Encode(int64(durationMs), false)
}
+// evalHSET sets the specified fields to their
+// respective values in an hashmap stored at key
+//
+// This command overwrites the values of specified
+// fields that exist in the hash.
+//
+// I... | core/eval.go | 26 | Go | 0.571 | suggestion | 54 | 51 | 51 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | lucifercr07 | kolharsam | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: numKeys = lengthKeys
}
default:
return Encode(errors.New("ERR key provided does not store a hashmap"), false)
}
} else {
newMap, keysInMap, err := hashMapBuilder(args, nil)
if er... | We shall use `diceerrors` package for standardization. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
import (
"errors"
orderedmap "github.com/wk8/go-ordered-map/v2"
)
type HMap = *orderedmap.OrderedMap[string, string]
func hashMapBuilder(args []string, currentHashMap HMap) (HMap, int64, error) {
var hmap HMap
var numKeysNewlySet int64
if currentHashMap == nil {
hmap = orderedmap.New[string, st... | Do not use NOTE annotation for this purpose.
```suggestion
iter := 1 // to move past args[0] (aka key) within args
``` | package core
import (
"fmt"
"github.com/dicedb/dice/core/diceerrors"
)
type HashMap map[string]string
func (h HashMap) Get(k string) (*string, bool) {
value, ok := h[k]
if !ok {
return nil, false
}
return &value, true
}
func (h HashMap) Set(k, v string) (*string, bool) {
value, ok := h[k]
if ok {
oldVa... | @@ -0,0 +1,39 @@
+package core
+
+import (
+ "errors"
+
+ orderedmap "github.com/wk8/go-ordered-map/v2"
+)
+
+type HMap = *orderedmap.OrderedMap[string, string]
+
+func hashMapBuilder(args []string, currentHashMap HMap) (HMap, int64, error) {
+ var hmap HMap
+ var numKeysNewlySet int64
+
+ if currentHashMap == nil {
+ ... | core/hmap.go | 21 | Go | 0.786 | suggestion | 122 | 40 | 46 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | JyotinderSingh | kolharsam | Review this pull request change.
Language: Go
File: core/hmap.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: package core
import (
"errors"
orderedmap "github.com/wk8/go-ordered-map/v2"
)
type HMap = *orderedmap.OrderedMap[string, string]
func hashMapBuilder(args []string, currentHashMap HMap) (HMap... | Do not use NOTE annotation for this purpose.
```suggestion
iter := 1 // to move past args[0] (aka key) within args
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// respective values in an hashmap stored at key
//
// This command overwrites the values of specified
// fields that exist in the hash.
//
// If key doesn't exist, a new key holding a hash is created.
//
// Usage: HSET key field value [field value ...]
func evalHSET(args []string, store *Store) []byte {
if len(args) ... | I believe if the key is already associated with another type, it should throw error as below
> (error) WRONGTYPE Operation against a key holding the wrong kind of value
We can do
`return diceerrors.NewErrWithMessage(diceerrors.WrongTypeErr)` | // RESP encoded -1 in case no expiration is set on the key
func evalPTTL(args []string, store *Store) []byte {
if len(args) != 1 {
return diceerrors.NewErrArity("PTTL")
}
key := args[0]
obj := store.Get(key)
if obj == nil {
return RespMinusTwo
}
exp, isExpirySet := getExpiry(obj, store)
if !isExpirySet... | @@ -2314,6 +2314,51 @@ func evalPTTL(args []string, store *Store) []byte {
return Encode(int64(durationMs), false)
}
+// evalHSET sets the specified fields to their
+// respective values in an hashmap stored at key
+//
+// This command overwrites the values of specified
+// fields that exist in the hash.
+//
+// I... | core/eval.go | 26 | Go | 0.786 | bug | 245 | 51 | 51 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | lucifercr07 | kolharsam | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: // respective values in an hashmap stored at key
//
// This command overwrites the values of specified
// fields that exist in the hash.
//
// If key doesn't exist, a new key holding a hash is crea... | I believe if the key is already associated with another type, it should throw error as below
> (error) WRONGTYPE Operation against a key holding the wrong kind of value
We can do
`return diceerrors.NewErrWithMessage(diceerrors.WrongTypeErr)` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
if ok {
oldValue := value
h[k] = v
return &oldValue, true
}
h[k] = v
return nil, false
}
func hashMapBuilder(keyValuePairs []string, currentHashMap HashMap) (HashMap, int64, error) {
var hmap HashMap
var numKeysNewlySet int64
if currentHashMap == nil {
hmap = make(HashMap)
} else {
hmap = currentHa... | Error message shouldn't be associated with 1 command type ideally. If we're planning to allow this class to used by other command types like `HMSET, HPERSIST` etc. | func (h HashMap) Set(k, v string) (*string, bool) {
value, ok := h[k]
if ok {
oldValue := value
h[k] = v
return &oldValue, true
}
h[k] = v
return nil, false
}
func hashMapBuilder(keyValuePairs []string, currentHashMap HashMap) (HashMap, int64, error) {
var hmap HashMap
var numKeysNewlySet int64
if curr... | @@ -0,0 +1,82 @@
+package core
+
+import (
+ "errors"
+)
+
+type HashMap map[string]string
+
+func (h HashMap) Get(k string) (*string, bool) {
+ value, ok := h[k]
+ if !ok {
+ return nil, false
+ }
+ return &value, true
+}
+
+func (h HashMap) Set(k, v string) (*string, bool) {
+ value, ok := h[k]
+ if ok {
+ oldValue... | core/hmap.go | 26 | Go | 0.714 | suggestion | 163 | 51 | 51 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | lucifercr07 | kolharsam | Review this pull request change.
Language: Go
File: core/hmap.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: if ok {
oldValue := value
h[k] = v
return &oldValue, true
}
h[k] = v
return nil, false
}
func hashMapBuilder(keyValuePairs []string, currentHashMap HashMap) (HashMap, int64, error) {
v... | Error message shouldn't be associated with 1 command type ideally. If we're planning to allow this class to used by other command types like `HMSET, HPERSIST` etc. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
}
iter += 2
}
return hmap, numKeysNewlySet, nil
}
//nolint:unused
func getValueFromHashMap(key, field string, store *Store) ([]byte, error) {
var value string
obj := store.Get(key)
if obj == nil {
return RespNIL, nil
}
switch currentVal := obj.Value.(type) {
case HashMap:
val, present := currentVal... | Instead of `errors.New` we can do `diceerrors.NewErr(diceerrors.WrongTypeErr)` | if !present {
numKeysNewlySet++
}
iter += 2
}
return hmap, numKeysNewlySet, nil
}
//nolint:unused
func getValueFromHashMap(key, field string, store *Store) ([]byte, error) {
var value string
obj := store.Get(key)
if obj == nil {
return RespNIL, nil
}
switch currentVal := obj.Value.(type) {
case ... | @@ -0,0 +1,82 @@
+package core
+
+import (
+ "errors"
+)
+
+type HashMap map[string]string
+
+func (h HashMap) Get(k string) (*string, bool) {
+ value, ok := h[k]
+ if !ok {
+ return nil, false
+ }
+ return &value, true
+}
+
+func (h HashMap) Set(k, v string) (*string, bool) {
+ value, ok := h[k]
+ if ok {
+ oldValue... | core/hmap.go | 26 | Go | 0.571 | bug | 78 | 31 | 33 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | lucifercr07 | kolharsam | Review this pull request change.
Language: Go
File: core/hmap.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: }
iter += 2
}
return hmap, numKeysNewlySet, nil
}
//nolint:unused
func getValueFromHashMap(key, field string, store *Store) ([]byte, error) {
var value string
obj := store.Get(key)
if ... | Instead of `errors.New` we can do `diceerrors.NewErr(diceerrors.WrongTypeErr)` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
var b []byte
buf := bytes.NewBuffer(b)
for _, b := range value.([]int64) {
buf.Write(Encode(b, false))
}
return []byte(fmt.Sprintf("*%d\r\n%s", len(v), buf.Bytes()))
case error:
return []byte(fmt.Sprintf("-%s\r\n", v))
case WatchEvent:
var b []byte
buf := bytes.NewBuffer(b)
we := value.(WatchEven... | Is this being used somewhere yet? | var b []byte
buf := bytes.NewBuffer(b)
for _, b := range value.([]int64) {
buf.Write(Encode(b, false))
}
return []byte(fmt.Sprintf("*%d\r\n%s", len(v), buf.Bytes()))
case error:
return []byte(fmt.Sprintf("-%s\r\n", v))
case WatchEvent:
var b []byte
buf := bytes.NewBuffer(b)
we := value.(WatchEven... | @@ -228,6 +228,17 @@ func Encode(value interface{}, isSimple bool) []byte {
buf.Write(Encode(row.Value.Value, false))
}
return []byte(fmt.Sprintf("*%d\r\n%s", len(v), buf.Bytes()))
+ case HashMap: | core/resp.go | 26 | Go | 0.143 | question | 33 | 42 | 33 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | JyotinderSingh | kolharsam | Review this pull request change.
Language: Go
File: core/resp.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: var b []byte
buf := bytes.NewBuffer(b)
for _, b := range value.([]int64) {
buf.Write(Encode(b, false))
}
return []byte(fmt.Sprintf("*%d\r\n%s", len(v), buf.Bytes()))
case error:
ret... | Is this being used somewhere yet? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
case WatchEvent:
var b []byte
buf := bytes.NewBuffer(b)
we := value.(WatchEvent)
buf.Write(Encode(fmt.Sprintf("key:%s", we.Key), false))
buf.Write(Encode(fmt.Sprintf("op:%s", we.Operation), false))
buf.Write(Encode(we.Value.Value, false))
return []byte(fmt.Sprintf("*3\r\n%s", buf.Bytes()))
case []DSQLQu... | No need to count elements this way, you can simply do a len(hashmap) to find the number of key value pairs | package core
import (
"bytes"
"fmt"
"io"
"strconv"
"github.com/dicedb/dice/internal/constants"
)
func readLength(buf *bytes.Buffer) (int64, error) {
s, err := readStringUntilSr(buf)
if err != nil {
return 0, err
}
v, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return 0, err
}
return v, nil
}... | @@ -228,6 +228,17 @@ func Encode(value interface{}, isSimple bool) []byte {
buf.Write(Encode(row.Value.Value, false))
}
return []byte(fmt.Sprintf("*%d\r\n%s", len(v), buf.Bytes()))
+ case HashMap:
+ var b []byte
+ buf := bytes.NewBuffer(b)
+ hashMap := value.(HashMap)
+ numOfKeyValuePairs := 0
+ for key,... | core/resp.go | 26 | Go | 0.357 | suggestion | 106 | 34 | 238 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | JyotinderSingh | kolharsam | Review this pull request change.
Language: Go
File: core/resp.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: case WatchEvent:
var b []byte
buf := bytes.NewBuffer(b)
we := value.(WatchEvent)
buf.Write(Encode(fmt.Sprintf("key:%s", we.Key), false))
buf.Write(Encode(fmt.Sprintf("op:%s", we.Operatio... | No need to count elements this way, you can simply do a len(hashmap) to find the number of key value pairs | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
key := args[0]
obj := store.Get(key)
var hashMap HashMap
var numKeys int64
if obj != nil {
switch currentVal := obj.Value.(type) {
case HashMap:
hashMap = currentVal
default:
return diceerrors.NewErrWithMessage(diceerrors.WrongTypeErr)
}
}
keyValuePairs := args[1:]
hashMap, numKeys, err := has... | We generate the hValue but don't really store it anywhere? If you are only using it to deduce the type encoding - that is probably not required (and you could directly store the exact type and encoding into the object since you know the object is an hmap) | key := args[0]
obj := store.Get(key)
var hashMap HashMap
var numKeys int64
if obj != nil {
switch currentVal := obj.Value.(type) {
case HashMap:
hashMap = currentVal
default:
return diceerrors.NewErrWithMessage(diceerrors.WrongTypeErr)
}
}
keyValuePairs := args[1:]
hashMap, numKeys, err := has... | @@ -2341,6 +2341,51 @@ func evalPTTL(args []string, store *Store) []byte {
return Encode(int64(durationMs), false)
}
+// evalHSET sets the specified fields to their
+// respective values in an hashmap stored at key
+//
+// This command overwrites the values of specified
+// fields that exist in the hash.
+//
+// I... | core/eval.go | 26 | Go | 0.643 | suggestion | 255 | 51 | 51 | false | #255: Implement `HSET` command | 373 | DiceDB/dice | 10,326 | C | JyotinderSingh | kolharsam | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #255: Implement `HSET` command
BEFORE CODE: key := args[0]
obj := store.Get(key)
var hashMap HashMap
var numKeys int64
if obj != nil {
switch currentVal := obj.Value.(type) {
case HashMap:
hashMap = currentVal
default:
re... | We generate the hValue but don't really store it anywhere? If you are only using it to deduce the type encoding - that is probably not required (and you could directly store the exact type and encoding into the object since you know the object is an hmap) | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
import (
"bytes"
"errors"
"fmt"
"math"
"strconv"
"strings"
"syscall"
"time"
"github.com/bytedance/sonic"
"github.com/charmbracelet/log"
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/core/bit"
"github.com/dicedb/dice/core/diceerrors"
"github.com/dicedb/dice/internal/constants"
"gi... | Ideally this should be atomic, however, this will be a non-issue once we have the shared-nothing multi-threaded approach in-place. So ignoring this for now. | }
// GETSET atomically sets key to value and returns the old value stored at key.
// Returns an error when key exists but does not hold a string value.
// Any previous time to live associated with the key is
// discarded on successful SET operation.
//
// Returns:
// Bulk string reply: the old value stored at the key.... | @@ -2287,3 +2287,33 @@ func evalLPOP(args []string, store *Store) []byte {
return Encode(x, false)
}
+
+// GETSET atomically sets key to value and returns the old value stored at key.
+// Returns an error when key exists but does not hold a string value.
+// Any previous time to live associated with the key is
+//... | core/eval.go | 26 | Go | 0.571 | suggestion | 156 | 2,320 | 51 | false | #276: GETSET command implementation | 377 | DiceDB/dice | 10,326 | C | JyotinderSingh | lucifercr07 | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #276: GETSET command implementation
BEFORE CODE: package core
import (
"bytes"
"errors"
"fmt"
"math"
"strconv"
"strings"
"syscall"
"time"
"github.com/bytedance/sonic"
"github.com/charmbracelet/log"
"github.com/dicedb/dice/config... | Ideally this should be atomic, however, this will be a non-issue once we have the shared-nothing multi-threaded approach in-place. So ignoring this for now. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
if err != nil {
if err == ErrDequeEmpty {
return RespNIL
}
panic(fmt.Sprintf("unknown error: %v", err))
}
return Encode(x, false)
}
func evalFLUSHDB(args []string, store *Store) []byte {
log.Info(args)
if len(args) > 1 {
return diceerrors.NewErrArity("FLUSHDB")
}
flushType := constants.Sync
if len... | ```suggestion
case constants.Sync, constants.Async:
store.ResetStore()
``` | obj := store.Get(args[0])
if obj == nil {
return RespNIL
}
if err := assertType(obj.TypeEncoding, ObjTypeByteList); err != nil {
return Encode(err, false)
}
if err := assertEncoding(obj.TypeEncoding, ObjEncodingDeque); err != nil {
return Encode(err, false)
}
deq := obj.Value.(*Deque)
x, err := deq.LP... | @@ -2287,3 +2287,26 @@ func evalLPOP(args []string, store *Store) []byte {
return Encode(x, false)
}
+
+func evalFLUSHDB(args []string, store *Store) []byte {
+ log.Info(args)
+ if len(args) > 1 {
+ return diceerrors.NewErrArity("FLUSHDB")
+ }
+
+ flushType := constants.Sync
+ if len(args) == 1 {
+ flushType = s... | core/eval.go | 26 | Go | 0.571 | suggestion | 80 | 33 | 47 | false | Added support for FLUSHDB command | 390 | DiceDB/dice | 10,326 | C | JyotinderSingh | ashwaniYDV | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: Added support for FLUSHDB command
BEFORE CODE: if err != nil {
if err == ErrDequeEmpty {
return RespNIL
}
panic(fmt.Sprintf("unknown error: %v", err))
}
return Encode(x, false)
}
func evalFLUSHDB(args []string, store *Store) []... | ```suggestion
case constants.Sync, constants.Async:
store.ResetStore()
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
import (
"bytes"
"errors"
"fmt"
"math"
"strconv"
"strings"
"syscall"
"time"
"github.com/bytedance/sonic"
"github.com/charmbracelet/log"
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/core/bit"
"github.com/dicedb/dice/core/diceerrors"
"github.com/dicedb/dice/internal/constants"
"gi... | ```suggestion
// TODO: Update this method to work with shared-nothing multithreaded implementation
switch flushType {
``` |
deq := obj.Value.(*Deque)
x, err := deq.LPop()
if err != nil {
if err == ErrDequeEmpty {
return RespNIL
}
panic(fmt.Sprintf("unknown error: %v", err))
}
return Encode(x, false)
}
func evalFLUSHDB(args []string, store *Store) []byte {
log.Info(args)
if len(args) > 1 {
return diceerrors.NewErrArity("... | @@ -2287,3 +2287,26 @@ func evalLPOP(args []string, store *Store) []byte {
return Encode(x, false)
}
+
+func evalFLUSHDB(args []string, store *Store) []byte {
+ log.Info(args)
+ if len(args) > 1 {
+ return diceerrors.NewErrArity("FLUSHDB")
+ }
+
+ flushType := constants.Sync
+ if len(args) == 1 {
+ flushType = s... | core/eval.go | 26 | Go | 0.857 | suggestion | 133 | 2,313 | 35 | false | Added support for FLUSHDB command | 390 | DiceDB/dice | 10,326 | C | JyotinderSingh | ashwaniYDV | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: Added support for FLUSHDB command
BEFORE CODE: package core
import (
"bytes"
"errors"
"fmt"
"math"
"strconv"
"strings"
"syscall"
"time"
"github.com/bytedance/sonic"
"github.com/charmbracelet/log"
"github.com/dicedb/dice/config"
... | ```suggestion
// TODO: Update this method to work with shared-nothing multithreaded implementation
switch flushType {
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
import (
"errors"
"sync"
"unsafe"
)
var (
MaxQueueSize = 10000
MaxQueues = 1000
)
var (
QueueCount = 0
muQueue sync.Mutex
)
type QueueRef struct {
qi *QueueInt
}
type QueueElement struct {
Key string
Obj *Obj
}
func NewQueueRef() (*QueueRef, error) {
muQueue.Lock()
defer muQueue.Unl... | These should be a part of the config instead of being global variables. | package core
import (
"sync"
"unsafe"
"github.com/dicedb/dice/core/diceerrors"
)
const (
MaxQueueSize = 10000
MaxQueues = 1000
)
var (
QueueCount = 0
muQueue sync.Mutex
)
type QueueRef struct {
qi *QueueInt
}
type QueueElement struct {
Key string
Obj *Obj
}
func NewQueueRef() (*QueueRef, error) {... | @@ -1,9 +1,21 @@
package core
import (
+ "errors"
+ "sync"
"unsafe"
)
+var (
+ MaxQueueSize = 10000
+ MaxQueues = 1000
+) | core/queueref.go | 12 | Go | 0.286 | suggestion | 71 | 37 | 37 | false | #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key | 393 | DiceDB/dice | 10,326 | C | JyotinderSingh | kushal0511-not | Review this pull request change.
Language: Go
File: core/queueref.go
PR Title: #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key
BEFORE CODE: package core
import (
"errors"
"sync"
"unsafe"
)
var (
MaxQueueSize = 10000
MaxQueues = 1000
)
var (
QueueCount = 0
muQueue sync.Mut... | These should be a part of the config instead of being global variables. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
return elements
}
func (s *StackRef) DeepCopy() *StackRef {
return &StackRef{
si: s.si.DeepCopy(),
}
}
// StackRefCleanup removes expired or deleted keys from the StackRef to maintain the accuracy of STACKREFLEN operations.
// While this process ensures correctness, it can be computationally intensive, especiall... | Rebase on the latest master please, we no longer use unsafe pointers in the codebase. | }
}
return elements
}
func (s *StackRef) DeepCopy() *StackRef {
return &StackRef{
si: s.si.DeepCopy(),
}
}
// StackRefCleanup removes expired or deleted keys from the StackRef to maintain the accuracy of STACKREFLEN operations.
// While this process ensures correctness, it can be computationally intensive, es... | @@ -81,3 +111,29 @@ func (s *StackRef) DeepCopy() *StackRef {
si: s.si.DeepCopy(),
}
}
+
+// StackRefCleanup removes expired or deleted keys from the StackRef to maintain the accuracy of STACKREFLEN operations.
+// While this process ensures correctness, it can be computationally intensive, especially as
+// the ... | core/stackref.go | 26 | Go | 0.286 | suggestion | 85 | 35 | 37 | false | #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key | 393 | DiceDB/dice | 10,326 | C | JyotinderSingh | kushal0511-not | Review this pull request change.
Language: Go
File: core/stackref.go
PR Title: #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key
BEFORE CODE: return elements
}
func (s *StackRef) DeepCopy() *StackRef {
return &StackRef{
si: s.si.DeepCopy(),
}
}
// StackRefCleanup removes expired or ... | Rebase on the latest master please, we no longer use unsafe pointers in the codebase. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
Host string = "0.0.0.0"
Port int = 7379
)
var KeysLimit int = 10000 // default buffer size.
// Will evict EvictionRatio of keys whenever eviction runs
var (
EvictionRatio float64 = 0.40
EvictionStrategy string = "allkeys-lru"
AOFFile string = "./dice-master.aof"
)
// Network
var (
IOBufferLeng... | Can we move these to queueref.go and declare them as constants? | Host string = "0.0.0.0"
Port int = 7379
)
var KeysLimit int = 10000 // default buffer size.
// Will evict EvictionRatio of keys whenever eviction runs
var (
EvictionRatio float64 = 0.40
EvictionStrategy string = "allkeys-lru"
AOFFile string = "./dice-master.aof"
)
// Network
var (
IOBufferLeng... | @@ -27,3 +27,13 @@ var (
// If requirepass is set to an empty string, no authentication is required
RequirePass string = constants.EmptyStr
)
+
+var ( | config/main.go | 26 | Go | 0.286 | question | 63 | 35 | 26 | false | #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key | 393 | DiceDB/dice | 10,326 | C | soumya-codes | kushal0511-not | Review this pull request change.
Language: Go
File: config/main.go
PR Title: #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key
BEFORE CODE: Host string = "0.0.0.0"
Port int = 7379
)
var KeysLimit int = 10000 // default buffer size.
// Will evict EvictionRatio of keys whenever evicti... | Can we move these to queueref.go and declare them as constants? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// Will evict EvictionRatio of keys whenever eviction runs
var (
EvictionRatio float64 = 0.40
EvictionStrategy string = "allkeys-lru"
AOFFile string = "./dice-master.aof"
)
// Network
var (
IOBufferLength int = 512
IOBufferLengthMAX int = 50 * 1024
)
// Users and ACLs
var (
// If requirepass is... | Can we move these to stackref.go and declare them as constants? | package config
import "github.com/dicedb/dice/internal/constants"
var (
Host string = "0.0.0.0"
Port int = 7379
)
var KeysLimit int = 10000 // default buffer size.
// Will evict EvictionRatio of keys whenever eviction runs
var (
EvictionRatio float64 = 0.40
EvictionStrategy string = "allkeys-lru"
AOFFil... | @@ -27,3 +27,13 @@ var (
// If requirepass is set to an empty string, no authentication is required
RequirePass string = constants.EmptyStr
)
+
+var (
+ MaxQueueSize = 10000
+ MaxQueues = 1000
+)
+
+var (
+ MaxStackSize = 10000 | config/main.go | 26 | Go | 0.286 | question | 63 | 29 | 31 | false | #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key | 393 | DiceDB/dice | 10,326 | C | soumya-codes | kushal0511-not | Review this pull request change.
Language: Go
File: config/main.go
PR Title: #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key
BEFORE CODE: // Will evict EvictionRatio of keys whenever eviction runs
var (
EvictionRatio float64 = 0.40
EvictionStrategy string = "allkeys-lru"
AOFFile ... | Can we move these to stackref.go and declare them as constants? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
return Encode(err, false)
}
if err := assertEncoding(obj.TypeEncoding, ObjEncodingStackInt); err != nil {
return Encode(err, false)
}
s := obj.Value.(*StackInt)
return Encode(s.Iterate(int(num)), false)
}
// evalQREFINS inserts the reference of the provided key identified by key
// first argument will be th... | We need to move to the new error wrappers. Please change in other places as well. | return diceerrors.NewErrSetType()
}
if err := assertEncoding(obj.TypeEncoding, ObjEncodingStackInt); err != nil {
return diceerrors.NewErrSetType()
}
s := obj.Value.(*StackInt)
return Encode(s.Iterate(int(num)), false)
}
// evalQREFINS inserts the reference of the provided key identified by key
// first arg... | @@ -1110,8 +1110,12 @@ func evalQREFINS(args []string, store *Store) []byte {
}
obj := store.Get(args[0])
+ qr, err := NewQueueRef()
+ if err != nil {
+ return Encode(err, false) | core/eval.go | 26 | Go | 0.429 | suggestion | 81 | 51 | 51 | false | #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key | 393 | DiceDB/dice | 10,326 | C | soumya-codes | kushal0511-not | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key
BEFORE CODE: return Encode(err, false)
}
if err := assertEncoding(obj.TypeEncoding, ObjEncodingStackInt); err != nil {
return Encode(err, false)
}
s := obj... | We need to move to the new error wrappers. Please change in other places as well. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
}
// Returns the length of the queue
func (q *QueueRef) Length(store *Store) int64 {
q.QueueRefCleanup(store)
return q.qi.Length
}
// QueueRefCleanup removes expired or deleted keys from the QueueRef to maintain the accuracy of QUEUEREFLEN operations.
// While this process ensures correctness, it can be computation... | As we are moving away from unsafe.Pointer in general, it is good to avoid it. Since this is not something introduced in this change and needs a bigger refactoring it may be good to open an issue to track this.
Can you please open an issue to move Stack and Queue and Dequeue from using unsafe pointers? | func (q *QueueRef) DeepCopy() *QueueRef {
return &QueueRef{
qi: q.qi.DeepCopy(),
}
}
// Returns the length of the queue
func (q *QueueRef) Length(store *Store) int64 {
q.QueueRefCleanup(store)
return q.qi.Length
}
// QueueRefCleanup removes expired or deleted keys from the QueueRef to maintain the accuracy of Q... | @@ -82,6 +100,32 @@ func (q *QueueRef) DeepCopy() *QueueRef {
}
// Returns the length of the queue
-func (q *QueueRef) Length() int64 {
+func (q *QueueRef) Length(store *Store) int64 {
+ q.QueueRefCleanup(store)
return q.qi.Length
}
+
+// QueueRefCleanup removes expired or deleted keys from the QueueRef to maint... | core/queueref.go | 26 | Go | 0.5 | refactor | 305 | 33 | 37 | false | #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key | 393 | DiceDB/dice | 10,326 | C | soumya-codes | kushal0511-not | Review this pull request change.
Language: Go
File: core/queueref.go
PR Title: #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key
BEFORE CODE: }
// Returns the length of the queue
func (q *QueueRef) Length(store *Store) int64 {
q.QueueRefCleanup(store)
return q.qi.Length
}
// QueueRefCl... | As we are moving away from unsafe.Pointer in general, it is good to avoid it. Since this is not something introduced in this change and needs a bigger refactoring it may be good to open an issue to track this.
Can you please open an issue to move Stack and Queue and Dequeue from using unsafe pointers? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
Host string = "0.0.0.0"
Port int = 7379
)
var KeysLimit int = 10000 // default buffer size.
// Will evict EvictionRatio of keys whenever eviction runs
var (
EvictionRatio float64 = 0.40
EvictionStrategy string = "allkeys-lru"
AOFFile string = "./dice-master.aof"
)
// Network
var (
IOBufferLeng... | Even if this is a global variable, lets move it to its specific file. | Host string = "0.0.0.0"
Port int = 7379
)
var KeysLimit int = 10000 // default buffer size.
// Will evict EvictionRatio of keys whenever eviction runs
var (
EvictionRatio float64 = 0.40
EvictionStrategy string = "allkeys-lru"
AOFFile string = "./dice-master.aof"
)
// Network
var (
IOBufferLeng... | @@ -27,3 +27,5 @@ var (
// If requirepass is set to an empty string, no authentication is required
RequirePass string = constants.EmptyStr
)
+
+var MaxStacks = 1000 | config/main.go | 26 | Go | 0.286 | suggestion | 69 | 27 | 26 | false | #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key | 393 | DiceDB/dice | 10,326 | C | soumya-codes | kushal0511-not | Review this pull request change.
Language: Go
File: config/main.go
PR Title: #285: Fix: STACKREFLEN and QUEUEREFLEN is not aware of the deletion of key
BEFORE CODE: Host string = "0.0.0.0"
Port int = 7379
)
var KeysLimit int = 10000 // default buffer size.
// Will evict EvictionRatio of keys whenever evicti... | Even if this is a global variable, lets move it to its specific file. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package core
import (
"sync"
)
var mu sync.Mutex
var cycle uint32 = 0
var counter uint32 = 0
var turn uint32 = 0
var totalBits int = 32
var turnBits int = 8
var counterBits int = totalBits - turnBits
func ExpandID(id uint32) uint64 {
return uint64(cycle)<<counterBits | uint64(counter)
}
// TODO: Persisting the c... | Is **id** really required in the parameter ? | package core
import (
"sync"
)
var mu sync.Mutex
var turn, cycle, counter uint32 = 0, 0, 0
var totalBits uint32 = 32
var turnBits uint32 = 4
var counterBits uint32 = totalBits - turnBits
var cycleMap []uint32
func init() {
cycleMap = make([]uint32, 1<<turnBits)
}
func ExpandID(id uint32) uint64 {
var _id uint6... | @@ -0,0 +1,31 @@
+package core
+
+import (
+ "sync"
+)
+
+var mu sync.Mutex
+var cycle uint32 = 0
+var counter uint32 = 0
+var turn uint32 = 0
+
+var totalBits int = 32
+var turnBits int = 8
+var counterBits int = totalBits - turnBits
+
+func ExpandID(id uint32) uint64 { | core/id.go | 20 | Go | 0.071 | question | 44 | 32 | 39 | false | The new ID implementation | 396 | DiceDB/dice | 10,326 | C | princejha95 | arpitbbhayani | Review this pull request change.
Language: Go
File: core/id.go
PR Title: The new ID implementation
BEFORE CODE: package core
import (
"sync"
)
var mu sync.Mutex
var cycle uint32 = 0
var counter uint32 = 0
var turn uint32 = 0
var totalBits int = 32
var turnBits int = 8
var counterBits int = totalBits - turnBits
... | Is **id** really required in the parameter ? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
for i := range subCommands {
subCommand := strings.ToUpper(subCommands[i])
switch subCommand {
case constants.NX:
nxCmd = true
if prevExpiry != nil {
shouldSetExpiry = false
}
case constants.XX:
xxCmd = true
if prevExpiry == nil {
shouldSetExpiry = false
}
case constants.GT:
gtC... | Please use the error builder utilities to form the error messages. You can refer to other such usages in the code for guidance.
Same for other instances. | for i := range subCommands {
subCommand := strings.ToUpper(subCommands[i])
switch subCommand {
case constants.NX:
nxCmd = true
if prevExpiry != nil {
shouldSetExpiry = false
}
case constants.XX:
xxCmd = true
if prevExpiry == nil {
shouldSetExpiry = false
}
case constants.GT:
gtC... | @@ -652,22 +655,85 @@ func evalEXPIREAT(args []string, store *Store) []byte {
}
var key string = args[0]
- exUnixTimeSec, err := strconv.ParseInt(args[1], 10, 64)
+ exUnixTimeSec, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return Encode(errors.New("ERR value is not an integer or out of range")... | core/eval.go | 26 | Go | 0.571 | suggestion | 154 | 51 | 51 | false | #355: FEAT: Added support for additional options in EXPIRE and EXPIREAT. | 403 | DiceDB/dice | 10,326 | C | JyotinderSingh | raghavbabbar | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #355: FEAT: Added support for additional options in EXPIRE and EXPIREAT.
BEFORE CODE: for i := range subCommands {
subCommand := strings.ToUpper(subCommands[i])
switch subCommand {
case constants.NX:
nxCmd = true
if prevExpiry ... | Please use the error builder utilities to form the error messages. You can refer to other such usages in the code for guidance.
Same for other instances. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
return Encode(obj.Value, false)
}
// evalJSONCLEAR Clear container values (arrays/objects) and set numeric values to 0,
// Already cleared values are ignored for empty containers and zero numbers
// args must contain at least the key; (path unused in this implementation)
// Returns encoded error if key is expired or... | Please use the new error utilities to create the error messages, they help in maintaining consistency. You can refer to the other functions in the code which are using them. Same for other places. | return Encode(obj.Value, false)
}
// evalJSONCLEAR Clear container values (arrays/objects) and set numeric values to 0,
// Already cleared values are ignored for empty containers and zero numbers
// args must contain at least the key; (path unused in this implementation)
// Returns encoded error if key is expired or... | @@ -315,14 +315,102 @@ func evalGETDEL(args []string, store *Store) []byte {
return Encode(obj.Value, false)
}
+// evalJSONCLEAR Clear container values (arrays/objects) and set numeric values to 0,
+// Already cleared values are ignored for empty containers and zero numbers
+// args must contain at least the key; ... | core/eval.go | 26 | Go | 0.571 | suggestion | 196 | 51 | 51 | false | #371: feat: add support for command [JSON.CLEAR] | 405 | DiceDB/dice | 10,326 | C | JyotinderSingh | jujiale | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #371: feat: add support for command [JSON.CLEAR]
BEFORE CODE: return Encode(obj.Value, false)
}
// evalJSONCLEAR Clear container values (arrays/objects) and set numeric values to 0,
// Already cleared values are ignored for empty containe... | Please use the new error utilities to create the error messages, they help in maintaining consistency. You can refer to the other functions in the code which are using them. Same for other places. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// Default path is root if not specified
path := defaultRootPath
if len(args) > 1 {
path = args[1]
}
// Retrieve the object from the database
obj := store.Get(key)
if obj == nil {
return diceerrors.NewErrWithMessage("could not perform this operation on a key that doesn't exist")
}
err := assertType(obj.T... | To be consistent with Redis, should we change the error message to "Existing key has wrong Redis type"?
```
redis:6379> SET key abc
OK
redis:6379> JSON.CLEAR key $.*
(error) Existing key has wrong Redis type
``` | // Default path is root if not specified
path := defaultRootPath
if len(args) > 1 {
path = args[1]
}
// Retrieve the object from the database
obj := store.Get(key)
if obj == nil {
return diceerrors.NewErrWithMessage("could not perform this operation on a key that doesn't exist")
}
err := assertType(obj.T... | @@ -315,14 +315,102 @@ func evalGETDEL(args []string, store *Store) []byte {
return Encode(obj.Value, false)
}
+// evalJSONCLEAR Clear container values (arrays/objects) and set numeric values to 0,
+// Already cleared values are ignored for empty containers and zero numbers
+// args must contain at least the key; ... | core/eval.go | 26 | Go | 1 | bug | 219 | 51 | 51 | false | #371: feat: add support for command [JSON.CLEAR] | 405 | DiceDB/dice | 10,326 | C | soumya-codes | jujiale | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #371: feat: add support for command [JSON.CLEAR]
BEFORE CODE: // Default path is root if not specified
path := defaultRootPath
if len(args) > 1 {
path = args[1]
}
// Retrieve the object from the database
obj := store.Get(key)
if o... | To be consistent with Redis, should we change the error message to "Existing key has wrong Redis type"?
```
redis:6379> SET key abc
OK
redis:6379> JSON.CLEAR key $.*
(error) Existing key has wrong Redis type
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// Retrieve the object from the database
obj := store.Get(key)
if obj == nil {
return diceerrors.NewErrWithMessage("could not perform this operation on a key that doesn't exist")
}
err := assertType(obj.TypeEncoding, ObjTypeJSON)
if err != nil {
return Encode(err, false)
}
err = assertEncoding(obj.TypeEnco... | This comment seems a bit misplaced. What are we trying to achieve here? | // Retrieve the object from the database
obj := store.Get(key)
if obj == nil {
return diceerrors.NewErrWithMessage("could not perform this operation on a key that doesn't exist")
}
err := assertType(obj.TypeEncoding, ObjTypeJSON)
if err != nil {
return diceerrors.NewErrWithMessage("Existing key has wrong Dic... | @@ -315,14 +315,102 @@ func evalGETDEL(args []string, store *Store) []byte {
return Encode(obj.Value, false)
}
+// evalJSONCLEAR Clear container values (arrays/objects) and set numeric values to 0,
+// Already cleared values are ignored for empty containers and zero numbers
+// args must contain at least the key; ... | core/eval.go | 26 | Go | 0.214 | question | 71 | 51 | 51 | false | #371: feat: add support for command [JSON.CLEAR] | 405 | DiceDB/dice | 10,326 | C | soumya-codes | jujiale | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #371: feat: add support for command [JSON.CLEAR]
BEFORE CODE: // Retrieve the object from the database
obj := store.Get(key)
if obj == nil {
return diceerrors.NewErrWithMessage("could not perform this operation on a key that doesn't ex... | This comment seems a bit misplaced. What are we trying to achieve here? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// Returns encoded error response if incorrect number of arguments
// Returns an integer reply specifying the number of matching JSON arrays
// and objects cleared + number of matching JSON numerical values zeroed.
func evalJSONCLEAR(args []string, store *Store) []byte {
if len(args) < 1 {
return diceerrors.NewErrAr... | Can you please explain this assertion?
In what scenario would Object be of type JSON and encoding wouldn't be of type JSON? | // Returns encoded error response if incorrect number of arguments
// Returns an integer reply specifying the number of matching JSON arrays
// and objects cleared + number of matching JSON numerical values zeroed.
func evalJSONCLEAR(args []string, store *Store) []byte {
if len(args) < 1 {
return diceerrors.NewErrAr... | @@ -315,14 +315,102 @@ func evalGETDEL(args []string, store *Store) []byte {
return Encode(obj.Value, false)
}
+// evalJSONCLEAR Clear container values (arrays/objects) and set numeric values to 0,
+// Already cleared values are ignored for empty containers and zero numbers
+// args must contain at least the key; ... | core/eval.go | 26 | Go | 0.5 | question | 124 | 51 | 51 | false | #371: feat: add support for command [JSON.CLEAR] | 405 | DiceDB/dice | 10,326 | C | soumya-codes | jujiale | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #371: feat: add support for command [JSON.CLEAR]
BEFORE CODE: // Returns encoded error response if incorrect number of arguments
// Returns an integer reply specifying the number of matching JSON arrays
// and objects cleared + number of ma... | Can you please explain this assertion?
In what scenario would Object be of type JSON and encoding wouldn't be of type JSON? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// args must contain at least the key; (path unused in this implementation)
// Returns encoded error if key is expired or it does not exist
// Returns encoded error response if incorrect number of arguments
// Returns an integer reply specifying the number of matching JSON arrays
// and objects cleared + number of mat... | To be consistent with Redis, should we return error message "Existing key has wrong Redis type"?
```
redis:6379> SET doc '{"obj":{"a":1, "b":2}, "arr":[1,2,3], "str": "foo", "bool": true, "int": 42, "float": 3.14}'
OK
redis:6379> JSON.GET doc $
(error) Existing key has wrong Redis type
``` | // args must contain at least the key; (path unused in this implementation)
// Returns encoded error if key is expired or it does not exist
// Returns encoded error response if incorrect number of arguments
// Returns an integer reply specifying the number of matching JSON arrays
// and objects cleared + number of mat... | @@ -315,14 +315,102 @@ func evalGETDEL(args []string, store *Store) []byte {
return Encode(obj.Value, false)
}
+// evalJSONCLEAR Clear container values (arrays/objects) and set numeric values to 0,
+// Already cleared values are ignored for empty containers and zero numbers
+// args must contain at least the key; ... | core/eval.go | 26 | Go | 1 | bug | 296 | 51 | 51 | false | #371: feat: add support for command [JSON.CLEAR] | 405 | DiceDB/dice | 10,326 | C | soumya-codes | jujiale | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #371: feat: add support for command [JSON.CLEAR]
BEFORE CODE: // args must contain at least the key; (path unused in this implementation)
// Returns encoded error if key is expired or it does not exist
// Returns encoded error response if ... | To be consistent with Redis, should we return error message "Existing key has wrong Redis type"?
```
redis:6379> SET doc '{"obj":{"a":1, "b":2}, "arr":[1,2,3], "str": "foo", "bool": true, "int": 42, "float": 3.14}'
OK
redis:6379> JSON.GET doc $
(error) Existing key has wrong Redis type
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
jsonData := obj.Value
_, err = sonic.Marshal(jsonData)
if err != nil {
return diceerrors.NewErrWithMessage("could not serialize result")
}
var countClear uint64 = 0
if len(args) == 1 || path == defaultRootPath {
if jsonData != struct{}{} {
// If path is root and len(args) == 1, return it instantly
new... | Why are we not checking for types such as String, Boolean and Null type? | jsonData := obj.Value
_, err = sonic.Marshal(jsonData)
if err != nil {
return diceerrors.NewErrWithMessage("Existing key has wrong Dice type")
}
var countClear uint64 = 0
if len(args) == 1 || path == defaultRootPath {
if jsonData != struct{}{} {
// If path is root and len(args) == 1, return it instantly
... | @@ -315,14 +315,102 @@ func evalGETDEL(args []string, store *Store) []byte {
return Encode(obj.Value, false)
}
+// evalJSONCLEAR Clear container values (arrays/objects) and set numeric values to 0,
+// Already cleared values are ignored for empty containers and zero numbers
+// args must contain at least the key; ... | core/eval.go | 26 | Go | 0.357 | question | 72 | 51 | 51 | false | #371: feat: add support for command [JSON.CLEAR] | 405 | DiceDB/dice | 10,326 | C | soumya-codes | jujiale | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #371: feat: add support for command [JSON.CLEAR]
BEFORE CODE: jsonData := obj.Value
_, err = sonic.Marshal(jsonData)
if err != nil {
return diceerrors.NewErrWithMessage("could not serialize result")
}
var countClear uint64 = 0
if ... | Why are we not checking for types such as String, Boolean and Null type? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
// and objects cleared + number of matching JSON numerical values zeroed.
func evalJSONCLEAR(args []string, store *Store) []byte {
if len(args) < 1 {
return diceerrors.NewErrArity("JSON.CLEAR")
}
key := args[0]
// Default path is root if not specified
path := defaultRootPath
if len(args) > 1 {
path = args[1]... | ```suggestion
return diceerrors.NewErrWithMessage("Existing key has wrong Dice type")
``` | // and objects cleared + number of matching JSON numerical values zeroed.
func evalJSONCLEAR(args []string, store *Store) []byte {
if len(args) < 1 {
return diceerrors.NewErrArity("JSON.CLEAR")
}
key := args[0]
// Default path is root if not specified
path := defaultRootPath
if len(args) > 1 {
path = args[1]... | @@ -315,14 +315,102 @@ func evalGETDEL(args []string, store *Store) []byte {
return Encode(obj.Value, false)
}
+// evalJSONCLEAR Clear container values (arrays/objects) and set numeric values to 0,
+// Already cleared values are ignored for empty containers and zero numbers
+// args must contain at least the key; ... | core/eval.go | 26 | Go | 0.714 | bug | 93 | 51 | 51 | false | #371: feat: add support for command [JSON.CLEAR] | 405 | DiceDB/dice | 10,326 | C | JyotinderSingh | jujiale | Review this pull request change.
Language: Go
File: core/eval.go
PR Title: #371: feat: add support for command [JSON.CLEAR]
BEFORE CODE: // and objects cleared + number of matching JSON numerical values zeroed.
func evalJSONCLEAR(args []string, store *Store) []byte {
if len(args) < 1 {
return diceerrors.NewErrA... | ```suggestion
return diceerrors.NewErrWithMessage("Existing key has wrong Dice type")
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
}
}
}
// Bit not found in the range
return -1
}
func getBitPosWithBitRange(byteSlice []byte, bitToFind byte, start, end int) int {
for i := start; i <= end; i++ {
// Calculate which byte and bit we're looking at
byteIndex := i / 8
// 7 - (i % 8) because we count bits from left to right in each byte
b... | This looks good. Can we move these functions to a common place like bytearray.go? What do you think? | package core
import (
"errors"
"strconv"
"strings"
"github.com/dicedb/dice/core/diceerrors"
"github.com/dicedb/dice/core/bit"
)
func evalBITPOS(args []string, store *Store) []byte {
if len(args) < 2 || len(args) > 5 {
return diceerrors.NewErrArity("BITPOS")
}
key := args[0]
obj := store.Get(key)
bitTo... | @@ -222,3 +222,47 @@ func getBitPosWithBitRange(byteSlice []byte, bitToFind byte, start, end int) int
// Bit not found in the range
return -1
}
+
+// ByteSliceToObj converts a byte slice to an Obj of the specified type and encoding | core/bitpos.go | 26 | Go | 0.429 | question | 100 | 51 | 179 | false | #386: Fix SETBIT command for encoding | 409 | DiceDB/dice | 10,326 | C | soumya-codes | kushal0511-not | Review this pull request change.
Language: Go
File: core/bitpos.go
PR Title: #386: Fix SETBIT command for encoding
BEFORE CODE: }
}
}
// Bit not found in the range
return -1
}
func getBitPosWithBitRange(byteSlice []byte, bitToFind byte, start, end int) int {
for i := start; i <= end; i++ {
// Calculat... | This looks good. Can we move these functions to a common place like bytearray.go? What do you think? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
log.Info("Password", config.RequirePass)
}
func main() {
setupFlags()
// Handle SIGTERM and SIGINT
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
// Create a wait group to manage goroutines
var wg sync.WaitGroup
// Initialize the AsyncServer
asyncServer := server.NewAs... | ```suggestion
go func() {
defer s.wg.Done()
if err := asyncServer.Run(); err != nil {
``` |
log.Info("Password", config.RequirePass)
}
func main() {
setupFlags()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Handle SIGTERM and SIGINT
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
// Initialize the AsyncServer
asyncServer := server... | @@ -25,28 +25,34 @@ func main() {
setupFlags()
// Handle SIGTERM and SIGINT
- var sigs chan os.Signal = make(chan os.Signal, 1)
+ sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
- // Find a port and bind
- // If port not available, raise FATAL error
- serverFD, err := serv... | main.go | 26 | Go | 0.571 | suggestion | 98 | 39 | 50 | false | Reorganize async server code | 410 | DiceDB/dice | 10,326 | C | soumya-codes | JyotinderSingh | Review this pull request change.
Language: Go
File: main.go
PR Title: Reorganize async server code
BEFORE CODE: log.Info("Password", config.RequirePass)
}
func main() {
setupFlags()
// Handle SIGTERM and SIGINT
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
// Create a... | ```suggestion
go func() {
defer s.wg.Done()
if err := asyncServer.Run(); err != nil {
``` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package server
import (
"context"
"net"
"os"
"sync"
"syscall"
"time"
"github.com/charmbracelet/log"
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/core"
"github.com/dicedb/dice/core/iomultiplexer"
"github.com/dicedb/dice/internal/constants"
"github.com/dicedb/dice/server/utils"
)
type AsyncServe... | Since we need to propagate the wait-group, it may not be good to store it as part of struct.
Compare it with context.
If you feel it is complicated we can create a waitgroup that has only one level depth. | package server
import (
"context"
"errors"
"net"
"os"
"sync"
"syscall"
"time"
"github.com/charmbracelet/log"
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/core"
"github.com/dicedb/dice/core/iomultiplexer"
"github.com/dicedb/dice/internal/constants"
"github.com/dicedb/dice/server/utils"
)
var E... | @@ -17,247 +16,211 @@ import (
"github.com/dicedb/dice/server/utils"
)
-var cronFrequency time.Duration = 1 * time.Second
-var lastCronExecTime time.Time = utils.GetCurrentTime()
-
-const EngineStatusWAITING int32 = 1 << 1
-const EngineStatusBUSY int32 = 1 << 2
-const EngineStatusSHUTTINGDOWN int32 = 1 << 3
-const... | server/async_tcp.go | 23 | Go | 0.429 | suggestion | 206 | 48 | 48 | false | Reorganize async server code | 410 | DiceDB/dice | 10,326 | C | soumya-codes | JyotinderSingh | Review this pull request change.
Language: Go
File: server/async_tcp.go
PR Title: Reorganize async server code
BEFORE CODE: package server
import (
"context"
"net"
"os"
"sync"
"syscall"
"time"
"github.com/charmbracelet/log"
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/core"
"github.com/dicedb... | Since we need to propagate the wait-group, it may not be good to store it as part of struct.
Compare it with context.
If you feel it is complicated we can create a waitgroup that has only one level depth. | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
package server
import (
"context"
"net"
"os"
"sync"
"syscall"
"time"
"github.com/charmbracelet/log"
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/core"
"github.com/dicedb/dice/core/iomultiplexer"
"github.com/dicedb/dice/internal/constants"
"github.com/dicedb/dice/server/utils"
)
type AsyncServe... | Contexts are typically designed to be passed through function calls, not stored long-term.
Also, the general practise is to create context in main() and pass over through different function calls.
| package server
import (
"context"
"errors"
"net"
"os"
"sync"
"syscall"
"time"
"github.com/charmbracelet/log"
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/core"
"github.com/dicedb/dice/core/iomultiplexer"
"github.com/dicedb/dice/internal/constants"
"github.com/dicedb/dice/server/utils"
)
var E... | @@ -17,247 +16,211 @@ import (
"github.com/dicedb/dice/server/utils"
)
-var cronFrequency time.Duration = 1 * time.Second
-var lastCronExecTime time.Time = utils.GetCurrentTime()
-
-const EngineStatusWAITING int32 = 1 << 1
-const EngineStatusBUSY int32 = 1 << 2
-const EngineStatusSHUTTINGDOWN int32 = 1 << 3
-const... | server/async_tcp.go | 21 | Go | 0.357 | suggestion | 199 | 46 | 46 | false | Reorganize async server code | 410 | DiceDB/dice | 10,326 | C | soumya-codes | JyotinderSingh | Review this pull request change.
Language: Go
File: server/async_tcp.go
PR Title: Reorganize async server code
BEFORE CODE: package server
import (
"context"
"net"
"os"
"sync"
"syscall"
"time"
"github.com/charmbracelet/log"
"github.com/dicedb/dice/config"
"github.com/dicedb/dice/core"
"github.com/dicedb... | Contexts are typically designed to be passed through function calls, not stored long-term.
Also, the general practise is to create context in main() and pass over through different function calls.
| You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
func setupFlags() {
flag.StringVar(&config.Host, "host", "0.0.0.0", "host for the dice server")
flag.IntVar(&config.Port, "port", 7379, "port for the dice server")
flag.StringVar(&config.RequirePass, "requirepass", config.RequirePass, "enable authentication for the default user")
flag.Parse()
log.Info("Password",... | nit: I believe this wouldn't be required as program would quit after `log.Fatal` |
func setupFlags() {
flag.StringVar(&config.Host, "host", "0.0.0.0", "host for the dice server")
flag.IntVar(&config.Port, "port", 7379, "port for the dice server")
flag.StringVar(&config.RequirePass, "requirepass", config.RequirePass, "enable authentication for the default user")
flag.Parse()
log.Info("Password"... | @@ -25,28 +25,34 @@ func main() {
setupFlags()
// Handle SIGTERM and SIGINT
- var sigs chan os.Signal = make(chan os.Signal, 1)
+ sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
- // Find a port and bind
- // If port not available, raise FATAL error
- serverFD, err := serv... | main.go | 26 | Go | 0.357 | nitpick | 80 | 45 | 51 | false | Reorganize async server code | 410 | DiceDB/dice | 10,326 | C | lucifercr07 | JyotinderSingh | Review this pull request change.
Language: Go
File: main.go
PR Title: Reorganize async server code
BEFORE CODE: func setupFlags() {
flag.StringVar(&config.Host, "host", "0.0.0.0", "host for the dice server")
flag.IntVar(&config.Port, "port", 7379, "port for the dice server")
flag.StringVar(&config.RequirePass, "... | nit: I believe this wouldn't be required as program would quit after `log.Fatal` | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
"github.com/dicedb/dice/internal/constants"
"github.com/dicedb/dice/server/utils"
)
type AsyncServer struct {
serverFD int
ctx context.Context
cancel context.CancelFunc
wg *sync.WaitGroup
maxClients int
multiplexer iomultiplexer.IOMultiplexer
connectedCl... | nit: Shall we make this as part of config? | "github.com/dicedb/dice/core/iomultiplexer"
"github.com/dicedb/dice/internal/constants"
"github.com/dicedb/dice/server/utils"
)
var ErrAborted = errors.New("server received ABORT command")
var ErrInvalidIPAddress = errors.New("invalid IP address")
type AsyncServer struct {
serverFD int
maxClients ... | @@ -17,247 +16,211 @@ import (
"github.com/dicedb/dice/server/utils"
)
-var cronFrequency time.Duration = 1 * time.Second
-var lastCronExecTime time.Time = utils.GetCurrentTime()
-
-const EngineStatusWAITING int32 = 1 << 1
-const EngineStatusBUSY int32 = 1 << 2
-const EngineStatusSHUTTINGDOWN int32 = 1 << 3
-const... | server/async_tcp.go | 26 | Go | 0.071 | question | 42 | 51 | 51 | false | Reorganize async server code | 410 | DiceDB/dice | 10,326 | C | lucifercr07 | JyotinderSingh | Review this pull request change.
Language: Go
File: server/async_tcp.go
PR Title: Reorganize async server code
BEFORE CODE: "github.com/dicedb/dice/internal/constants"
"github.com/dicedb/dice/server/utils"
)
type AsyncServer struct {
serverFD int
ctx context.Context
cancel conte... | nit: Shall we make this as part of config? | You are an expert software engineer and code reviewer. Review pull requests carefully for correctness, bugs, security issues, performance problems, maintainability, and unnecessary complexity. Only raise actionable issues supported by the code. Explain why an issue matters and suggest a concrete fix when appropriate. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.