Beispiel #1
0
 function testAddPrefix()
 {
     $expected = 'bar:foo';
     $this->assertEqual($expected, Redis::addPrefix('foo', 'bar'));
     $expected = 'foo:bar';
     $this->assertEqual($expected, Redis::addPrefix('bar', 'foo'));
     $expected = 'foo!bar';
     $this->assertEqual($expected, Redis::addPrefix('bar', 'foo', array('separator' => '!')));
     $expected = 'fooHELPbar';
     $this->assertEqual($expected, Redis::addPrefix('bar', 'foo', array('separator' => 'HELP')));
     $expected = 'foo.bar';
     $this->assertEqual($expected, Redis::addPrefix('bar', 'foo', array('separator' => '.')));
     $expected = 'bar';
     $this->assertEqual($expected, Redis::addPrefix('bar', '', array('separator' => '!')));
     $expected = 'foo';
     $this->assertEqual($expected, Redis::addPrefix('foo'));
     $expected = 'foo';
     $this->assertEqual($expected, Redis::addPrefix('', 'foo'));
 }
Beispiel #2
0
 /**
  * get amount of items within a list from redis
  *
  * {{{
  *   Lists::count('key');
  *   Lists::count('key', array('user' => 'foo', 'global')); // for multiple buckets at once
  * }}}
  *
  * @see li3_redis\storage\Redis::listLength()
  * @see li3_redis\storage\Redis::getKey()
  * @param string $key The key to uniquely identify the item in redis
  * @param string|array $buckets an array of additional prefixes, can be a numerical indexed
  *        array with strings, or an associated array, in which the key and value will be glued
  *        together by a separater or just a string, for one additional prefix.
  * @param array $options array with additional options, see Redis::getKey()
  * @return integer|boolean the number of values in that list, false if key does not exist
  * @filter
  */
 public static function count($key, $buckets = null, array $options = array())
 {
     $defaults = array('namespace' => static::$namespace);
     $options += $defaults;
     $params = compact('key', 'buckets', 'options');
     return static::_filter(__METHOD__, $params, function ($self, $params) {
         extract($params);
         if (is_null($buckets)) {
             return Redis::listLength($key, $options);
         }
         $result = array();
         $buckets = !is_array($buckets) ? array($buckets) : $buckets;
         foreach ($buckets as $prefix => $val) {
             $options['prefix'] = !is_numeric($prefix) ? Redis::addPrefix($val, $prefix) : $val;
             $result[$options['prefix']] = Redis::listLength($key, $options);
         }
         return count($result) > 1 ? $result : array_shift($result);
     });
 }