4

我希望能够通过 cURL 创建一个 Riak 存储桶。我一直在网上搜索,似乎无法找到一种方法来做到这一点。我知道有一些方法可以通过驱动程序轻松完成,但需要能够使用 cURL 来完成我正在开发的 Saas 应用程序。

4

3 回答 3

7

你会做一个 PUT 传递你想要作为 json 对象的存储桶属性,例如

curl -v http://riak3.local:8098/riak/newBucket -X PUT -H Content-Type:application/json --data-binary '{"props":{"n_val":5}}'

文档有更完整的细节。

于 2012-10-13T03:37:07.300 回答
4

另一件事 - 要记住的重要一点是,没有办法通过调用(通过 CURL 或客户端 api)显式地“创建”存储桶。

您只能通过上面的调用创建自定义存储桶。

原因是——存储桶只是键的前缀。Riak 系统中没有任何对象可以跟踪存储桶。某处没有文件,内存中没有变量,或类似的东西。这就是为什么简单的“list buckets”命令如此昂贵的原因:Riak 实际上必须遍历集群中的每个键,并通过查看键前缀来组装一个桶列表。

The only thing that exists as actual objects are buckets with non-default settings, ie, custom buckets. That's what that curl command above does -- it keeps track of some non-default settings for Riak to consult if a call ever comes in to that bucket.

Anyways, the moral of the story is: you don't need to create buckets in the normal course of operations. You can just start writing to them, and they will come into being (again, in the sense of, keys with bucket prefixes will come into being, which means they can now be iterated over by the expensive 'list buckets' call).

You only have to issue the call for custom buckets (and also, you don't want to do that too much, either, as there is a practical limit to the number of custom buckets created in a cluster, somewhere around 9000).

于 2012-10-21T17:50:52.353 回答
3

我还发现,如果您将新对象添加到不存在的存储桶中,它将即时创建该存储桶。

请记住,当您向其中添加密钥时,会自动创建存储桶。无需显式“创建”存储桶(有关存储桶及其属性的更多信息,请参见页面下方。)

存储桶属性和操作

于 2012-10-13T07:13:28.310 回答