Skip to content

joaojeronimo/go-redis-cluster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Redis Cluster

A Redis Cluster Client for the Go Programming Language.

(Well, not really. It's only a thin wrapper above the amazing Radix module. It even uses the Radix module, borrows heavily from it, and the Radix guys did 99% of the work. This is only a thin wrapper that discovers your cluster, connects to all the nodes, and does client-side sharding.)

Installing it

Since this is a wrapper above Radix, you'll need to install it:

go get github.com/fzzbt/radix/redis

And then you can install Go Redis Cluster:

go get github.com/joaojeronimo/go-redis-cluster

Using it

You'll need the link of one member of the cluster, and the rest will be automatically discovered, and everything will be dealt with (slots, etc). After that, you can use it pretty much like you use the Radix module, except you cannot use the obvious commands that (a) affect multiple keys (b) Publish/Subscribe.

Redis Cluster only implements a subset of the commands: "all the single keys commands available in the non distributed version of Redis" (read more about this in the Implemented subset section of the Cluster Spec)

Other than that, it's almost exactly the same as using the Radix module, even the commands' names are the same:

package main

import (
	"github.com/joaojeronimo/go-redis-cluster"
)

func main() {
	cc := rediscluster.NewCluster("localhost:6379") // Connect to the whole cluster only knowing the link of one member
	defer cc.Close()                                // Close it when main returns

	// the usual commands:
	cc.Hset("someHash", "someKey", "someValue")
	theValue := cc.Hget("someHash", "someKey").String()
	if theValue == "someValue" {
		println("OK")
	}

	// Async stuff too:
	cc.Sadd("someSet", "value1", "value2", "value3")
	future := cc.AsyncScard("someSet")
	card, err := (<-future).Int()
	if err != nil {
		panic(err)
	}
	if 3 == card {
		println("OK")
	}
}

Other stuff

I also created a similar module for Node.JS, we use both of them in production, as well as Redis 3.0 that is unstable but passes the tests. So far so good :)

Releases

No releases published

Packages

No packages published

Languages