Ruby:连接到 Couchbase

Ruby: connect to Couchbase

我想通过 couchbase gem.

连接到 Couchbase 数据库服务器
require 'couchbase'
c = Couchbase.connect('http://<server>:<port>/pools/default/buckets/auth')

我收到一个错误:

*** Couchbase::Error::BucketNotFound Exception: bootstrap error, The bucket requested does not exist

以下代码适用于 (couchbase python package):

from couchbase.bucket import Bucket
c = Bucket('couchbase://<server>/auth')

如何使用连接字符串 couchbase://<server>/auth 从 ruby 进行连接?

这是我在我的机器上看到的。

# ruby --version
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]

# gem --version
1.3.7

# gem list --local

*** LOCAL GEMS ***

connection_pool (2.2.0)
couchbase (1.3.14)
multi_json (1.12.1)
yaji (0.3.5)

# cat test.ruby
require 'couchbase'
c = Couchbase.connect('http://localhost:8091/pools/default/buckets/BUCKETNAME')
puts c.get('test123')


# cbc get test123 -U couchbase://localhost/BUCKETNAME 
test123              CAS=0x8f1269ea6014, Flags=0x0. Size=17
{"hello":"there"}

# ruby -rubygems test.ruby
[WARNING] MultiJson is using the default adapter (ok_json). We recommend loading a different JSON library to improve performance.
hellothere

这是在我的一个 Couchbase 节点上。我有一个名为 BUCKETNAME 的存储桶,它包含一个带有键 "test123" 的文档,文档的内容是

{
  "hello": "there"
}

如果是custom需要指定bucket:

Couchbase.connect("http://<server>:8091/pools/default", :bucket => 'auth')