1
0
Fork 0
mirror of https://github.com/Luzifer/cloudkeys-go.git synced 2024-11-14 17:02:43 +00:00
cloudkeys-go/vendor/github.com/xuyu/goredis
Knut Ahlers 7581358922
Switch to dep for vendoring, update dependencies
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-12-08 13:03:10 +01:00
..
.gitignore Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
connection.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
connection_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
hashes.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
hashes_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
hyperloglog.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
hyperloglog_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
keys.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
keys_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
LICENSE Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
lists.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
lists_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
pipelining.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
pipelining_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
pubsub.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
pubsub_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
README.md Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
redis.go Switch to dep for vendoring, update dependencies 2017-12-08 13:03:10 +01:00
redis_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
scripting.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
scripting_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
server.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
server_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
sets.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
sets_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
sort.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
sort_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
sorted_sets.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
sorted_sets_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
strings.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
strings_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
transactions.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00
transactions_test.go Migrated Godeps to go1.6 vendoring 2016-05-13 17:29:06 +02:00

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