scache_rnrotb

Description

bool scache_rnrotb(resource session, string path, long count)
bool $SCacheConnection->rnrotb(string path, long count)

Rings have current position on what inserts and removes occur. Current position is regarded ring's first element and can be changed by rotating ring with scache_rnrotb and scache_rnrotf functions.

scache_rnrotb rotates ring backwards in given path given count of steps. When rotating ring one step backwards, current element becomes second element of ring and last element becomes first ie. current element.

Parameters

session
Session resource returned from scache_open, scache_reset or scache_connect
path
Slash (/) separated null-terminated path on backend's session tree
count
Number of steps to rotate. Negative number rotates to oppisite direction

Return values

TRUE on success, FALSE on fail. On FALSE scache_lasterr returns last error code which is one of below :

Notes

Rotate functions allows negative stepping. Rotating one step backwards equals rotating -1 steps forward.

In practice rotating and accessing resulting rotated ring should be always done through scache_iov to abolish risk of other clients modifying ring for it's own needs.

Example

Atomic way of rotating and accessing value :

<?php
$conn = scache_reset(md5(uniqid()));

/* purge possible pre-existing */
scache_rnclear($conn, 'queue');

/* populate ring */
scache_rnpush($conn, 'queue', 1); // as first element
scache_rnpush($conn, 'queue', 2); // as first element
scache_rnpush($conn, 'queue', 3); // as first element

list($dummy, $val) =
    scache_iov($conn,
               Array(Array(SCIOP_RNROTF, 'queue', 1),
	             Array(SCIOP_RNGET, 'queue')));

echo "Return value: $val\n";
?>