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
Session resource returned from scache_open, scache_reset or scache_connect
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 :

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.