The bulk getBulk() methods allow you to
get one or more items from the database in a single request. Using
the bulk methods is more efficient than multiple single requests
as the operation can be conducted in a single network call.
| API Call | client.getBulk(keycollection) | ||
| Asynchronous | no | ||
| Description | Get one or more key values | ||
| Returns | Map<String,Object> (
Map of Strings/Objects
) | ||
| Arguments | |||
Collection<String> keycollection | One or more keys used to reference a value | ||
The first format accepts a String
Collection as the request argument which is
used to specify the list of keys that you want to retrieve. The
return type is Map between the keys and object
values.
For example:
Map<String,Object> keyvalues = client.getBulk(keylist); System.out.printf("A is %s\n",keyvalues.get("keyA")); System.out.printf("B is %s\n",keyvalues.get("keyB")); System.out.printf("C is %s\n",keyvalues.get("keyC"));
The returned map will only contain entries for keys that exist from the original request. For example, if you request the values for three keys, but only one exists, the resultant map will contain only that one key/value pair.
| API Call | client.getBulk(keycollection, transcoder) | ||
| Asynchronous | no | ||
| Description | Get one or more key values | ||
| Returns | Map<String,T> (
Map of Strings/Transcoded objects
) | ||
| Arguments | |||
Collection<String> keycollection | One or more keys used to reference a value | ||
Transcoder<T> transcoder | Transcoder class to be used to serialize value | ||
The second form of the getBulk() method
supports the same Collection argument, but also
supports the use of a custom transcoder on the returned values.
The specified transcoder will be used for every value requested from the database.
| API Call | client.getBulk(keyn) | ||
| Asynchronous | no | ||
| Description | Get one or more key values | ||
| Returns | Map<String,Object> (
Map of Strings/Objects
) | ||
| Arguments | |||
String... keyn | One or more keys used to reference a value | ||
The third form of the getBulk() method
supports a variable list of arguments with each interpreted as the
key to be retrieved from the database.
For example, the equivalent of the Collection
method operation using this method would be:
Map<String,Object> keyvalues = client.getBulk("keyA","keyB","keyC"); System.out.printf("A is %s\n",keyvalues.get("keyA")); System.out.printf("B is %s\n",keyvalues.get("keyB")); System.out.printf("C is %s\n",keyvalues.get("keyC"));
The return Map will only contain entries for
keys that exist. Non-existent keys will be silently ignored.
| API Call | client.getBulk(transcoder, keyn) | ||
| Asynchronous | no | ||
| Description | Get one or more key values | ||
| Returns | Map<String,T> (
Map of Strings/Transcoded objects
) | ||
| Arguments | |||
Transcoder<T> transcoder | Transcoder class to be used to serialize value | ||
String... keyn | One or more keys used to reference a value | ||
The fourth form of the getBulk() method uses
the variable list of arguments but supports a custom transcoder.
Note that unlike other formats of the methods used for supporting custom transcoders, the transcoder specification is at the start of the argument list, not the end.
| API Call | client.asyncGetBulk(keycollection) | ||
| Asynchronous | yes | ||
| Description | Get one or more key values | ||
| Returns | BulkFuture<Map<String,Object>> (
Map of Strings/Objects
) | ||
| Arguments | |||
Collection<String> keycollection | One or more keys used to reference a value | ||
The asynchronous getBulk() method
supports a Collection of keys to be retrieved,
returning a BulkFuture object (part of the
spymemcached package) with the returned map of
key/value information. As with other asynchronous methods, the
benefit is that you do not need to actively wait for the response.
The BulkFuture object operates slightly
different in context to the standard Future
object. Whereas the Future object gets a
returned single value, the BulkFuture object
will return an object containing as many keys as have been
returned. For very large queries requesting large numbers of keys
this means that multiple requests may be required to obtain every
key from the original list.
For example, the code below will obtain as many keys as possible
from the supplied Collection.
BulkFuture<Map<String,Object>> keyvalues = membase.asyncGetBulk(keylist); Map<String,Object> keymap = keyvalues.getSome(5,TimeUnit.SECONDS); System.out.printf("A is %s\n",keymap.get("keyA")); System.out.printf("B is %s\n",keymap.get("keyB")); System.out.printf("C is %s\n",keymap.get("keyC"));
| API Call | client.asyncGetBulk(keycollection, transcoder) | ||
| Asynchronous | yes | ||
| Description | Get one or more key values | ||
| Returns | BulkFuture<Map<String,T>> (
Map of Strings/Transcoded objects
) | ||
| Arguments | |||
Collection<String> keycollection | One or more keys used to reference a value | ||
Transcoder<T> transcoder | Transcoder class to be used to serialize value | ||
The second form of the asynchronous getBulk()
method supports the custom transcoder for the returned values.
| API Call | client.asyncGetBulk(keyn) | ||
| Asynchronous | yes | ||
| Description | Get one or more key values | ||
| Returns | BulkFuture<Map<String,Object>> (
Map of Strings/Objects
) | ||
| Arguments | |||
String... keyn | One or more keys used to reference a value | ||
The third form is identical to the multi-argument key request
method (see
collection
based asyncBulkGet()), except that the
operation occurs asynchronously.
| API Call | client.asyncGetBulk(transcoder, keyn) | ||
| Asynchronous | yes | ||
| Description | Get one or more key values | ||
| Returns | BulkFuture<Map<String,T>> (
Map of Strings/Transcoded objects
) | ||
| Arguments | |||
Transcoder<T> transcoder | Transcoder class to be used to serialize value | ||
String... keyn | One or more keys used to reference a value | ||
The final form of the asyncGetBulk()
method supports a custom transcoder with the variable list of keys
supplied as arguments.