Esempio n. 1
0
 function testAddMember()
 {
     $scope = __FUNCTION__;
     Redis::config(array('format' => $scope));
     $leaderboard = new Leaderboard('leaderboard');
     $leaderboard->removeMember('david');
     $this->assertEqual(1, $leaderboard->addMember('david', 69));
     $this->assertEqual(1, $this->redis->zSize($scope . ':' . $this->prefix . 'leaderboard'));
 }
Esempio n. 2
0
 function testSum()
 {
     $scope = __FUNCTION__;
     Redis::config(array('format' => $scope));
     $data1 = array('calls' => 140, 'fails' => 22);
     $data2 = array('calls' => 35, 'fails' => 3);
     $data3 = array('calls' => 17, 'fails' => 29);
     $this->assertTrue($this->redis->hMset("{$scope}:stats:global:foo", $data1));
     $this->assertTrue($this->redis->hMset("{$scope}:stats:prefix1:foo", $data2));
     $this->assertTrue($this->redis->hMset("{$scope}:stats:prefix2:foo", $data3));
     $this->assertEqual($data1, $this->redis->hGetAll("{$scope}:stats:global:foo"));
     $this->assertEqual($data2, $this->redis->hGetAll("{$scope}:stats:prefix1:foo"));
     $this->assertEqual($data3, $this->redis->hGetAll("{$scope}:stats:prefix2:foo"));
     // simplest call
     $this->assertEqual(array_sum(array_values($data1)), Stats::sum('foo'));
     // with one prefix
     $this->assertEqual(array_sum(array_values($data2)), Stats::sum('foo', 'prefix1'));
     // with one prefix as array
     $this->assertEqual(array_sum(array_values($data3)), Stats::sum('foo', array('prefix2')));
     // with two prefixes as flat array
     $expected = array('global' => array_sum(array_values($data1)), 'prefix2' => array_sum(array_values($data3)));
     $this->assertEqual($expected, Stats::sum('foo', array('global', 'prefix2')));
 }
Esempio n. 3
0
 function testDecrement()
 {
     $scope = __FUNCTION__;
     Redis::config(array('format' => $scope));
     $this->assertEqual(1, $this->redis->incr("{$scope}:foo"));
     $this->assertEqual(0, Redis::decrement('foo'));
     $this->assertEqual(-1, Redis::decrement('foo'));
     $this->assertEqual(-1, $this->redis->get("{$scope}:foo"));
     $this->assertEqual(-5, Redis::decrement('bar', 5));
     $this->assertEqual(-5, $this->redis->get("{$scope}:bar"));
     $this->assertEqual(-2, Redis::decrement('foo'));
     $this->assertEqual(-2, $this->redis->get("{$scope}:foo"));
     $this->assertEqual(-1, Redis::decrement('foo', 1, array('format' => $scope . ':test')));
     $this->assertEqual(-1, $this->redis->get("{$scope}:test:foo"));
     $this->assertEqual(-1, Redis::decrement('foo', 1, array('namespace' => 'bar')));
     $this->assertEqual(-1, $this->redis->get("{$scope}:bar:foo"));
     $this->assertEqual(-1, Redis::decrement('foo', 1, array('namespace' => 'bar', 'prefix' => 'baz')));
     $this->assertEqual(-1, $this->redis->get("{$scope}:bar:baz:foo"));
 }
Esempio n. 4
0
 function testCount()
 {
     $scope = __FUNCTION__;
     Redis::config(array('format' => $scope));
     $this->redis->rPush("{$scope}:lists:foo", 'bar');
     $this->redis->rPush("{$scope}:lists:foo", 'baz');
     $this->assertEqual(2, Lists::count('foo'));
     $this->redis->rPush("{$scope}:lists:foo", 'bam');
     $this->assertEqual(3, Lists::count('foo'));
     $this->assertEqual(3, Lists::size('foo'));
     $this->assertEqual(3, Lists::length('foo'));
 }
Esempio n. 5
0
<?php

use lithium\action\Dispatcher;
use lithium\console\Dispatcher as ConsoleDispatcher;
use li3_redis\storage\Redis;
/**
 * Apply filter to Dispatcher, to initialize Redis configuration
 */
Dispatcher::applyFilter('_call', function ($self, $params, $chain) {
    Redis::config();
    return $chain->next($self, $params, $chain);
});
ConsoleDispatcher::applyFilter('_call', function ($self, $params, $chain) {
    Redis::config();
    return $chain->next($self, $params, $chain);
});