Lightweight extension to couchbase/gocb bucket that provides CRUD and N1QL retry logic
In our testing with Couchbase, we noticed we sometimes see errors that stem from either an internal lock within the gocb client, sporadic networking issues, etc etc. These errors have nothing to do with the request being executed and there is nothing to "handle" within our app code, thus the only solution was to catch every error and just try it again.
This package is the end result of that work. Its only dependency is the upstream gocb package, and provides glide, dep, and mod dependency manager files.
package main
import(
"fmt"
"time"
"github.com/couchbase/gocb/v2"
"github.com/myENA/pail/v2"
)
func main() {
// create couchbase connection and bucket as you normally would
connStr := "couchbase://127.0.0.1"
cluster, err := pail.Connect(connStr, gocb.ClusterOptions{}, 5, 20 * time.Millisecond)
if err != nil {
panic(err)
}
p := cluster.Bucket("bucketname")
// From here, the API is pretty simple. Any call you wish to attempt retries on, execute the "TryX" version of the
// standard api method
type pType struct {
Key string
Value string
}
tPtr := new(pType)
// TryGet wraps bucket.Get
res, err := p.DefaultCollection().TryGetContent("mykey", tPtr, nil)
if err != nil {
panic(err)
}
fmt.Println(res)
}