How to find a property listing in kvs

How to find a record by property or predicate function in kvs? For instance:

kvs:find(fun(X) -> X#user.name == "Alexander").

I can use this:

lists:filter(Predicate, kvs:all(entity)).

But I do not want to load all the records into memory.

+3
source share
1 answer

I found that kvs is a keystore, so we should only look for the entry with the keys specified in the entity table schema:

-record(user, {
   id,
   userName,
   password
}).

#table{name=user,fields=record_info(fields,user), keys = [userName]}

Then we can do this:

kvs:index(user, userName, "Alexander").
+4
source

All Articles