riak.bucket
Buckets are both namespaces for the key-value pairs you store in Riak, and containers for properties that apply to that namespace. In older versions of Riak, this was the only logical organization available. Now a higher-level collection called a Bucket Type can group buckets together. They allow for efficiently setting properties on a group of buckets at the same time.
Unlike buckets, Bucket Types must be explicitly created and activated before being used:
riak-admin bucket-type create n_equals_1 '{"props":{"n_val":1}}'
riak-admin bucket-type activate n_equals_1
Bucket Type creation and activation is only supported via the riak-admin bucket-type
command-line tool. Riak 2.0 does not include an API to perform these actions, but the Python client can retrieve <BucketType.get_properties>
and set
<BucketType.set_properties>
bucket-type properties.
If Bucket Types are not specified, the default bucket type is used. These buckets should be created via the bucket()
<riak.client.RiakClient.bucket>
method on the client object, like so:
import riak
client = riak.RiakClient()
mybucket = client.bucket('mybucket')
Buckets with a user-specified Bucket Type can also be created via the same bucket()<riak.client.RiakClient.bucket>
method with an additional parameter or explicitly via bucket_type()<riak.client.RiakClient.bucket_type>
:
othertype = client.bucket_type('othertype')
otherbucket = othertype.bucket('otherbucket')
# Alternate way to get a bucket within a bucket-type
mybucket = client.bucket('mybucket', bucket_type='mybuckettype')
For more detailed discussion, see Using Bucket Types.
RiakBucket
name
The name of the bucket, a string.
bucket_type
The parent BucketType
for the bucket.
resolver
Bucket properties are flags and defaults that apply to all keys in the bucket.
RiakBucket.get_properties
RiakBucket.set_properties
RiakBucket.clear_properties
RiakBucket.get_property
RiakBucket.set_property
Some of the most commonly-used bucket properties are exposed as object properties as well. The getters and setters simply call RiakBucket.get_property
and RiakBucket.set_property
respectively.
RiakBucket.n_val
RiakBucket.allow_mult
RiakBucket.r
RiakBucket.pr
RiakBucket.w
RiakBucket.dw
RiakBucket.pw
RiakBucket.rw
The primary purpose of buckets is to act as namespaces for keys. As such, you can use the bucket object to create, fetch and delete objects <riak.riak_object.RiakObject>
.
RiakBucket.new
RiakBucket.new_from_file
RiakBucket.get
RiakBucket.multiget
RiakBucket.delete
RiakBucket.search
RiakBucket.get_index
RiakBucket.stream_index
RiakBucket.paginate_index
RiakBucket.paginate_stream_index
Similar to RiakClient <riak.client.RiakClient>
, buckets can register custom transformation functions for media-types. When undefined on the bucket, RiakBucket.get_encoder
and RiakBucket.get_decoder
will delegate to the client associated with the bucket.
RiakBucket.get_encoder
RiakBucket.set_encoder
RiakBucket.get_decoder
RiakBucket.set_decoder
Shortcuts for RiakClient.get_keys()
<riak.client.RiakClient.get_keys>
and RiakClient.stream_keys()
<riak.client.RiakClient.stream_keys>
are exposed on the bucket object. The same admonitions for these operations apply.
RiakBucket.get_keys
RiakBucket.stream_keys
BucketType
name
The name of the Bucket Type, a string.
BucketType.is_default
BucketType.bucket
Bucket Type properties are flags and defaults that apply to all buckets in the Bucket Type.
BucketType.get_properties
BucketType.set_properties
BucketType.get_property
BucketType.set_property
BucketType.datatype
The assigned datatype for this bucket type, if present.
- rtype
None or str
Shortcuts for RiakClient.get_buckets()
<riak.client.RiakClient.get_buckets>
and RiakClient.stream_buckets()
<riak.client.RiakClient.stream_buckets>
are exposed on the bucket type object. This is similar to Listing keys on buckets.
BucketType.get_buckets
BucketType.stream_buckets
When Riak Search 1.0 is enabled on the server, you can toggle which buckets have automatic indexing turned on using the search
bucket property (and on older versions, the precommit
property). These methods simplify interacting with that configuration.
RiakBucket.search_enabled
RiakBucket.enable_search
RiakBucket.disable_search
The ~RiakBucket.get_counter
and ~RiakBucket.update_counter
. See legacy_counters
for more details.
Warning
Legacy counters are incompatible with Bucket Types.
RiakBucket.get_counter
RiakBucket.update_counter