Struct riak::Client
[−]
[src]
pub struct Client { /* fields omitted */ }
Client
Represents a connection to a Riak server's Protocol Buffers API.
Methods
impl Client
[src]
fn new<A: ToSocketAddrs>(addr: A) -> Result<Client, RiakErr>
Constructs a new Client
with the timeout for requests with a default timeout.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); riak.ping().unwrap();
Errors
TODO
fn new_with_timeout<A: ToSocketAddrs>(
addr: A,
timeout: u32
) -> Result<Client, RiakErr>
addr: A,
timeout: u32
) -> Result<Client, RiakErr>
Constructs a new Client
with a timeout (in seconds) provided.
Examples
use riak::Client; let mut riak = Client::new_with_timeout("10.0.0.2:8087", 3600).unwrap(); riak.ping().unwrap();
Errors
TODO
fn set_timeout(&mut self, timeout: u32)
Set the timeout (in seconds) allowed for future requests.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); riak.set_timeout(3600);
fn reconnect(&mut self) -> Result<(), RiakErr>
Reconnect to the Riak server originally connected to when this client was initiated.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); riak.reconnect().unwrap();
Errors
TODO
fn ping(&mut self) -> Result<(), RiakErr>
Sends a ping message to Riak and returns a Result.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); riak.ping().unwrap();
Errors
TODO
fn server_info(&mut self) -> Result<(String, String), RiakErr>
Get the node name and server version of the Riak server reached.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let (node, version) = riak.server_info().unwrap(); println!("Connected to node {}, running Riak version {}", node, version);
fn stream_buckets(&mut self) -> Result<BucketStream, RiakErr>
Produces a stream of bucket names.
Caution: This call can be expensive for the server. Do not use in performance-sensitive code.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let mut bucketstream = riak.stream_buckets().unwrap(); loop { match bucketstream.next() { Some(buckets) => println!("found buckets {:?}", buckets.unwrap()), None => break, }; }
Errors
TODO
fn list_buckets(&mut self) -> Result<Vec<Vec<u8>>, RiakErr>
Produces a list of bucket names.
Caution: This call can be expensive for the server. Do not use in performance-sensitive code.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let buckets = riak.list_buckets().unwrap(); for bucket in buckets.iter() { println!("found bucket named {:?}", bucket); }
Errors
TODO
fn set_bucket_properties(
&mut self,
bucket_props: BucketProps
) -> Result<(), RiakErr>
&mut self,
bucket_props: BucketProps
) -> Result<(), RiakErr>
Sets the properties for a bucket given a bucket name.
Examples
use riak::Client; use riak::bucket::BucketProps; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let mut bucket_props = BucketProps::new("testbucket"); bucket_props.set_backend("leveldb"); riak.set_bucket_properties(bucket_props).unwrap();
Errors
TODO
fn get_bucket_properties<T: Into<Vec<u8>>>(
&mut self,
bucket_name: T
) -> Result<BucketProps, RiakErr>
&mut self,
bucket_name: T
) -> Result<BucketProps, RiakErr>
Retrieves bucket properties for a bucket given a bucket name.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); riak.get_bucket_properties("testbucket").unwrap();
Errors
TODO
fn set_bucket_type_properties(
&mut self,
bucket_type_props: BucketTypeProps
) -> Result<(), RiakErr>
&mut self,
bucket_type_props: BucketTypeProps
) -> Result<(), RiakErr>
Assigns a set of bucket properties to a bucket type.
Examples
use riak::Client; use riak::bucket::BucketTypeProps; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let mut bucket_type_props = BucketTypeProps::new("testbuckettype"); bucket_type_props.set_backend("leveldb"); riak.set_bucket_type_properties(bucket_type_props).unwrap();
Errors
TODO
fn get_bucket_type_properties<T: Into<Vec<u8>>>(
&mut self,
bucket_type_name: T
) -> Result<BucketTypeProps, RiakErr>
&mut self,
bucket_type_name: T
) -> Result<BucketTypeProps, RiakErr>
Gets the bucket properties associated with a bucket type.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); riak.get_bucket_type_properties("testbuckettype").unwrap();
Errors
TODO
fn reset_bucket<T: Into<Vec<u8>>>(
&mut self,
bucket_type_name: T,
bucket_name: T
) -> Result<(), RiakErr>
&mut self,
bucket_type_name: T,
bucket_name: T
) -> Result<(), RiakErr>
Resets the properties for a bucket
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); riak.reset_bucket("testbuckettype", "testbucket").unwrap();
Errors
TODO
fn stream_keys<T: Into<Vec<u8>>>(
&mut self,
bucket: T
) -> Result<KeyStream, RiakErr>
&mut self,
bucket: T
) -> Result<KeyStream, RiakErr>
Produces a stream of keys from a bucket given a bucket name.
Note: This operation requires traversing all keys stored in the cluster and should not be used in production.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let mut keystream = riak.stream_keys("testbucket").unwrap(); loop { match keystream.next() { Some(keys_result) => println!("found keys {:?}", keys_result.unwrap()), None => break, }; }
Errors
TODO
fn list_keys<T: Into<Vec<u8>>>(
&mut self,
bucket: T
) -> Result<Vec<Vec<u8>>, RiakErr>
&mut self,
bucket: T
) -> Result<Vec<Vec<u8>>, RiakErr>
Produces a list of keys provided a bucket name
Note: This operation requires traversing all keys stored in the cluster and should not be used in production.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let keys = riak.list_keys("testbucket").unwrap(); for key in keys.iter() { println!("found key in bucket testbucket named {:?}", key); }
Errors
TODO
fn store_object(&mut self, req: StoreObjectReq) -> Result<(), RiakErr>
Stores an object on the Riak server.
Examples
use riak::Client; use riak::object::{ObjectContent, StoreObjectReq}; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let content = ObjectContent::new("This is a test!"); let mut req = StoreObjectReq::new("testbucket", content); req.set_key("testkey"); riak.store_object(req).unwrap();
Errors
TODO
fn fetch_object(
&mut self,
req: FetchObjectReq
) -> Result<FetchObjectResp, RiakErr>
&mut self,
req: FetchObjectReq
) -> Result<FetchObjectResp, RiakErr>
Fetches an object from the Riak server.
Examples
use riak::Client; use riak::object::FetchObjectReq; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let req = FetchObjectReq::new("testbucket", "testkey"); let object = riak.fetch_object(req).unwrap(); println!("testkey object contained: {:?}", object);
Errors
TODO
fn delete_object(&mut self, request: DeleteObjectReq) -> Result<(), RiakErr>
Deletes an object from Riak
Examples
use riak::Client; use riak::object::DeleteObjectReq; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let mut request = DeleteObjectReq::new("testbucket", "testkey"); request.set_dw(3); riak.delete_object(request).unwrap();
Errors
TODO
fn fetch_preflist<T: Into<Vec<u8>>>(
&mut self,
bucket: T,
key: T
) -> Result<Vec<PreflistItem>, RiakErr>
&mut self,
bucket: T,
key: T
) -> Result<Vec<PreflistItem>, RiakErr>
Fetch the preflist for a bucket/key combination.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let preflist = riak.fetch_preflist("testbucket", "testkey").unwrap(); for preflist_item in preflist { if preflist_item.is_primary { println!("found primary partition {:?} for key {:?} on node {:?}", preflist_item.partition, "testkey", preflist_item.node); } }
Errors
TODO
fn set_yokozuna_schema<T: Into<Vec<u8>>>(
&mut self,
name: T,
content: T
) -> Result<(), RiakErr>
&mut self,
name: T,
content: T
) -> Result<(), RiakErr>
Create a search schema
Examples
use riak::Client; use std::fs::File; use std::io::Read; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let mut xml: Vec<u8> = Vec::new(); let mut file = File::open("/tmp/riak-rust-client-default-schema.xml").unwrap(); let _ = file.read_to_end(&mut xml).unwrap(); let schema_name = "schedule".to_string().into_bytes(); riak.set_yokozuna_schema(schema_name, xml).unwrap();
Errors
TODO
fn get_yokozuna_schema<T: Into<Vec<u8>>>(
&mut self,
name: T
) -> Result<Vec<u8>, RiakErr>
&mut self,
name: T
) -> Result<Vec<u8>, RiakErr>
Retrieve a search schema
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); riak.get_yokozuna_schema("schedule").unwrap();
Errors
TODO
fn set_yokozuna_index(&mut self, index: YokozunaIndex) -> Result<(), RiakErr>
set a search index
Examples
use riak::Client; use riak::yokozuna::YokozunaIndex; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let index = YokozunaIndex::new("myindex"); riak.set_yokozuna_index(index).unwrap();
Errors
TODO
fn get_yokozuna_index<T: Into<Vec<u8>>>(
&mut self,
name: T
) -> Result<Vec<YokozunaIndex>, RiakErr>
&mut self,
name: T
) -> Result<Vec<YokozunaIndex>, RiakErr>
get a search index
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); riak.get_yokozuna_index("myindex").unwrap();
Errors
TODO
fn delete_yokozuna_index<T: Into<Vec<u8>>>(
&mut self,
name: T
) -> Result<(), RiakErr>
&mut self,
name: T
) -> Result<(), RiakErr>
Deletes an index
Examples
use riak::Client; use riak::yokozuna::YokozunaIndex; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let index = YokozunaIndex::new("deleteme"); riak.set_yokozuna_index(index).unwrap(); riak.delete_yokozuna_index("deleteme").unwrap();
Errors
TODO
fn search(&mut self, query: SearchQuery) -> Result<SearchQueryResp, RiakErr>
Perform a Riak Search
Examples
use riak::Client; use riak::yokozuna::SearchQuery; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let mut query = SearchQuery::new("test*", "myindex"); query.set_df("_yz_id"); riak.search(query).unwrap();
fn mapreduce<T: Into<Vec<u8>>>(
&mut self,
request: T,
content_type: T
) -> Result<Vec<Vec<u8>>, RiakErr>
&mut self,
request: T,
content_type: T
) -> Result<Vec<Vec<u8>>, RiakErr>
Perform a MapReduce Job
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let job = r#" {"inputs": "bucket_501653", "query": [ {"map": { "arg": null, "name": "Riak.mapValuesJson", "language": "javascript", "keep": false }}, {"reduce": { "arg": null, "name": "Riak.reduceSum", "language": "javascript", "keep": true }} ]} "#; riak.mapreduce(job, "application/json").unwrap();
Errors
TODO
fn data_type_fetch(
&mut self,
request: DataTypeFetchReq
) -> Result<DataTypeFetchResp, RiakErr>
&mut self,
request: DataTypeFetchReq
) -> Result<DataTypeFetchResp, RiakErr>
Data Type Fetch
Examples
use riak::Client; use riak::data_type::DataTypeFetchReq; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let req = DataTypeFetchReq::new("sets", "bucket", "key"); riak.data_type_fetch(req).unwrap();
fn secondary_index_request_streaming(
&mut self,
req: IndexReq
) -> Result<SecondaryIndexStream, RiakErr>
&mut self,
req: IndexReq
) -> Result<SecondaryIndexStream, RiakErr>
Secondary Index Request - Streaming
Examples
use riak::Client; use riak::bucket::BucketTypeProps; use riak::object::{ObjectContent, StoreObjectReq}; use riak::secondary_index::{IndexReq, IndexQueryType}; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let mut bucket_type_props = BucketTypeProps::new("2itest"); bucket_type_props.set_backend("leveldb"); riak.set_bucket_type_properties(bucket_type_props).unwrap(); let mut content = ObjectContent::new("This is a test!"); content.set_indexes(vec![("test_bin".as_bytes().to_vec(), "test2i".as_bytes().to_vec())]); let mut req = StoreObjectReq::new("2itestbucket", content); req.set_bucket_type("2itest"); req.set_key("testkey2i"); riak.store_object(req).unwrap(); let mut req = IndexReq::new("2itest", "2itestbucket", "test_bin", IndexQueryType::EQ); req.set_key("test2i"); req.set_pagination_sort(true); let mut stream = riak.secondary_index_request_streaming(req).unwrap(); stream.all().unwrap();
fn secondary_index_request_non_streaming(
&mut self,
req: IndexReq
) -> Result<IndexResp, RiakErr>
&mut self,
req: IndexReq
) -> Result<IndexResp, RiakErr>
Secondary Index Request - Non-Streaming
Examples
use riak::Client; use riak::bucket::BucketTypeProps; use riak::object::{ObjectContent, StoreObjectReq}; use riak::secondary_index::{IndexReq, IndexQueryType}; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let mut bucket_type_props = BucketTypeProps::new("2itest"); bucket_type_props.set_backend("leveldb"); riak.set_bucket_type_properties(bucket_type_props).unwrap(); let mut content = ObjectContent::new("This is a test!"); content.set_indexes(vec![("test_bin".as_bytes().to_vec(), "test2i".as_bytes().to_vec())]); let mut req = StoreObjectReq::new("2itestbucket", content); req.set_bucket_type("2itest"); req.set_key("testkey2i"); riak.store_object(req).unwrap(); let mut req = IndexReq::new("2itest", "2itestbucket", "test_bin", IndexQueryType::EQ); req.set_key("test2i"); req.set_pagination_sort(true); riak.secondary_index_request_non_streaming(req).unwrap();
Errors
TODO