Skip to content

Commit

Permalink
Fixes .WATCH fingerprinting to generate consistent fingerprints (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
JyotinderSingh authored Oct 12, 2024
1 parent b0de463 commit a30f0a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions integration_tests/commands/resp/getwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func TestGETWATCHWithSDK(t *testing.T) {
assert.Assert(t, watch != nil)
firstMsg, err := watch.Watch(context.Background(), "GET", getWatchKey)
assert.NilError(t, err)
assert.Equal(t, firstMsg.Command, "GET.WATCH")
assert.Equal(t, firstMsg.Command, "GET")
assert.Equal(t, firstMsg.Fingerprint, "1768826704")
channels[i] = watch.Channel()
}

Expand Down Expand Up @@ -132,7 +133,8 @@ func TestGETWATCHWithSDK2(t *testing.T) {
assert.Assert(t, watch != nil)
firstMsg, err := watch.GetWatch(context.Background(), getWatchKey)
assert.NilError(t, err)
assert.Equal(t, firstMsg.Command, "GET.WATCH")
assert.Equal(t, firstMsg.Command, "GET")
assert.Equal(t, firstMsg.Fingerprint, "1768826704")
channels[i] = watch.Channel()
}

Expand Down
6 changes: 4 additions & 2 deletions integration_tests/commands/resp/zrangewatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ func TestZRANGEWATCHWithSDK(t *testing.T) {
assert.Assert(t, watch != nil)
firstMsg, err := watch.Watch(context.Background(), "ZRANGE", zrangeWatchKey, "0", "-1", "REV", "WITHSCORES")
assert.NilError(t, err)
assert.Equal(t, firstMsg.Command, "ZRANGE.WATCH")
assert.Equal(t, firstMsg.Command, "ZRANGE")
assert.Equal(t, firstMsg.Fingerprint, "2491069200")
channels[i] = watch.Channel()
}

Expand Down Expand Up @@ -156,7 +157,8 @@ func TestZRANGEWATCHWithSDK2(t *testing.T) {
subscribers[i].watch = conn
firstMsg, err := conn.ZRangeWatch(context.Background(), zrangeWatchKey, "0", "-1", "REV", "WITHSCORES")
assert.NilError(t, err)
assert.Equal(t, firstMsg.Command, "ZRANGE.WATCH")
assert.Equal(t, firstMsg.Command, "ZRANGE")
assert.Equal(t, firstMsg.Fingerprint, "2491069200")
channels[i] = conn.Channel()
}

Expand Down
5 changes: 4 additions & 1 deletion internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,11 @@ func (w *BaseWorker) executeCommand(ctx context.Context, diceDBCmd *cmd.DiceDBCm
case Watch:
// Generate the Cmd being watched. All we need to do is remove the .WATCH suffix from the command and pass
// it along as is.
// Modify the command name to remove the .WATCH suffix, this will allow us to generate a consistent
// fingerprint (which uses the command name without the suffix)
diceDBCmd.Cmd = diceDBCmd.Cmd[:len(diceDBCmd.Cmd)-6]
watchCmd := &cmd.DiceDBCmd{
Cmd: diceDBCmd.Cmd[:len(diceDBCmd.Cmd)-6], // Remove the .WATCH suffix
Cmd: diceDBCmd.Cmd,
Args: diceDBCmd.Args,
}
cmdList = append(cmdList, watchCmd)
Expand Down

0 comments on commit a30f0a4

Please sign in to comment.