SimpleRiak is a very simple riak HTTP client. It wraps request and simplifies the calls made to riak as much as possible.
Usage
WARNING
There is a breaking change in SimpleRiak 0.1.0. When doing getKeys, get, or mapred with multiple indexes, they are no longer specified in an array. Use an object with multiple keys instead.
Installation
npm install simpleriak
Object creation
Host, port, and bucket are all optional. Host defaults to localhost and port to 8098. If bucket is present, it sets the default bucket to be used in future calls. If you don't set the bucket here, you must specify it in each call you make. Specifying a bucket in a call always takes precedence over the default.
var riak = ;
Callbacks
Every function returns the same callback pattern (err, reply).
err will be an Error object if any error is present reply is an object containing the following keys
- "statusCode" will be the HTTP status code returned from riak
- "data" will be the body of the HTTP response from riak
- "headers" is the complete HTTP headers returned from riak
- "key" when a location header is present, this property will contain the key in the header
List buckets
riak;
List keys
riak;
List keys (matching an index)
riak;
When using an index, you may either specify a start and end to be used with riak's range finding, or a key which will search for an exact match.
List keys (matching a search)
riak; riak;
Searching supports all query parameters supported by the Riak Solr interface.
List indexes (matching a key)
riak;
This is a utility function to retrieve and parse the indexes associated with a key. It can be useful, for instance if you store permissions in an index and need to check it before acting on the key.
Get bucket properties
riak;
Set bucket properties
riak;
You can specify any editable property for a bucket.
Get data (by key)
riak;
Get data (by index)
riak;
When fetching data by index, the reply data will always be an array. This usage is actually an interface to the MapReduce function (described later) that fetches the keys and uses the Riak.mapValuesJson map phase to return data. Note that you can specify multiple indexes.
riak;
Get data (by search)
riak;
Store data (Riak created key)
riak;
Store data (User specified key)
riak;
Store data (with an index)
riak;
You can specify as many indexes as you like, the property name will be the index and its value the key.
Delete a key
riak;
Note that this function does not work with an index, this is by design. If you need to delete all keys that match an index, use getKeys and iterate the results.
Modify a key's contents
SimpleRiak includes a simple modify function that performs a GET request, alters the response, then saves it back to the correct key.
{ return data + ' is now changed!';} riak;
Note that this function only works by key. The index property here is used to modify the indexes stored for the specific key. To remove an index completely, set its value to undefined.
riak;
MapReduce
{ var ret = index = vvalues0metadataindex; if indexcreator_bin === arg ret; return ret;}; riak;
The MapReduce function can take map and reduce phases as either an object (shown above), a string
riak;
or a function directly
riak;
You may specify a bucket, a bucket and key, an array of keys, or a bucket and an index using an exact match or range. Indexes and search inputs are run through getKeys and the resulting array passed to mapreduce, so this input also supports matching on multiple indexes and full search query parameters.
riak;riak; // default bucket is usedriak;riak;riak;
Search
riak;
All parameters allowed by the Solr interface are allowed here and are passed directly through. The response will come back in the same format as MapReduce. The numFound, start, and params data normally returned by Solr can be found in the headers property of the reply.
Ping
riak;
Stats
riak;
Resources
riak;