bool scache_rnunshift(resource session, string path, mixed value)
bool $SCacheConnection->rnunshift(string path, mixed value)

scache_rnunshift stores value as a first element to begin of a ring in given path. Element on current position of ring will move to second position on ring.

Though by definition ring has no ends - and neither has scached-rings - ring contains current position that can be changed with rotate function scache_rotf and scache_rnrotb. With scache_rnpush value is added as position preceding the current position. scache_rnunshift does opposite adding value to first element moving current first element to second position..

As like all other scached-functions, ring supports pathed keys. If existing multilevel path is overwritten on upper level, descending nodes are overwritten.


Session resource returned from scache_open, scache_reset or scache_connect
Slash (/) separated null-terminated path on backend's session tree
Value to be stored. Must be serialize()able.

Return values

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


Rings are generally useful for implementing FIFOs and LIFOs (queues and stacks). Most common user would be web clients feeding data to work-queues to be consumed by separate dedicated external server process.

In work-queue setups, special considerations need to be taken to ensure there is always some consumer to consume queue-pushed data. As a safety measure, ring has size limits. After exceeding limits, additions will fail with SCERR_LIMITS_REACHED.

Due to nature of ring-type implementation there is no performance penalties on operating on either end of ring.


$conn = scache_reset(md5(uniqid()));

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

/* Backward FIFO (Queue) */
scache_rnunshift($conn, 'queue', 1); // as first element
scache_rnunshift($conn, 'queue', 2); // as first element
scache_rnunshift($conn, 'queue', 3); // as first element
echo scache_rnpop($conn, 'queue') . "\n"; // purge from end, displays 1
echo scache_rnpop($conn, 'queue') . "\n"; // displays 2
echo scache_rnpop($conn, 'queue') . "\n"; // displays 3

/* Backward LIFO (Stack) */
scache_rnunshift($conn, 'queue', 1); // return true
scache_rnunshift($conn, 'queue', 2); // return true
scache_rnunshift($conn, 'queue', 3); // return true
echo scache_rnshift($conn, 'queue') . "\n"; // displays 3
echo scache_rnshift($conn, 'queue') . "\n"; // displays 2
echo scache_rnshift($conn, 'queue') . "\n"; // displays 1