Skip to content

Commit

Permalink
Run the redis test server with enable-debug-command
Browse files Browse the repository at this point in the history
This is required for Redis >= 7.x, cf.
https://raw.githubusercontent.com/redis/redis/7.0/00-RELEASENOTES:

    * MODULE and DEBUG commands disabled (protected) by default, for
      better security (#9920)

Without this patch, some unit tests fail:

~~~~
=== RUN   TestLatency
    reply_test.go:256:
        	Error Trace:	/<<PKGBUILDDIR>>/_build/src/github.com/gomodule/redigo/redis/reply_test.go:256
        	Error:      	Received unexpected error:
        	            	ERR DEBUG command not allowed. If the enable-debug-command option is set to "local", you can run it from a local connection, otherwise you need to set this option in the configuration file, and then restart the server.
        	Test:       	TestLatency

Gbp-Pq: Name 0002-Run-the-redis-test-server-with-enable-debug-command.patch
  • Loading branch information
elboulangero committed Oct 10, 2023
1 parent a60882b commit 116465c
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions redis/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,61 @@ type Server struct {
done chan struct{}
}

type Version struct {
major int
minor int
micro int
}

func GetRedisVersion() (*Version, error) {
out, err := exec.Command("redis-server", "--version").Output()
if err != nil {
return nil, err
}

version := ""
fields := strings.Fields(string(out))
for _, field := range fields {
if strings.HasPrefix(field, "v=") {
version = field[2:]
break
}
}
if version == "" {
return nil, errors.New("no version string")
}

values := [3]int{}
elems := strings.Split(version, ".")
for i, _ := range elems {
if i > 2 {
break
}
values[i], err = strconv.Atoi(elems[i])
if err != nil {
return nil, err
}
}

v := &Version{
major: values[0],
minor: values[1],
micro: values[2],
}

return v, nil
}

func NewServer(name string, args ...string) (*Server, error) {
version, err := GetRedisVersion()
if err != nil {
return nil, err
}

if version.major >= 7 {
args = append(args, "--enable-debug-command", "local")
}

s := &Server{
name: name,
cmd: exec.Command(*serverPath, args...),
Expand Down

0 comments on commit 116465c

Please sign in to comment.