go-redisproto a lightweight library for Redis protocol in GoLang


Circle CI

There are plenty of good client/server implementations of the redis protocol, but not many of them that are designed for RPC (see My Blog to see how to use RPC in golang ).
go-redisproto is a lightweight library for building server software capable of exploit the advantages of the redis protocol and RPC.
The advantages of go-redisproto is to use it’s own buffered reader to avoid memory copy compared to other exist client libraries.
It parses data really fast and requires a minimum amount of memory. Therefore, it enhances
the performance in both client and server services, especially in some projects required RPC.
This could be an alternate implementation of redis, a custom proxy to redis, and widely be used in high throughput API applications.


Many thanks to secmack for his original version(github.com/secmack/go-redisproto), who gave me the golden opportunity to do this wonderful project.
He worked so hard to provide this source code.

Recommended Books


Use go tool to install the package in your packages tree:

go get github.com/secmask/go-redisproto

Then you can use it in import section of your Go programs:

import "github.com/secmask/go-redisproto"


See full example in my GitHUb (https://github.com/phuongdo/go-redisproto)

import "github.com/secmask/go-redisproto"
parser := redisproto.NewParser(conn)
writer := redisproto.NewWriter(bufio.NewWriter(conn))

// read a command from a connection
command, err := parser.ReadCommand()
if err != nil {
_, ok := err.(*redisproto.ProtocolError)
if ok {
ew = writer.WriteError(err.Error())
} else {
log.Println(err, " closed connection to ", conn.RemoteAddr())
} else {
cmd := strings.ToUpper(string(command.Get(0)))
switch cmd {
case "GET":
ew = writer.WriteBulkString("dummy")
case "SET":
ew = writer.WriteBulkString("OK")
ew = writer.WriteError("Command not support")
if command.IsLast() {
if ew != nil {
log.Println("Connection closed", ew)

Start a demo server:

$ go run example/main.go

Test the protocol
telnet localhost 6380
Connected to localhost.
Escape character is '^]'.
-Command not support
SET hello
GET hello


Start a demo server:

$ go run example/main.go

Run redis-benchmark (required redis client installed in your local computer)

redis-benchmark -p 6380 -c 32 -n 1000000 lpush k2 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
====== lpush k2 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ======
1000000 requests completed in 6.51 seconds
32 parallel clients
3 bytes payload
keep alive: 1

99.87% <= 1 milliseconds
99.96% <= 2 milliseconds
99.99% <= 3 milliseconds
100.00% <= 4 milliseconds
100.00% <= 5 milliseconds
100.00% <= 9 milliseconds
100.00% <= 10 milliseconds
153727.91 requests per second


applications used go-redisproto

  1. https://github.com/secmask/mqueue
  2. https://github.com/secmask/roller

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: