Does Go SDK support memcached buckets?


#1

I’m trying to use the Go SDK with a Memcached bucket.

Example:

package main

import (
“crypto/rand”
“encoding/hex”
“fmt”

"github.com/couchbaselabs/gocb"

)

const (
mcurl = "http://localhost:8091"
bucketName = "mc"
saslpassword = "saslpassword"
ttl = uint32(3600)
)

func main() {
cluster, err := gocb.Connect(mcurl)
if err != nil {
fmt.Errorf("%v\n", err)
}

bucket, err := cluster.OpenBucket(bucketName, saslpassword)
if err != nil {
	fmt.Errorf("%v\n", err)
}

rndkey := make([]byte, 16)
if _, err := rand.Read(rndkey); err != nil {
	fmt.Errorf("%#v\n", err)
}
key := hex.EncodeToString(rndkey)
payload := fmt.Sprintf("value-%s", key)

fmt.Printf("Insert {%s, %d, \"%s\"}\n", key, ttl, payload)

cas, err := bucket.Insert(key, payload, ttl)
if err != nil {
	fmt.Errorf("%v\n", err)
}

fmt.Printf("%v\n", cas)

}

Works okay with a Couchbase bucket, but with a Memcached bucket it panics with a divide by zero:

$ go run main.go
Insert {973f73381b3d9126c39be7b2144be095, 3600, “value-973f73381b3d9126c39be7b2144be095”}
panic: runtime error: integer divide by zero
[signal 0x8 code=0x7 addr=0xe39bc pc=0xe39bc]

goroutine 1 [running]:
github.com/couchbaselabs/gocb/gocbcore.(*Agent).routeRequest(0xc208052730, 0xc2080642d0, 0xc20800b220)
$(GOCODE)/src/github.com/couchbaselabs/gocb/gocbcore/agentrouting.go:324 +0x19c
github.com/couchbaselabs/gocb/gocbcore.(*Agent).dispatchDirect(0xc208052730, 0xc2080642d0, 0x0, 0x0)
$(GOCODE)/src/github.com/couchbaselabs/gocb/gocbcore/agentrouting.go:340 +0x44
github.com/couchbaselabs/gocb/gocbcore.(*Agent).dispatchOp(0xc208052730, 0xc2080642d0, 0x0, 0x0, 0x0, 0x0)
$(GOCODE)/src/github.com/couchbaselabs/gocb/gocbcore/agentops.go:29 +0x56
github.com/couchbaselabs/gocb/gocbcore.(*Agent).store(0xc208052730, 0x2, 0xc20801ee80, 0x20, 0x20, 0xc20803b440, 0x26, 0x30, 0xc204000
$(GOCODE)/src/github.com/couchbaselabs/gocb/gocbcore/agentops.go:293 +0x376
github.com/couchbaselabs/gocb/gocbcore.(*Agent).Add(0xc208052730, 0xc20801ee80, 0x20, 0x20, 0xc20803b440, 0x26, 0x30, 0xe1004000000, 0
$(GOCODE)/src/github.com/couchbaselabs/gocb/gocbcore/agentops.go:297 +0xdd
github.com/couchbaselabs/gocb.func·012(0xc20801ee60, 0x0, 0x0, 0x0, 0x0)
$(GOCODE)/src/github.com/couchbaselabs/gocb/bucket_crud.go:173 +0xee
github.com/couchbaselabs/gocb.(*Bucket).hlpCasExec(0xc208052370, 0xc208079e08, 0x0, 0x0, 0x0)
$(GOCODE)/src/github.com/couchbaselabs/gocb/bucket_crud.go:51 +0x175
github.com/couchbaselabs/gocb.(*Bucket).Insert(0xc208052370, 0xc20801ee40, 0x20, 0x260a20, 0xc20800b1f0, 0xe10, 0x0, 0x0, 0x0)
$(GOCODE)/src/github.com/couchbaselabs/gocb/bucket_crud.go:175 +0x156
main.main()
$(GOCODE)/go-sdk-validation/main.go:38 +0x75c


#2

Hey @jmcgill_public,

Unfortunately the Go SDK does not currently support connecting to a memcached bucket. While support for this is something we will be including in the future, it is not yet available.

Cheers, Brett