Skip to content
Tam. Nguyen Duc edited this page Jun 3, 2014 · 2 revisions

Sharding

Gore supports simple sharding strategy: a fixed number of Redis instances are grouped into "cluster", each instance holds a portion of the cluster keyset.

When a single command needed to be execute on the cluster, gore will redirect the command to approriate instance based on the key. Gore makes sure that each key will be redirected to only one instance consistently. Because of the nature of the fixed-sharding, the number of Redis instances in the cluster should never change, and pipeline or transaction is not supported.

Gore provides two ways to connect to a cluster.

The first way is using Sentinel. All Redis instances in the same cluster should have the same prefix, and the suffix should be a number. For example: "mycluster1", "mycluster2", ..., "mycluster20". Using Sentinel, you can get a cluster relatively easy:

s := NewSentinel()
s.AddServer("127.0.0.1:26379", "127.0.0.1:26380", "127.0.0.1:26381")
err := s.Dial()
if err != nil {
      return
}
c, err := s.GetCluster("mycluster")

The second way is to add shard to a cluster manually:

c := NewCluster()
c.AddShard("127.0.0.1:6379", "127.0.0.1:6380")
err := c.Dial()
if err != nil {
      return
}

Using cluster

A single command can be ran on the cluster with Execute:

rep, err := c.Execute(NewCommand("SET", "kirisame", "marisa"))
if err != nil || !rep.IsOk() {
      return
}
rep, err := c.Execute(NewCommand("GET", "kirisame"))
if err != nil {
      return
}
value, _ := rep.String() // value should be "marisa"
Clone this wiki locally