redis client for golang
Switch branches/tags
Nothing to show
Clone or download
iwanbk and xuyu Only put back the connection to pool if got no error. (#18)
* Only put back the connection to pool if got no error.

* remove unnecessary `defer`
Latest commit 89fbe94 Sep 28, 2016
Permalink
Failed to load latest commit information.
.gitignore git ignore .idea Jan 14, 2015
LICENSE Initial commit Aug 23, 2013
README.md Update README.md May 5, 2014
connection.go comments: makes golint happy Feb 25, 2014
connection_test.go update tests Jan 16, 2014
hashes.go comments: makes golint happy Feb 25, 2014
hashes_test.go redis: fix hscan, sscan, zscan Jan 10, 2014
hyperloglog.go hyperloglog: support new redis data structure HyperLogLog Apr 25, 2014
hyperloglog_test.go hyperloglog: support new redis data structure HyperLogLog Apr 25, 2014
keys.go fix keys.go with golint Mar 18, 2014
keys_test.go keys: add object command test case Jan 12, 2014
lists.go update comments with golint Mar 18, 2014
lists_test.go benchmark: add some benchmarks Jan 13, 2014
pipelining.go update comments with golint Mar 18, 2014
pipelining_test.go add pipelining test case Jan 8, 2014
pubsub.go update comments with golint Mar 18, 2014
pubsub_test.go pubsub: add quit(bool) var to prevent test fail Jan 12, 2014
redis.go Only put back the connection to pool if got no error. (#18) Sep 29, 2016
redis_test.go DialURL: Added support for defaults Mar 29, 2015
scripting.go update comments with golint Mar 18, 2014
scripting_test.go update test case Jan 8, 2014
server.go Fixed ConfigSet Mar 26, 2015
server_test.go fix pool put panic at runtime when c(connection) is nil Jul 2, 2014
sets.go update comments with golint Mar 18, 2014
sets_test.go redis: fix hscan, sscan, zscan Jan 10, 2014
sort.go update comments with golint Mar 18, 2014
sort_test.go sort: add sort list test case Jan 11, 2014
sorted_sets.go sorted_sets: support redis new feature `lex` about sorted sets Apr 25, 2014
sorted_sets_test.go sorted_sets: add the remain commands implement Jan 11, 2014
strings.go add SimpleSet function to perform `SET key value` Aug 20, 2014
strings_test.go fix set empty string error Jan 14, 2015
transactions.go update comments with golint Mar 18, 2014
transactions_test.go add more transaction test case Jan 4, 2014

README.md

goredis

GoDoc

redis client in golang

Go or Golang is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

  • Pure golang, and doesn't depend on any 3rd party libraries;
  • Hight test coverage and will continue to improve;
  • Tested under Go 1.2 and Redis 2.8.3;
  • Tested under Go 1.2.1 and Redis 2.8.4;

Features

Document

Simple Example

Connect:

client, err := Dial()
client, err := Dial(&DialConfig{Address: "127.0.0.1:6379"})
client, err := DialURL("tcp://auth:password@127.0.0.1:6379/0?timeout=10s&maxidle=1")

Try a redis command is simple too, let's do GET/SET:

err := client.Set("key", "value", 0, 0, false, false)
value, err := client.Get("key")

Or you can execute a custom command with Redis.ExecuteCommand method:

reply, err := client.ExecuteCommand("SET", "key", "value")
err := reply.OKValue()

And then a Reply struct which represent the redis response data is defined:

type Reply struct {
	Type    int
	Error   string
	Status  string
	Integer int64  // Support Redis 64bit integer
	Bulk    []byte // Support Redis Null Bulk Reply
	Multi   []*Reply
}

Reply.Type is defined as:

const (
	ErrorReply = iota
	StatusReply
	IntegerReply
	BulkReply
	MultiReply
)

Reply struct has many useful methods:

func (rp *Reply) IntegerValue() (int64, error)
func (rp *Reply) BoolValue() (bool, error)
func (rp *Reply) StatusValue() (string, error)
func (rp *Reply) OKValue() error
func (rp *Reply) BytesValue() ([]byte, error)
func (rp *Reply) StringValue() (string, error)
func (rp *Reply) MultiValue() ([]*Reply, error)
func (rp *Reply) HashValue() (map[string]string, error)
func (rp *Reply) ListValue() ([]string, error)
func (rp *Reply) BytesArrayValue() ([][]byte, error)
func (rp *Reply) BoolArrayValue() ([]bool, error)

You can find more examples in test files.

Run Test

normal test:

go test

coverage test:

go test -cover

coverage test with html result:

go test -coverprofile=cover.out
go tool cover -html=cover.out

Welcome to report issues :)

Run Benchmark

go test -test.run=none -test.bench="Benchmark.*"

At my virtualbox Ubuntu 13.04 with single CPU: Intel(R) Core(TM) i5-3450 CPU @ 3.10GHz, get result:

BenchmarkPing	   50000	     40100 ns/op
BenchmarkLPush	   50000	     34939 ns/op
BenchmarkLRange	   50000	     41420 ns/op
BenchmarkGet	   50000	     37948 ns/op
BenchmarkIncr	   50000	     44460 ns/op
BenchmarkSet	   50000	     41300 ns/op

Welcome to show your benchmark result :)

License

The MIT License (MIT) Copyright (c) 2013 xuyu