Giter Club home page Giter Club logo

Comments (5)

mna avatar mna commented on August 24, 2024

Hello Nikita,

Redis cluster requires at least 3 master nodes to work as expected:

Note that the minimal cluster that works as expected requires to contain at least three master nodes. For your first tests it is strongly suggested to start a six nodes cluster with three masters and three slaves.
(https://redis.io/topics/cluster-tutorial)

The problem with a single node running in cluster mode is that the CLUSTER SLOTS command that redisc uses to detect the topology returns an empty set, so there is absolutely no information as to what node address handles what key, and CUSTER INFO goes a step further, it returns:

cluster_state:fail
cluster_slots_assigned:0

Even if I wanted to allow a special mode where it's ok to have a single node, redis will just refuse to serve anything that touches keys:

127.0.0.1:6379> set x a
(error) CLUSTERDOWN Hash slot not served
127.0.0.1:6379> get x
(error) CLUSTERDOWN Hash slot not served

So there's not much that can be done. It's relatively easy to spin up a redis cluster with a bash script, though, if you want to go that way.

Hope this helps,
Martin

from redisc.

lohmag avatar lohmag commented on August 24, 2024

Actually it could be easily fixed like that -
redis-cli CLUSTER ADDSLOTS $(for i in {0..16383}; do echo $i; done | xargs echo)
Redis starts working in cluster mode only with one node.

from redisc.

mna avatar mna commented on August 24, 2024

๐Ÿ‘ cool, even better.

from redisc.

lohmag avatar lohmag commented on August 24, 2024

I think you didn't understand me. CLUSTER ADDSLOTS is a necessary command to create cluster, so you can create a cluster from one redis master node. Without it redis will work in standalone mode. Your examples in previous comment relate to standalone redis.

from redisc.

mna avatar mna commented on August 24, 2024

CLUSTER ADDSLOTS is a necessary command to create cluster

:D thanks I totally forgot about that, haven't used redis cluster in a long time. Yeah, I thought you meant that the reason your standalone mode did not work was because you did not run this command. Did you try starting the standalone redis server and running that CLUSTER ADDSLOTS command? It does work for me, i.e. this program returns the value of the key correctly:

func main() {
	// create the cluster
	cluster := redisc.Cluster{
		StartupNodes: []string{":6379"},
		DialOptions:  []redis.DialOption{redis.DialConnectTimeout(5 * time.Second)},
		CreatePool:   createPool,
	}
	defer cluster.Close()

	// initialize its mapping
	if err := cluster.Refresh(); err != nil {
		log.Fatalf("Refresh failed: %v", err)
	}

	// grab a connection from the pool
	conn := cluster.Get()
	defer conn.Close()

	// call commands on it
	s, err := redis.String(conn.Do("GET", "some-key"))
	if err != nil {
		log.Fatalf("GET failed: %v", err)
	}
	log.Println(s)
}

I start the single redis-server instance with this config:

port 6379
cluster-enabled yes
cluster-config-file nodes.0.out
cluster-node-timeout 5000
appendonly no

And I run the CLUSTER ADDSLOTS command exactly as you mentioned. If that doesn't work for you there may be some specific command you're using that maybe fails in that scenario, or you're having unrelated connection problems, you'll have to give me more details with reproducible and runnable code.

from redisc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.