Skip to content

cluster.Set() returns redis.Nil without doing anything #2628

Open
@MakDon

Description

@MakDon

Before all, please see this issue

The path to reproduce this issue:

  • First, we create a new redis cluster in cluster-preferred-endpoint-type unknown-endpoint mode:
cd /path/to/redis/repo
make
cd src
mkdir 7001
mkdir 7002
mkdir 7003
echo "port 7001\ncluster-enabled yes\ncluster-config-file nodes.conf\ncluster-node-timeout 5000\nappendonly yes\ncluster-preferred-endpoint-type unknown-endpoint" > 7001/redis.conf
echo "port 7002\ncluster-enabled yes\ncluster-config-file nodes.conf\ncluster-node-timeout 5000\nappendonly yes\ncluster-preferred-endpoint-type unknown-endpoint" > 7002/redis.conf
echo "port 7003\ncluster-enabled yes\ncluster-config-file nodes.conf\ncluster-node-timeout 5000\nappendonly yes\ncluster-preferred-endpoint-type unknown-endpoint" > 7003/redis.conf

cd 7001
nohup ../redis-server redis.conf &
cd ..

cd 7002
nohup ../redis-server redis.conf &
cd ..

cd 7003
nohup ../redis-server redis.conf &
cd ..

sleep 5 # wait for redis starts

./redis-cli --cluster-yes --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003
  • Then, try to update the key foo:
package main

import (
	"context"
	"fmt"

	"github.com/redis/go-redis/v9"
)

func main() {
	ctx := context.Background()

	cluster := redis.NewClusterClient(&redis.ClusterOptions{
		Addrs: []string{":7001"},
	})

	foo, err := cluster.Set(ctx, "foo", "barr", 0).Result()
	fmt.Println(foo, err) // Output: <space>redis: nil
	bar, err := cluster.Get(ctx, "foo").Result()
	fmt.Println(foo, err, bar) // Output: <space>redis: nil
}

It returns redis: Nil in this line, node, err = c.cmdNode(ctx, cmdInfo, slot), which makes it confusing that the Set command seems to be processed correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions