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, RiakError>
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, RiakError>
timeout: u32)
-> Result<Client, RiakError>
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<(), RiakError>
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<(), RiakError>
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), RiakError>
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, RiakError>
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<String>, RiakError>
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_name: &str,
bucket_props: &BucketProps)
-> Result<(), RiakError>
bucket_name: &str,
bucket_props: &BucketProps)
-> Result<(), RiakError>
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(); bucket_props.set_backend("bitcask"); riak.set_bucket_properties("superheroes", &bucket_props).unwrap();
Errors
TODO
fn get_bucket_properties(&mut self,
bucket_name: &str)
-> Result<BucketProps, RiakError>
bucket_name: &str)
-> Result<BucketProps, RiakError>
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(); let bucket_props = riak.get_bucket_properties("superheroes").unwrap(); println!("bucket properties for superheroes: {:?}", bucket_props);
Errors
TODO
fn set_bucket_type_properties(&mut self,
bucket_type_name: &str,
bucket_type_props: &BucketProps)
-> Result<(), RiakError>
bucket_type_name: &str,
bucket_type_props: &BucketProps)
-> Result<(), RiakError>
Assigns a set of bucket properties to a bucket type.
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(); bucket_props.set_backend("bitcask"); riak.set_bucket_type_properties("comicbooks", &bucket_props).unwrap();
Errors
TODO
fn get_bucket_type_properties(&mut self,
bucket_type_name: &str)
-> Result<BucketProps, RiakError>
bucket_type_name: &str)
-> Result<BucketProps, RiakError>
Gets the bucket properties associated with a bucket type.
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); let props = riak.get_bucket_type_properties("comicbooks").unwrap(); println!("found bucket properties for type \"comicbooks\": {:?}", props);
Errors
TODO
fn reset_bucket(&mut self,
bucket_type: &str,
bucket: &str)
-> Result<(), RiakError>
bucket_type: &str,
bucket: &str)
-> Result<(), RiakError>
Resets the properties for a bucket
Examples
use riak::Client; let mut riak = Client::new("10.0.0.2:8087").unwrap(); riak.reset_bucket("default", "superheroes").unwrap();
Errors
TODO
fn stream_keys(&mut self, bucket: &str) -> Result<KeyStream, RiakError>
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("superheroes").unwrap(); loop { match keystream.next() { Some(keys_result) => println!("found keys {:?}", keys_result.unwrap()), None => break, }; }
Errors
TODO
fn list_keys(&mut self, bucket: &str) -> Result<Vec<String>, RiakError>
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("superheroes").unwrap(); for key in keys.iter() { println!("found key in bucket superheroes named {}", key); }
Errors
TODO
fn store_object(&mut self, req: &StoreObjectReq) -> Result<(), RiakError>
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 contents = ObjectContent::new("I am the night, I am Batman!".as_bytes()); let mut req = StoreObjectReq::new("superheroes", &contents); req.set_key("batman"); riak.store_object(&req).unwrap();
Errors
TODO
fn fetch_object(&mut self,
req: &FetchObjectReq)
-> Result<FetchObjectResp, RiakError>
req: &FetchObjectReq)
-> Result<FetchObjectResp, RiakError>
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("superheroes", "batman"); let object = riak.fetch_object(&req).unwrap(); println!("batman object contained: {:?}", object);
Errors
TODO
fn delete_object(&mut self, request: &DeleteObjectReq) -> Result<(), RiakError>
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("superheroes", "batman"); request.set_dw(3); riak.delete_object(&request).unwrap();
Errors
TODO
fn fetch_preflist(&mut self,
bucket: &str,
key: &str)
-> Result<Vec<PreflistItem>, RiakError>
bucket: &str,
key: &str)
-> Result<Vec<PreflistItem>, RiakError>
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("superheroes", "batman").unwrap(); for preflist_item in preflist { if preflist_item.is_primary { println!("found primary partition {} for key {} on node {}", preflist_item.partition, "batman", preflist_item.node); } }
Errors
TODO
fn set_yokozuna_schema(&mut self,
name: &str,
content: &Vec<u8>)
-> Result<(), RiakError>
name: &str,
content: &Vec<u8>)
-> Result<(), RiakError>
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(); riak.set_yokozuna_schema("schedule", &xml).unwrap();
Errors
TODO
fn get_yokozuna_schema(&mut self, name: &str) -> Result<Vec<u8>, RiakError>
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<(), RiakError>
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(&mut self,
name: &str)
-> Result<Vec<YokozunaIndex>, RiakError>
name: &str)
-> Result<Vec<YokozunaIndex>, RiakError>
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