user1997296 user1997296 - 1 year ago 150
PHP Question

Filtering aerospike LLIST

Can anyone please show me how to filter an Aerospike LLIST bin not by the key and return all the result using PHP.

In my case the bin 'notes' is containing many rows of key, title, desc & category. I can retrieve all rows using the following code but
I need to do a filter on the category and get the results of only those within the same category. If udf is needed please assist to show me the udf code as well and how to apply the filter to get the results.

$db = new Aerospike($config, false);<br/>
$key = $db->initKey('mynamespace', 'myset', $userid);<br/>
$list = new \Aerospike\LDT\LList($db, $key, 'notes');<br/>
$status = $list->scan($results);

Answer Source

Manage to modify the UDF as follows and it works.

  local category_filters = {} 
  function category_filters.filterBy(element,val)            
  if element['category'] == val[1] then
    return element   
    return nil   
return category_filters

Invoked by

$status = $list->scan($results, 'category_filters', 'filterBy', array($category));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download