How to provide a user defined keyFunction for use in LDTs


I’m using Java client to access aerospike. I wanted to pass a user defined keyFunction to get unique value for each object. How can I do that from java?

I would also like to know, what’s the use of userModule parameter in all LDT’s and how can we use it in Java. I’m not able to find any good examples of UDF’s being used from Java Code.

client.getLargeSet(WritePolicy policy, Key key, String binName, String userModule)

Anshu keyFunction in LDT on the server side feature is going to deprecated as it add unnecessary burden on server side. Suggest you run the function client side (which is better scaling model) and send the key when inserting data into LDT. I assume your question is in context of LLIST / LMAP. Lset does not have notion of key it only has values.

UserModule is a lua function which user register to create the functions which perform following functionality.


local mymodule = {}
function myfilter(rec)
    if rec['bin'] = 10 then
       return rec
       return nil
return mymodule;   

aql> register module 'mymodule.lua'

Above example is filter function definition. You can pass mymodule as module name and myfilter as filter name when making calls. Once registered server will pick it up

– R

Raj, Thanks for your Reply!!

How can I send the key when inserting data into LLIST.

Suppose I’ve a complex object with field “Long” and “String” and I want to keep my data sorted in LLIST on basis of “Long” so that if I do a range scan on “Long” I get my objects.

Code I’m using to create an LLIST is:

LargeList listMap = client.getLargeList(policy, key, "idsObj", null);
List<MyObject> idsListmap = new ArrayList<>();
idsListmap.add(new MyObject(113L, "c"));
idsListmap.add(new MyObject(114L, "d"));
idsListmap.add(new MyObject(111L, "a"));
idsListmap.add(new MyObject(112L, "b"));

Now I should be able to do a range scan using Longs such that passing range 111 to 112 gives me

MyObject(111L, "a")
MyObject(112L, "b")


It would look like

 LargeList listMap = client.getLargeList(policy, key, "idsObj", null);
 List<MyObject> idsListmap = new ArrayList<>();
 Map<String,Value> valueMap = new HashMap<String,Value>();

 valueMap.put("key", Value.get(113L));
 valueMap.put("value", Value.get("c"));
 valueMap.put("key", Value.get(114L));
 valueMap.put("value", Value.get("d"));

 valueMap.put("key", Value.get(111L));
 valueMap.put("value", Value.get("d"));


You can find many such examples in java client example folder.

– R