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]

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

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

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);

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

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

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);

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

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

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("bitcask");

riak.set_bucket_properties(bucket_props).unwrap();

Errors

TODO

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

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("bitcask");

riak.set_bucket_type_properties(bucket_type_props).unwrap();

Errors

TODO

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

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

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

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

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

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

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

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

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

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

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

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

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

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();

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

Trait Implementations

impl Debug for Client
[src]

Formats the value using the given formatter.