1# Redbench 2[![GoDoc](https://img.shields.io/badge/api-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/tidwall/redbench) 3 4Redbench is a Go package that allows for bootstrapping benchmarks 5for servers using a custom implementation of the Redis protocol. It provides 6the same inputs and outputs as the 7[redis-benchmark](https://redis.io/topics/benchmarks) tool. 8 9The purpose of this library is to provide benchmarking for 10[Redcon](https://github.com/tidwall/redcon) compatible servers such as 11[Tile38](https://github.com/tidwall/tile38), but also works well for Redis 12operations that are not covered by the `redis-benchmark` tool such as the 13`GEO*` commands, custom lua scripts, or [Redis Modules](http://antirez.com/news/106). 14 15## Getting Started 16 17### Installing 18 19To start using Redbench, install Go and run `go get`: 20 21```sh 22$ go get -u github.com/tidwall/redbench 23``` 24 25This will retrieve the library. 26 27### Example 28 29The following example will run a benchmark for the `PING,SET,GET,GEOADD,GEORADIUS` 30commands on a server at 127.0.0.1:6379. 31 32```go 33package main 34 35import ( 36 "math/rand" 37 "strconv" 38 "time" 39 40 "github.com/tidwall/redbench" 41) 42 43func main() { 44 redbench.Bench("PING", "127.0.0.1:6379", nil, nil, func(buf []byte) []byte { 45 return redbench.AppendCommand(buf, "PING") 46 }) 47 redbench.Bench("SET", "127.0.0.1:6379", nil, nil, func(buf []byte) []byte { 48 return redbench.AppendCommand(buf, "SET", "key:string", "val") 49 }) 50 redbench.Bench("GET", "127.0.0.1:6379", nil, nil, func(buf []byte) []byte { 51 return redbench.AppendCommand(buf, "GET", "key:string") 52 }) 53 rand.Seed(time.Now().UnixNano()) 54 redbench.Bench("GEOADD", "127.0.0.1:6379", nil, nil, func(buf []byte) []byte { 55 return redbench.AppendCommand(buf, "GEOADD", "key:geo", 56 strconv.FormatFloat(rand.Float64()*360-180, 'f', 7, 64), 57 strconv.FormatFloat(rand.Float64()*170-85, 'f', 7, 64), 58 strconv.Itoa(rand.Int())) 59 }) 60 redbench.Bench("GEORADIUS", "127.0.0.1:6379", nil, nil, func(buf []byte) []byte { 61 return redbench.AppendCommand(buf, "GEORADIUS", "key:geo", 62 strconv.FormatFloat(rand.Float64()*360-180, 'f', 7, 64), 63 strconv.FormatFloat(rand.Float64()*170-85, 'f', 7, 64), 64 "10", "km") 65 }) 66} 67``` 68 69Which is similar to executing: 70 71``` 72$ redis-benchmark -t PING,SET,GET 73``` 74 75For a more complete example, check out [tile38-benchmark](https://github.com/tidwall/tile38/blob/master/cmd/tile38-benchmark/main.go) from the [Tile38](https://github.com/tidwall/tile38) project. 76 77### Custom Options 78 79```go 80type Options struct { 81 Requests int 82 Clients int 83 Pipeline int 84 Quiet bool 85 CSV bool 86 Stdout io.Writer 87 Stderr io.Writer 88} 89``` 90 91## Contact 92Josh Baker [@tidwall](http://twitter.com/tidwall) 93 94## License 95Redbench source code is available under the MIT [License](/LICENSE). 96 97