scache_rnget
Description
bool scache_rnget(resource session, string path)
bool $SCacheConnection->rnget(string path)
scache_rnget retrieves first (ie. current) element from begin of a ring in given path. Unlike scache_rnshift, scache_rnget does not remove element after retrieving.
Parameters
session
path
Slash (/) separated null-terminated path on backend's session tree
Return values
TRUE on success, FALSE on fail. On FALSE scache_lasterr returns last error code which 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
Polling other positions can be done with scache_iov. Example of retrieving last element of ring :
<?php $conn = scache_reset(md5(uniqid())); function scache_rngetlast($conn, $path) { list($dummy1, $val, $dummy2) = scache_iov($conn, Array(Array(SCIOP_RNROTB, $path, 1), Array(SCIOP_RNGET, $path), Array(SCIOP_RNROTF, $path, 1))); return $val; } /* purge possible pre-existing */ scache_rnclear($conn, 'queue'); /* populate ring */ scache_rnpush($conn, 'queue', 1); // to last element scache_rnpush($conn, 'queue', 2); // to last element scache_rnpush($conn, 'queue', 3); // to last element echo "Last-1: " . scache_rngetlast($conn, 'queue') . "\n"; // displays 3 echo "Last-2: " . scache_rngetlast($conn, 'queue') . "\n"; // displays 3 ?>
To ensure proper concurrency with other accessing clients, temporal rotations must not be done with separate rotate function. Operations through scache_iov are atomic.