当前位置: 首页>>代码示例>>PHP>>正文


PHP Redis::hLen方法代码示例

本文整理汇总了PHP中Redis::hLen方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::hLen方法的具体用法?PHP Redis::hLen怎么用?PHP Redis::hLen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Redis的用法示例。


在下文中一共展示了Redis::hLen方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getParentById

 /**
  * 根据 category_id 获取顶级分类的信息
  * @param $categoriesId
  * @return array
  */
 public function getParentById($categoriesId)
 {
     if ($this->redis->hLen($this->redisParentChildKey) == 0) {
         $this->setRedisCategoryParentChild();
     }
     $parentId = $this->redis->hGet($this->redisParentChildKey, $categoriesId);
     return ['categories_id' => $parentId, 'categories_name' => $this->getCategoryNameById($parentId)];
 }
开发者ID:xidiao,项目名称:gxfenxi,代码行数:13,代码来源:CategoryRedis.php

示例2: testHashes

 public function testHashes()
 {
     $this->redis->delete('h', 'key');
     $this->assertTrue(0 === $this->redis->hLen('h'));
     $this->assertTrue(TRUE === $this->redis->hSet('h', 'a', 'a-value'));
     $this->assertTrue(1 === $this->redis->hLen('h'));
     $this->assertTrue(TRUE === $this->redis->hSet('h', 'b', 'b-value'));
     $this->assertTrue(2 === $this->redis->hLen('h'));
     $this->assertTrue('a-value' === $this->redis->hGet('h', 'a'));
     // simple get
     $this->assertTrue('b-value' === $this->redis->hGet('h', 'b'));
     // simple get
     $this->assertTrue(FALSE === $this->redis->hSet('h', 'a', 'another-value'));
     // replacement
     $this->assertTrue('another-value' === $this->redis->hGet('h', 'a'));
     // get the new value
     $this->assertTrue('b-value' === $this->redis->hGet('h', 'b'));
     // simple get
     $this->assertTrue(FALSE === $this->redis->hGet('h', 'c'));
     // unknown hash member
     $this->assertTrue(FALSE === $this->redis->hGet('key', 'c'));
     // unknownkey
     // hDel
     $this->assertTrue(TRUE === $this->redis->hDel('h', 'a'));
     // TRUE on success
     $this->assertTrue(FALSE === $this->redis->hDel('h', 'a'));
     // FALSE on failure
     $this->redis->delete('h');
     $this->redis->hSet('h', 'x', 'a');
     $this->redis->hSet('h', 'y', 'b');
     // keys
     $keys = $this->redis->hKeys('h');
     $this->assertTrue($keys === array('x', 'y') || $keys === array('y', 'x'));
     // values
     $values = $this->redis->hVals('h');
     $this->assertTrue($values === array('a', 'b') || $values === array('b', 'a'));
     // keys + values
     $all = $this->redis->hGetAll('h');
     $this->assertTrue($all === array('x' => 'a', 'y' => 'b') || $all === array('y' => 'b', 'x' => 'a'));
     // hExists
     $this->assertTrue(TRUE === $this->redis->hExists('h', 'x'));
     $this->assertTrue(TRUE === $this->redis->hExists('h', 'y'));
     $this->assertTrue(FALSE === $this->redis->hExists('h', 'w'));
     $this->redis->delete('h');
     $this->assertTrue(FALSE === $this->redis->hExists('h', 'x'));
     // hIncrBy
     /*
     $this->redis->delete('h');
     $this->assertTrue(2.5 === $this->redis->hIncrBy('h', 2.5, 'x'));
     $this->assertTrue(3.5 === $this->redis->hIncrBy('h', 1, 'x'));
     
     $this->redis->hSet('h', 'y', 'not-a-number');
     $this->assertTrue(FALSE === $this->redis->hIncrBy('h', 1, 'y'));
     */
 }
开发者ID:korsunivan,项目名称:phpredis,代码行数:55,代码来源:TestRedis.php

示例3: handle

 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // 避免重复操作
     if ($this->attempts() > 3) {
         return;
     }
     $this->redis = PRedis::connection();
     if (is_object($this->sheet)) {
         $vote_dest = 'jk_upvote:' . $this->sheet->getAttributeValue('song_id') . ':userLIST';
         if (true == $this->redis->hGet($vote_dest, $this->user)) {
             return;
         }
         $this->redis->hSet($vote_dest, $this->user, 1);
         $vote_count = $this->redis->hLen($vote_dest);
         $stat = $this->sheet->storeUpVoteNumber($this->sheet->getAttributeValue('song_id'), $vote_count);
         if (!$stat) {
             $this->failed();
         }
     }
 }
开发者ID:RedrockTeam,项目名称:jukebox,代码行数:25,代码来源:UpVote.php

示例4: testDifferentTypeSortedSet

 public function testDifferentTypeSortedSet()
 {
     $key = '{hash}sortedset';
     $dkey = '{hash}' . __FUNCTION__;
     $this->redis->del($key);
     $this->assertEquals(1, $this->redis->zAdd($key, 0, 'value'));
     // string I/F
     $this->assertEquals(FALSE, $this->redis->get($key));
     $this->assertEquals(FALSE, $this->redis->getset($key, 'value2'));
     $this->assertEquals(FALSE, $this->redis->append($key, 'append'));
     $this->assertEquals(FALSE, $this->redis->getRange($key, 0, 8));
     $this->assertEquals(array(FALSE), $this->redis->mget(array($key)));
     $this->assertEquals(FALSE, $this->redis->incr($key));
     $this->assertEquals(FALSE, $this->redis->incrBy($key, 1));
     $this->assertEquals(FALSE, $this->redis->decr($key));
     $this->assertEquals(FALSE, $this->redis->decrBy($key, 1));
     // lists I/F
     $this->assertEquals(FALSE, $this->redis->rPush($key, 'lvalue'));
     $this->assertEquals(FALSE, $this->redis->lPush($key, 'lvalue'));
     $this->assertEquals(FALSE, $this->redis->lLen($key));
     $this->assertEquals(FALSE, $this->redis->lPop($key));
     $this->assertEquals(FALSE, $this->redis->lrange($key, 0, -1));
     $this->assertEquals(FALSE, $this->redis->lTrim($key, 0, 1));
     $this->assertEquals(FALSE, $this->redis->lGet($key, 0));
     $this->assertEquals(FALSE, $this->redis->lSet($key, 0, "newValue"));
     $this->assertEquals(FALSE, $this->redis->lrem($key, 'lvalue', 1));
     $this->assertEquals(FALSE, $this->redis->lPop($key));
     $this->assertEquals(FALSE, $this->redis->rPop($key));
     $this->assertEquals(FALSE, $this->redis->rPoplPush($key, $dkey . 'lkey1'));
     // sets I/F
     $this->assertEquals(FALSE, $this->redis->sAdd($key, 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->srem($key, 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->sPop($key));
     $this->assertEquals(FALSE, $this->redis->sMove($key, $dkey . 'skey1', 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->scard($key));
     $this->assertEquals(FALSE, $this->redis->sismember($key, 'sValue1'));
     $this->assertEquals(FALSE, $this->redis->sInter($key, $dkey . 'skey2'));
     $this->assertEquals(FALSE, $this->redis->sUnion($key, $dkey . 'skey4'));
     $this->assertEquals(FALSE, $this->redis->sDiff($key, $dkey . 'skey7'));
     $this->assertEquals(FALSE, $this->redis->sMembers($key));
     $this->assertEquals(FALSE, $this->redis->sRandMember($key));
     // hash I/F
     $this->assertEquals(FALSE, $this->redis->hSet($key, 'key1', 'value1'));
     $this->assertEquals(FALSE, $this->redis->hGet($key, 'key1'));
     $this->assertEquals(FALSE, $this->redis->hMGet($key, array('key1')));
     $this->assertEquals(FALSE, $this->redis->hMSet($key, array('key1' => 'value1')));
     $this->assertEquals(FALSE, $this->redis->hIncrBy($key, 'key2', 1));
     $this->assertEquals(FALSE, $this->redis->hExists($key, 'key2'));
     $this->assertEquals(FALSE, $this->redis->hDel($key, 'key2'));
     $this->assertEquals(FALSE, $this->redis->hLen($key));
     $this->assertEquals(FALSE, $this->redis->hKeys($key));
     $this->assertEquals(FALSE, $this->redis->hVals($key));
     $this->assertEquals(FALSE, $this->redis->hGetAll($key));
 }
开发者ID:Jerry-Shaw,项目名称:phpredis,代码行数:54,代码来源:RedisTest.php

示例5: testHashes

 public function testHashes()
 {
     $this->redis->delete('h', 'key');
     $this->assertTrue(0 === $this->redis->hLen('h'));
     $this->assertTrue(1 === $this->redis->hSet('h', 'a', 'a-value'));
     $this->assertTrue(1 === $this->redis->hLen('h'));
     $this->assertTrue(1 === $this->redis->hSet('h', 'b', 'b-value'));
     $this->assertTrue(2 === $this->redis->hLen('h'));
     $this->assertTrue('a-value' === $this->redis->hGet('h', 'a'));
     // simple get
     $this->assertTrue('b-value' === $this->redis->hGet('h', 'b'));
     // simple get
     $this->assertTrue(0 === $this->redis->hSet('h', 'a', 'another-value'));
     // replacement
     $this->assertTrue('another-value' === $this->redis->hGet('h', 'a'));
     // get the new value
     $this->assertTrue('b-value' === $this->redis->hGet('h', 'b'));
     // simple get
     $this->assertTrue(FALSE === $this->redis->hGet('h', 'c'));
     // unknown hash member
     $this->assertTrue(FALSE === $this->redis->hGet('key', 'c'));
     // unknownkey
     // hDel
     $this->assertTrue(1 === $this->redis->hDel('h', 'a'));
     // 1 on success
     $this->assertTrue(0 === $this->redis->hDel('h', 'a'));
     // 0 on failure
     $this->redis->delete('h');
     $this->redis->hSet('h', 'x', 'a');
     $this->redis->hSet('h', 'y', 'b');
     $this->assertTrue(2 === $this->redis->hDel('h', 'x', 'y'));
     // variadic
     // hsetnx
     $this->redis->delete('h');
     $this->assertTrue(TRUE === $this->redis->hSetNx('h', 'x', 'a'));
     $this->assertTrue(TRUE === $this->redis->hSetNx('h', 'y', 'b'));
     $this->assertTrue(FALSE === $this->redis->hSetNx('h', 'x', '?'));
     $this->assertTrue(FALSE === $this->redis->hSetNx('h', 'y', '?'));
     $this->assertTrue('a' === $this->redis->hGet('h', 'x'));
     $this->assertTrue('b' === $this->redis->hGet('h', 'y'));
     // keys
     $keys = $this->redis->hKeys('h');
     $this->assertTrue($keys === array('x', 'y') || $keys === array('y', 'x'));
     // values
     $values = $this->redis->hVals('h');
     $this->assertTrue($values === array('a', 'b') || $values === array('b', 'a'));
     // keys + values
     $all = $this->redis->hGetAll('h');
     $this->assertTrue($all === array('x' => 'a', 'y' => 'b') || $all === array('y' => 'b', 'x' => 'a'));
     // hExists
     $this->assertTrue(TRUE === $this->redis->hExists('h', 'x'));
     $this->assertTrue(TRUE === $this->redis->hExists('h', 'y'));
     $this->assertTrue(FALSE === $this->redis->hExists('h', 'w'));
     $this->redis->delete('h');
     $this->assertTrue(FALSE === $this->redis->hExists('h', 'x'));
     // hIncrBy
     $this->redis->delete('h');
     $this->assertTrue(2 === $this->redis->hIncrBy('h', 'x', 2));
     $this->assertTrue(3 === $this->redis->hIncrBy('h', 'x', 1));
     $this->assertTrue(2 === $this->redis->hIncrBy('h', 'x', -1));
     $this->assertTrue(FALSE === $this->redis->hIncrBy('h', 'x', "not-a-number"));
     $this->assertTrue("2" === $this->redis->hGet('h', 'x'));
     $this->redis->hSet('h', 'y', 'not-a-number');
     $this->assertTrue(FALSE === $this->redis->hIncrBy('h', 'y', 1));
     // hIncrByFloat
     $this->redis->delete('h');
     $this->assertTrue(1.5 === $this->redis->hIncrByFloat('h', 'x', 1.5));
     $this->assertTrue(3.0 === $this->redis->hincrByFloat('h', 'x', 1.5));
     $this->assertTrue(1.5 === $this->redis->hincrByFloat('h', 'x', -1.5));
     $this->redis->hset('h', 'y', 'not-a-number');
     $this->assertTrue(FALSE === $this->redis->hIncrByFloat('h', 'y', 1.5));
     // hmset
     $this->redis->delete('h');
     $this->assertTrue(TRUE === $this->redis->hMset('h', array('x' => 123, 'y' => 456, 'z' => 'abc')));
     $this->assertTrue('123' === $this->redis->hGet('h', 'x'));
     $this->assertTrue('456' === $this->redis->hGet('h', 'y'));
     $this->assertTrue('abc' === $this->redis->hGet('h', 'z'));
     $this->assertTrue(FALSE === $this->redis->hGet('h', 't'));
     // hmget
     $this->assertTrue(array('x' => '123', 'y' => '456') === $this->redis->hMget('h', array('x', 'y')));
     $this->assertTrue(array('z' => 'abc') === $this->redis->hMget('h', array('z')));
     $this->assertTrue(array('x' => '123', 't' => FALSE, 'y' => '456') === $this->redis->hMget('h', array('x', 't', 'y')));
     $this->assertFalse(array(123 => 'x') === $this->redis->hMget('h', array(123)));
     $this->assertTrue(array(123 => FALSE) === $this->redis->hMget('h', array(123)));
     // hmget/hmset with numeric fields
     $this->redis->del('h');
     $this->assertTrue(TRUE === $this->redis->hMset('h', array(123 => 'x', 'y' => 456)));
     $this->assertTrue('x' === $this->redis->hGet('h', 123));
     $this->assertTrue('x' === $this->redis->hGet('h', '123'));
     $this->assertTrue('456' === $this->redis->hGet('h', 'y'));
     $this->assertTrue(array(123 => 'x', 'y' => '456') === $this->redis->hMget('h', array('123', 'y')));
     // check non-string types.
     $this->redis->delete('h1');
     $this->assertTrue(TRUE === $this->redis->hMSet('h1', array('x' => 0, 'y' => array(), 'z' => new stdclass(), 't' => NULL)));
     $h1 = $this->redis->hGetAll('h1');
     $this->assertTrue('0' === $h1['x']);
     $this->assertTrue('Array' === $h1['y']);
     $this->assertTrue('Object' === $h1['z']);
     $this->assertTrue('' === $h1['t']);
 }
开发者ID:0,项目名称:phpredis,代码行数:100,代码来源:TestRedis.php

示例6: cache_count

 /**
  * Count cache items
  *
  * @param	string	Cache key
  * @return	bool
  */
 public function cache_count($key)
 {
     $value = $this->_redis->hLen($key);
     return $value;
 }
开发者ID:KodeStar,项目名称:pro-api,代码行数:11,代码来源:Cache_redis.php

示例7: mbr

 public function mbr()
 {
     $this->pData = checkData($_POST);
     $this->gData = checkData($_GET);
     $this->pData['orderField'] = $orderField = isset($this->pData['orderField']) ? $this->pData['orderField'] : 'tdate';
     $this->pData['orderDirection'] = $orderDirection = isset($this->pData['orderDirection']) ? $this->pData['orderDirection'] : 'desc';
     $this->orderField = $orderField;
     $this->orderDirection = $orderDirection;
     $s_date = $this->pData['s_date'];
     $e_date = isset($this->pData['e_date']) ? $this->pData['e_date'] : date("Y-m-d");
     $this->pData['s_date'] = $s_date;
     $this->pData['e_date'] = $e_date;
     $date = date("Y-m-d", time());
     $hash = "mbr_" . $date;
     $redis = new Redis();
     $redis->connect('192.168.0.15', 6379);
     $install_all = $redis->hLen("install");
     //总安装量
     //print_r($install_all);die;
     $data[] = $redis->hgetall("mbr");
     $value = array();
     foreach ($data as $k => $v) {
         foreach ($v as $key => $val) {
             $value[] = json_decode($val);
         }
     }
     if ($e_date) {
         for ($i = 0; $i < count($value); $i++) {
             if ($value[$i][3] <= $e_date) {
                 $values[] = $value[$i];
             }
         }
     } else {
         if ($s_date) {
             for ($i = 0; $i < count($value); $i++) {
                 if ($value[$i][3] >= $s_date) {
                     $values[] = $value[$i];
                 }
             }
         } else {
             if (isset($e_date) && isset($s_date)) {
                 for ($i = 0; $i < count($value); $i++) {
                     if ($value[$i][3] >= $s_date && $value[$i][3] <= $e_date) {
                         $values[] = $value[$i];
                     }
                 }
             } else {
                 for ($i = 0; $i < count($value); $i++) {
                     $values[] = $value[$i];
                 }
             }
         }
     }
     for ($i = 0; $i < count($values); $i++) {
         unset($values[$i][2]);
         $value_str[] = implode(",", $values[$i]);
     }
     $arr = array_unique($value_str);
     foreach ($arr as $k => $v) {
         $value_arr[] = $v;
     }
     for ($i = 0; $i < count($value_arr); $i++) {
         $value_a[] = explode(",", $value_arr[$i]);
     }
     //print_r($value_a);die;
     $this->s->assign('count', 5);
     $this->s->assign('install_all', $install_all);
     $this->s->assign('data', $value_a);
     $this->s->assign('total', count($value_a));
     $this->s->assign('search', $this->pData);
 }
开发者ID:13240361944,项目名称:analyze,代码行数:71,代码来源:wapDataAction.class.php

示例8: testHashes

 public function testHashes()
 {
     $this->redis->delete('h', 'key');
     $this->assertTrue(0 === $this->redis->hLen('h'));
     $this->assertTrue(TRUE === $this->redis->hSet('h', 'a', 'a-value'));
     $this->assertTrue(1 === $this->redis->hLen('h'));
     $this->assertTrue(TRUE === $this->redis->hSet('h', 'b', 'b-value'));
     $this->assertTrue(2 === $this->redis->hLen('h'));
     $this->assertTrue('a-value' === $this->redis->hGet('h', 'a'));
     // simple get
     $this->assertTrue('b-value' === $this->redis->hGet('h', 'b'));
     // simple get
     $this->assertTrue(FALSE === $this->redis->hSet('h', 'a', 'another-value'));
     // replacement
     $this->assertTrue('another-value' === $this->redis->hGet('h', 'a'));
     // get the new value
     $this->assertTrue('b-value' === $this->redis->hGet('h', 'b'));
     // simple get
     $this->assertTrue(FALSE === $this->redis->hGet('h', 'c'));
     // unknown hash member
     $this->assertTrue(FALSE === $this->redis->hGet('key', 'c'));
     // unknownkey
     // hDel
     $this->assertTrue(TRUE === $this->redis->hDel('h', 'a'));
     // TRUE on success
     $this->assertTrue(FALSE === $this->redis->hDel('h', 'a'));
     // FALSE on failure
     $this->redis->delete('h');
     $this->redis->hSet('h', 'x', 'a');
     $this->redis->hSet('h', 'y', 'b');
     // keys
     $keys = $this->redis->hKeys('h');
     $this->assertTrue($keys === array('x', 'y') || $keys === array('y', 'x'));
     // values
     $values = $this->redis->hVals('h');
     $this->assertTrue($values === array('a', 'b') || $values === array('b', 'a'));
     // keys + values
     $all = $this->redis->hGetAll('h');
     $this->assertTrue($all === array('x' => 'a', 'y' => 'b') || $all === array('y' => 'b', 'x' => 'a'));
     // hExists
     $this->assertTrue(TRUE === $this->redis->hExists('h', 'x'));
     $this->assertTrue(TRUE === $this->redis->hExists('h', 'y'));
     $this->assertTrue(FALSE === $this->redis->hExists('h', 'w'));
     $this->redis->delete('h');
     $this->assertTrue(FALSE === $this->redis->hExists('h', 'x'));
     // hIncrBy
     $this->redis->delete('h');
     $this->assertTrue(25 === $this->redis->hIncrBy('h', 'x', 25));
     $this->assertTrue(35 === $this->redis->hIncrBy('h', 'x', 10));
     $this->redis->hSet('h', 'y', 'not-a-number');
     $this->assertTrue(FALSE === $this->redis->hIncrBy('h', 'y', 1));
     $this->redis->delete('h1');
     //hMGet, hMSet
     $this->redis->hset("h1", "field1", "value1");
     $this->redis->hset("h1", "field2", "value2");
     $this->assertTrue(array('field1' => 'value1', 'field2' => 'value2') === $this->redis->hGetAll('h1'));
     $this->assertTrue(array('field1' => 'value1', 'field2' => 'value2') === $this->redis->hMGet('h1', array('field1', 'field2')));
     $this->assertTrue(array('field1' => 'value1') === $this->redis->hMGet('h1', array('field1')));
     $this->assertTrue(FALSE === $this->redis->hMGet('h1', array()));
     $this->assertTrue(TRUE === $this->redis->hMSet('h1', array('field3' => 'value3')));
     $this->assertTrue(array('field1' => 'value1', 'field2' => 'value2', 'field3' => 'value3') === $this->redis->hGetAll('h1'));
     $this->assertTrue(TRUE === $this->redis->hMSet('h1', array('field3' => 'value4')));
     $this->assertTrue(array('field1' => 'value1', 'field2' => 'value2', 'field3' => 'value4') === $this->redis->hGetAll('h1'));
     $this->assertTrue(TRUE === $this->redis->hMSet('h1', array('x' => 0, 'y' => array(), 'z' => new stdclass())));
     $h1 = $this->redis->hGetAll('h1');
     $this->assertTrue('0' === $h1['x']);
     $this->assertTrue('Array' === $h1['y']);
     $this->assertTrue('Object' === $h1['z']);
 }
开发者ID:virtulis,项目名称:phpredis,代码行数:69,代码来源:TestRedis.php

示例9: hashLen

 /**
  * 获取hash表中元素个数
  * @param $hash string 哈希表名
  */
 public static function hashLen($hash)
 {
     $redis = new \Redis();
     $redis->connect(self::_HOST, self::_PORT);
     $return = null;
     $return = $redis->hLen($hash);
     $redis->close();
     $redis = null;
     return $return;
 }
开发者ID:skyshow,项目名称:ticket,代码行数:14,代码来源:MyRedis.class.php


注:本文中的Redis::hLen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。