Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xiaost/redisgo
A high performance and simple redis client for Go(golang)
https://github.com/xiaost/redisgo
go golang redis redis-client
Last synced: 3 months ago
JSON representation
A high performance and simple redis client for Go(golang)
- Host: GitHub
- URL: https://github.com/xiaost/redisgo
- Owner: xiaost
- License: apache-2.0
- Created: 2018-04-10T15:44:15.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-22T08:15:59.000Z (almost 6 years ago)
- Last Synced: 2024-06-20T05:27:59.460Z (7 months ago)
- Topics: go, golang, redis, redis-client
- Language: Go
- Size: 23.4 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redisgo
[![GoDoc](https://godoc.org/github.com/xiaost/redisgo?status.svg)](https://godoc.org/github.com/xiaost/redisgo)
A high performance and simple redis client for Go(golang).
It is inspired by [redigo](https://github.com/gomodule/redigo).
here is benchmark results compare to [redigo](https://github.com/gomodule/redigo) and [go-redis](https://github.com/go-redis/redis) with go1.10.1, i7-7700:
```
BenchmarkCmdSetRedisgo 10000000 188 ns/op 5 B/op 0 allocs/op
BenchmarkCmdSetRedigo 5000000 329 ns/op 112 B/op 5 allocs/op
BenchmarkCmdSetGoredis 2000000 748 ns/op 372 B/op 9 allocs/op
```### Usage
```go
package mainimport (
"context"
"log"
"net""github.com/xiaost/redisgo"
)func main() {
pool := redisgo.NewPool(func(ctx context.Context) (*redisgo.Conn, error) {
conn, err := net.Dial("tcp", "127.0.0.1:6379")
if err != nil {
return nil, err
}
return redisgo.NewConn(conn), nil
})redisconn, err := pool.Get(context.TODO())
if err != nil {
log.Fatal(err)
}
defer redisconn.Close() // returns to poolerr = redisconn.DoNoReply("SET", "hello", "world")
/* or you can do it like this:
reply, err := c.Do(cmd, args...)
if err == nil {
err = reply.Err()
reply.Free()
}
*/
if err != nil {
log.Fatal(err)
}b, err := redisconn.DoBytes("GET", "hello")
/* or you can do it like this:
var b []byte
reply, err := c.Do("GET", "hello")
if err == nil {
b, err = reply.Bytes()
reply.Free()
}
*/
if err != nil { // err == redisgo.ErrNil if not exists
log.Fatal(err)
}
if s := string(b); s != "world" {
log.Fatal(s)
}
}
```