Jamm\Memory\RedisObject::select_fx PHP Method

select_fx() public method

Select from storage via callback function
public select_fx ( callable $fx, boolean $get_array = false ) : mixed
$fx callable ($value, $key) - should return true to select key(s)
$get_array boolean
return mixed
    public function select_fx($fx, $get_array = false)
    {
        $arr = array();
        $prefix_length = strlen($this->prefix);
        $keys = $this->redis->Keys($this->prefix . '*');
        foreach ($keys as $key) {
            $index = substr($key, $prefix_length);
            $value = $this->read($index);
            if (empty($value)) {
                continue;
            }
            if ($fx($value, $index) === true) {
                if (!$get_array) {
                    return $value;
                } else {
                    $arr[$index] = $value;
                }
            }
        }
        if (!$get_array || empty($arr)) {
            return false;
        } else {
            return $arr;
        }
    }