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.
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.
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.
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"; ?>