scache_rnpop
Description
bool scache_rnpop(resource session, string path)
bool $SCacheConnection->rnpop(string path)
scache_rnpop retrieves last element from end of a ring in given path. First (ie. current) element can be retrieved with scache_rnshift.
Both scache_rnpop and scache_rnshift remove element from ring after retrieving while scache_rnget doesn't remove element it touches.
Parameters
session
path
Slash (/) separated null-terminated path on backend's session tree
Return values
Stored content on success or FALSE if given path does not exist or error occurred.
In case of failure, error codes resolvable by scache_lasterr is one of below :
- SCERR_NOTEXIST Path given does not exist.
- SCERR_NO_SESSION Connected session does not exist or has been expired. Connection is not valid any more.
- SCERR_NO_ACCESS Caching is not allowed on assigned partition.
- SCERR_LIMITS_REACHED Partition has exceeded its memory or node limits and new session cannot be created until memory is freed.
- SCERR_NOT_CONNECTED Connection to backend is broken and cannot be reconnected.
- SCERR_PROTOCOL Internal protocol error has occurred when communicating to backend. This indicates something is severely broken.
Notes
scache_rnpush, scache_rnunshift, scache_rnpop and scache_rnshift are generally useful from implementing work queues.
Example
<?php $conn = scache_reset(md5(uniqid())); /* purge possible pre-existing */ scache_rnclear($conn, 'queue'); /* FIFO -purging */ scache_rnpush($conn, 'queue', 1); // as first element scache_rnpush($conn, 'queue', 2); // as first element scache_rnpush($conn, 'queue', 3); // as first element scache_rnsize($conn, 'queue'); // returns 3 scache_rnshift($conn, 'queue'); // returns 1 scache_rnsize($conn, 'queue'); // returns 2 scache_rnshift($conn, 'queue'); // returns 2 scache_rnsize($conn, 'queue'); // returns 1 ?>