Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing page_state in result metadata for token based paging #85

Open
NathanBaulch opened this issue May 13, 2019 · 1 comment
Open

Comments

@NathanBaulch
Copy link

NathanBaulch commented May 13, 2019

I'm trying to implement token based paging in my project's API but it doesn't look like the page_state result metadata is exposed by Cassandra\Response\Result. Is there a recommended way to capture this value so my clients can request the next page at a later time?

For now I'm using the following hack to work around this:

$pageState = null;
while (true) {
    /** @var Result $res */
    $res = $cass->querySync('SELECT "key" FROM message', [], null, ['page_size' => 10, 'paging_state' => $pageState]);
    yield from $res->fetchCol();
    $pageState = CassandraResultMetadataAccessor::getPageState($res);
    if (!$pageState) break;
    echo 'DEBUG: paging token for client: ' . base64_encode($pageState) . "\n";
}

class CassandraResultMetadataAccessor extends Result
{
    public static function getPageState(Result $res) {
        return $res->_metadata['page_state'] ?? null;
    }
}
@NathanBaulch
Copy link
Author

OK, it looks like this has already been fixed in master, it's just that the most recent release v0.5.2 is 84 commits behind despite this project having no activity in the last 3.5 years. So I guess I'll try my chances with the latest unreleased code (I also need the unreleased Tuple support). My workaround above still applies if you're using the official release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant