コード例 #1
0
ファイル: RedisTest.php プロジェクト: bruensicke/li3_redis
 function testDelete()
 {
     $scope = __FUNCTION__;
     Redis::config(array('format' => $scope));
     $this->assertEqual('test', $this->redis->set("{$scope}:bar", 'test'));
     $this->assertEqual(1, Redis::delete('bar'));
     $this->assertEqual(1, $this->redis->incr("{$scope}:baz"));
     $this->assertEqual(1, Redis::delete('baz'));
     $this->assertEqual(0, Redis::delete('non-existent'));
     $this->assertTrue($this->redis->hMset("{$scope}:foo", array('name' => 'Joe', 'salary' => 2000)));
     $this->assertEqual(1, Redis::delete('foo'));
 }
コード例 #2
0
ファイル: Stats.php プロジェクト: bruensicke/li3_redis
 /**
  * delete given values from Stats, or a whole stats set at once
  *
  * {{{
  *   Stats::delete('foo'); // will remove the whole set
  *   Stats::delete('foo', 'field'); // will remove `field` from `foo`
  *   Stats::delete('foo', array('field')); // same as above
  *   Stats::delete('foo', array('field1', 'field2')); // will remove both fields from `foo`
  * }}}
  *
  *
  * @see li3_redis\storage\Stats::inc()
  * @see li3_redis\storage\Redis::getKey()
  * @param string $key redis key which identifies the hash
  * @param string|array $fields a string to remove a field from given hash or an array thereof.
  * @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 count of values that has been removed
  * @filter
  */
 public static function delete($key, $fields = null, $buckets = 'global', array $options = array())
 {
     $defaults = array('namespace' => static::$namespace);
     $options += $defaults;
     $params = compact('key', 'fields', 'buckets', 'options');
     return static::_filter(__METHOD__, $params, function ($self, $params) {
         extract($params);
         $result = array();
         $buckets = !is_array($buckets) ? array($buckets) : $buckets;
         foreach ($buckets as $prefix => $val) {
             $options['prefix'] = !is_numeric($prefix) ? Redis::addPrefix($val, $prefix) : $val;
             if (empty($fields)) {
                 $result[] = Redis::delete($key, $options);
             } else {
                 $return = Redis::deleteFromHash($key, $fields, $options);
                 $result[] = is_numeric($return) ? $return : array_sum($return);
             }
         }
         return array_sum($result);
     });
 }