开发者

How do you organize buckets in Riak?

开发者 https://www.devze.com 2023-03-08 14:45 出处:网络
Since Riak uses buckets as a way of separating keys, is it possible to have buckets within buckets? If not how would one go about organizing a Riak setup with many buckets for several apps.

Since Riak uses buckets as a way of separating keys, is it possible to have buckets within buckets? If not how would one go about organizing a Riak setup with many buckets for several apps.

The basic problem is how one would go about representing "databases" and "tables" within Riak. Sinc开发者_运维问答e a bucket translates to a table, what translates to a database?

Namespaces in programming languages usually have hierarchies. It makes sense for Riak buckets to also allow hierarchies, since buckets are essentially namespaces.


You need to think about Riak as about very big key -> value "table" where buckets are only prefixes for keys. Now when you know that you can do anything with buckets as long as they are still binary objects.

You can create linear "tables":

<<"table1">>
<<"table2">>

Or you can create hierarchies:

<<"db1.table1">>
<<"db1.table2">>
<<"db2.table1">>
<<"db2.table2">>

Or you even can use tuples as buckets:

1> term_to_binary({"db1", "table1"}).
<<131,104,2,107,0,3,100,98,49,107,0,6,116,97,98,108,101,49>>
2> term_to_binary({"db1", "table2"}).
<<131,104,2,107,0,3,100,98,49,107,0,6,116,97,98,108,101,50>>
3> term_to_binary({"db2", "table1"}).
<<131,104,2,107,0,3,100,98,50,107,0,6,116,97,98,108,101,49>>
4> term_to_binary({"db2", "table2"}).
<<131,104,2,107,0,3,100,98,50,107,0,6,116,97,98,108,101,50>>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号