Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

support routing the FCALL and FCALL_RO commands #11

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion redis/command_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var replicaSafe = makeSet(strings.Split(
"SCARD SDIFF SINTER SISMEMBER SMEMBERS SRANDMEMBER STRLEN SUNION "+
"ZCARD ZCOUNT ZLEXCOUNT ZRANGE ZRANGEBYLEX ZREVRANGEBYLEX "+
"ZRANGEBYSCORE ZRANK ZREVRANGE ZREVRANGEBYSCORE ZREVRANK ZSCORE "+
"XPENDING XREVRANGE XREAD XLEN ", " "))
"XPENDING XREVRANGE XREAD XLEN FCALL_RO", " "))

// ReplicaSafe returns true if command is readonly and "safe to run on replica".
// Some commands like "scan" are not included, because their result could differ between
Expand Down
4 changes: 4 additions & 0 deletions redis/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func (r Request) Key() (string, bool) {
}
var n int
switch r.Cmd {
case "FCALL", "FCALL_RO":
n = 2
case "EVAL", "EVALSHA":
n = 2
case "BITOP":
Expand All @@ -63,6 +65,8 @@ func (r Request) KeyByte() ([]byte, bool) {
}
var n int
switch r.Cmd {
case "FCALL", "FCALL_RO":
n = 2
case "EVAL", "EVALSHA":
n = 2
case "BITOP":
Expand Down
48 changes: 48 additions & 0 deletions redis/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,59 @@ func TestRequestKey(t *testing.T) {
assert.Equal(t, "2", k)
assert.True(t, ok)

k, ok = Req("FCALL", "foo", 1, 2, 3).Key()
assert.Equal(t, "2", k)
assert.True(t, ok)

k, ok = Req("FCALL_RO", "foo", 1, 2, 3).Key()
assert.Equal(t, "2", k)
assert.True(t, ok)

k, ok = Req("BITOP", "AND", 1, 2).Key()
assert.Equal(t, "1", k)
assert.True(t, ok)
}

func TestRequestKeyByte(t *testing.T) {
var k []byte
var ok bool

k, ok = Req("GET", 1).KeyByte()
assert.Equal(t, []byte("1"), k)
assert.True(t, ok)

_, ok = Req("GET").Key()
assert.False(t, ok)

k, ok = Req("SET", 1, 2).KeyByte()
assert.Equal(t, []byte("1"), k)
assert.True(t, ok)

k, ok = Req("RANDOMKEY").KeyByte()
assert.Equal(t, []byte("RANDOMKEY"), k)
assert.False(t, ok)

k, ok = Req("EVAL", "return KEY[1]", 1, 2, 3).KeyByte()
assert.Equal(t, []byte("2"), k)
assert.True(t, ok)

k, ok = Req("EVALSHA", "1234abcdef", 1, 2, 3).KeyByte()
assert.Equal(t, []byte("2"), k)
assert.True(t, ok)

k, ok = Req("FCALL", "foo", 1, 2, 3).KeyByte()
assert.Equal(t, []byte("2"), k)
assert.True(t, ok)

k, ok = Req("FCALL_RO", "foo", 1, 2, 3).KeyByte()
assert.Equal(t, []byte("2"), k)
assert.True(t, ok)

k, ok = Req("BITOP", "AND", 1, 2).KeyByte()
assert.Equal(t, []byte("1"), k)
assert.True(t, ok)
}

func TestArgToString(t *testing.T) {
var k string
var ok bool
Expand Down
Loading