riakcached.clients

class riakcached.clients.RiakClient(bucket, pool=None)[source]

A Memcache like client to the Riak HTTP Interface

Constructor for a new riakcached.clients.RiakClient

Pool - if no pool is provided then a default riakcached.pools.Urllib3Pool is used

Parameters:
add_deserializer(content_type, deserializer)[source]

Add a content-type deserializer to the client

The deserializer function should have the following definition:

def deserializer(data):
    return undo_something(data)

Example:

def base64_deserializer(data):
    return base64.b64decode(data)
client.add_deserializer("application/base64", base64_deserializer)
Parameters:
  • content_type (str) – the content-type to associate deserializer with
  • deserializer (function) – the deserializer function to use with content_type
add_serializer(content_type, serializer)[source]

Add a content-type serializer to the client

The serializer function should have the following definition:

def serializer(data):
    return do_something(data)

and should return a str

Example:

def base64_serializer(data):
    return base64.b64encode(data)
client.add_serializer("application/base64", base64_serializer)
Parameters:
  • content_type (str) – the content-type to associate serializer with
  • serializer (function) – the serializer function to use with content_type
delete(key)[source]

Delete the provided key from the client’s bucket

Parameters:key (str) – the key to delete
Returns:bool - True if the key was removed, False otherwise
Raises :riakcached.exceptions.RiakcachedBadRequest
delete_many(keys)[source]

Delete multiple keys at once from the client’s bucket

Parameters:keys (list) – list of str keys to delete
Returns:dict - the keys are the keys provided and the values are True or False from the calls to delete()
Raises :riakcached.exceptions.RiakcachedBadRequest
deserialize(data, content_type)[source]

Deserialize the provided data from content_type

This method will lookup the registered deserializer for the provided Content-Type (defaults to str(data)) and passes data through the deserializer.

Parameters:
  • data (str) – the data to deserialize
  • content_type (str) – the Content-Type to deserialize data from
Returns:

object - whatever the deserializer returns

get(key, counter=False)[source]

Get the value of the key from the client’s bucket

Parameters:
  • key (str) – the key to get from the bucket
  • counter (bool) – whether or not the key is a counter
Returns:

object - the deserialized value of key

Returns:

None - if the call was not successful or the key was not found

Raises :

riakcached.exceptions.RiakcachedBadRequest

Raises :

riakcached.exceptions.RiakcachedServiceUnavailable

get_many(keys)[source]

Get the value of multiple keys at once from the client’s bucket

Parameters:keys (list) – the list of keys to get
Returns:dict - the keys are the keys provided and the values are the results from calls to get(), except keys whose values are None are not included in the result
Raises :riakcached.exceptions.RiakcachedBadRequest
Raises :riakcached.exceptions.RiakcachedServiceUnavailable
incr(key, value=1)[source]

Increment the counter with the provided key

Parameters:
  • key (str) – the counter to increment
  • value (int) – how much to increment by
Returns:

bool - True/False whether or not it was successful

Raises :

riakcached.exceptions.RiakcachedConflict

Raises :

riakcached.exceptions.RiakcachedBadRequest

keys()[source]

Get a list of all keys

Returns:list - list of keys on the server
Returns:None - when the call is not successful
ping()[source]

Ping the server to ensure it is up

Returns:bool - True if it is successful, False otherwise
props()[source]

Get the properties for the client’s bucket

Returns:dict - the bucket‘s set properties
Returns:None - when the call is not successful
serialize(data, content_type)[source]

Serialize the provided data to content_type

This method will lookup the registered serializer for the provided Content-Type (defaults to str(data)) and passes data through the serializer.

Parameters:
  • data (object) – the data to serialize
  • content_type (str) – the desired Content-Type for the provided data
Returns:

str - the serialized data

set(key, value, content_type='text/plain')[source]

Set the value of a key for the client’s bucket

Parameters:
  • key (str) – the key to set the value for
  • value (object) – the value to set, this will get serialized for the content_type
  • content_type (str) – the Content-Type for value
Returns:

bool - True if the call is successful, False otherwise

Raises :

riakcached.exceptions.RiakcachedBadRequest

Raises :

riakcached.exceptions.RiakcachedPreconditionFailed

set_many(values, content_type='text/plain')[source]

Set the value of multiple keys at once for the client’s bucket

Parameters:
  • values (dict) – the key -> value pairings for the keys to set
  • content_type (str) – the Content-Type for all of the values provided
Returns:

dict - the keys are the keys provided and the values are True or False from the calls to set()

Raises :

riakcached.exceptions.RiakcachedBadRequest

Raises :

riakcached.exceptions.RiakcachedPreconditionFailed

set_props(props)[source]

Set the properties for the client’s bucket

Parameters:props (dict) – the properties to set
Returns:bool - True if it is successful otherwise False
stats()[source]

Get the server stats

Returns:dict - the stats from the server
Returns:None - when the call is not successful
class riakcached.clients.ThreadedRiakClient(bucket, pool=None)[source]

A threaded version of riakcached.clients.RiakClient

The threaded version uses threads to try to parallelize the {set,get,delete}_many method calls

Constructor for a new riakcached.clients.RiakClient

Pool - if no pool is provided then a default riakcached.pools.Urllib3Pool is used

Parameters:
delete_many(keys)[source]

Delete multiple keys at once from the client’s bucket

Parameters:keys (list) – list of str keys to delete
Returns:dict - the keys are the keys provided and the values are True or False from the calls to delete()
Raises :riakcached.exceptions.RiakcachedBadRequest
get_many(keys)[source]

Get the value of multiple keys at once from the client’s bucket

Parameters:keys (list) – the list of keys to get
Returns:dict - the keys are the keys provided and the values are the results from calls to get(), except keys whose values are None are not included in the result
Raises :riakcached.exceptions.RiakcachedBadRequest
Raises :riakcached.exceptions.RiakcachedServiceUnavailable
set_many(values)[source]

Set the value of multiple keys at once for the client’s bucket

Parameters:
  • values (dict) – the key -> value pairings for the keys to set
  • content_type (str) – the Content-Type for all of the values provided
Returns:

dict - the keys are the keys provided and the values are True or False from the calls to set()

Raises :

riakcached.exceptions.RiakcachedBadRequest

Raises :

riakcached.exceptions.RiakcachedPreconditionFailed

Table Of Contents

Previous topic

Riakcached documentation

Next topic

riakcached.exceptions

This Page