Search code examples
phpudfaerospike

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);

Solution

  • 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   
      else
        return nil   
      end 
    end 
    return category_filters
    

    Invoked by

    $status = $list->scan($results, 'category_filters', 'filterBy', array($category));