scache_rnrotf
Description
bool scache_rnrotf(resource session, string path, long count)
bool $SCacheConnection->rnrotf(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_rnrotf and scache_rnrotb functions.
scache_rnrotf rotates ring forward in given path given count of steps. When rotating ring one step forward, current element becomes last element of ring.
Parameters
session
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 :
- 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
Rotate functions allows negative stepping. Rotating one step forward equals rotating -1 steps backwards.
Example
Enumeration through all elements on ring :
<?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 for($i = 0, $count = scache_rnsize($conn, 'queue'); $i < $count; $i++) { echo "Pos $i: " . scache_rnget($conn, 'queue') . "\n"; scache_rnrotf($conn, 'queue', 1); } /* Displays Pos 0: 1 Pos 1: 2 Pos 2: 3 */ ?>