Skip to content
Visit booth 3171 at Google Cloud Next to see how to unlock real-time decisions at scaleMore info

Bin operations

You can use the Rust client API to perform separate operations on multiple bins in a record in a single command. This feature allows the application to modify and read bins of a record in a single transaction (that is, perform an atomic modification that returns the result).

Some record operations include:

OperationDescriptionConditions
writeWrite a value to a bin.
getRead the value of a bin.
get_headerRead only the metadata (generation and time-to-live) of the record.
addAdd an integer to the existing value of the bin.The existing value must be integer.
appendAppend a string to the existing value of the bin.The existing value must be string.
prependPrepend a string to the existing value of the bin.The existing value must be string.
touchRewrite the same record.Generation and time-to-live are updated.

Operation specification

To specify operations on different bins in the same transaction, create the bins with the values to apply:

let key = as_key!("test", "demoset", "opkey");
let bin1 = as_bin!("optintbin", 7);
let bin2 = as_bin!("optstringbin", "string value");
client.put(&policy, &key, &vec![&bin1, &bin2]).unwrap();
let bin3 = as_bin!(bin1.name, 4);
let bin4 = as_bin!(bin2.name, "new string");

Create the appropriate operations using the bins and supply them to the operate() function:

let ops = vec![
operations::add(&bin3),
operations::put(&bin4),
operations::get(),
];
match client.operate(&policy, &key, &ops) {
Ok(record) => println!("optintbin: {}", record.bins.get(bin1.name).unwrap()),
Err(err) => println!("Error writing record: {}", err),
}
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?