Open Source: Redis Client for Go
There are a number of client libraries for Redis written in Go. They generally take two forms: one which provides a connection type where you can send handwritten commands, and the other which provides a connection type with methods for the many Redis commands. The reply types typically provide a set of methods that return a string, a slice of strings, a slice of bytes, a map, etc.
This leaves out my favorite Go idiom: readers and writers, so I wrote another Redis client for Go that solves this deficiency. This means when I GET a value that’s a 128 MB bulk string, I get back a reader that I can stream back to the client almost as quickly as I receive the data, and without storing any more than my buffer length in memory.
So what does this mean?
This allows for some exciting efficiency, particularly when it comes to bulk strings and arrays, but it does demand some complexity to reconcile the Redis protocol with a FIFO stream. In particular, when you read an array from a Redis response, and the elements are bulk strings, to read the next element, you must read the entire previous element into memory. To solve this, I wrote a few utility IO types to allow response elements to be seamlessly cached. This gives you the flexibility to have the best of both worlds when required.
The library currently supports:
- Connection pooling
- A Print-like API