Skip to content
/ pail Public

Lightweight extension to couchbase/gocb bucket that provides CRUD and N1QL retry logic

License

Notifications You must be signed in to change notification settings

myENA/pail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pail

Lightweight extension to couchbase/gocb bucket that provides CRUD and N1QL retry logic

Purpose

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.

Basic Usage

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)
}

About

Lightweight extension to couchbase/gocb bucket that provides CRUD and N1QL retry logic

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages