Beispiel #1
0
 public function show($name)
 {
     $stats = StatsCore::get($name);
     $max = max(array_map('strlen', array_keys($stats)));
     foreach ($stats as $key => $value) {
         $this->out(sprintf("%{$max}s: %s", $key, $value));
     }
 }
Beispiel #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')));
 }