Пример #1
0
<?php

/**
 * This example shows a series of number additions and subtractions pulled from
 * an array of up/down scores.
 */
include "vendor/autoload.php";
/**
 * Create the redis object and initialise a connection.
 */
$helper = new RedisHelper\RedisHelper();
$helper->connect(true, 'localhost', 6379, '');
$ourKey = "our_vote_site_key";
$ourNumber = 100;
$helper->set($ourKey, $ourNumber);
$votes = [['type' => 'down', 'value' => 1], ['type' => 'up', 'value' => 1], ['type' => 'up', 'value' => 3], ['type' => 'down', 'value' => 2]];
foreach ($votes as $vote) {
    echo "Rolling count: ";
    if ($vote['type'] == 'down') {
        echo $helper->subtract($ourKey, $vote['value'])->get($ourKey) . "\n";
    } else {
        echo $helper->add($ourKey, $vote['value'])->get($ourKey) . "\n";
    }
}