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


PHP Client::lindex方法代码示例

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


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

示例1: grabFromRedis

 /**
  * Returns the value of a given key
  *
  * Examples:
  *
  * ``` php
  * <?php
  * // Strings
  * $I->grabFromRedis('string');
  *
  * // Lists: get all members
  * $I->grabFromRedis('example:list');
  *
  * // Lists: get a specific member
  * $I->grabFromRedis('example:list', 2);
  *
  * // Lists: get a range of elements
  * $I->grabFromRedis('example:list', 2, 4);
  *
  * // Sets: get all members
  * $I->grabFromRedis('example:set');
  *
  * // ZSets: get all members
  * $I->grabFromRedis('example:zset');
  *
  * // ZSets: get a range of members
  * $I->grabFromRedis('example:zset', 3, 12);
  *
  * // Hashes: get all fields of a key
  * $I->grabFromRedis('example:hash');
  *
  * // Hashes: get a specific field of a key
  * $I->grabFromRedis('example:hash', 'foo');
  * ```
  *
  * @param string $key The key name
  *
  * @return mixed
  *
  * @throws ModuleException if the key does not exist
  */
 public function grabFromRedis($key)
 {
     $args = func_get_args();
     switch ($this->driver->type($key)) {
         case 'none':
             throw new ModuleException($this, "Cannot grab key \"{$key}\" as it does not exist");
             break;
         case 'string':
             $reply = $this->driver->get($key);
             break;
         case 'list':
             if (count($args) === 2) {
                 $reply = $this->driver->lindex($key, $args[1]);
             } else {
                 $reply = $this->driver->lrange($key, isset($args[1]) ? $args[1] : 0, isset($args[2]) ? $args[2] : -1);
             }
             break;
         case 'set':
             $reply = $this->driver->smembers($key);
             break;
         case 'zset':
             if (count($args) === 2) {
                 throw new ModuleException($this, "The method grabFromRedis(), when used with sorted " . "sets, expects either one argument or three");
             }
             $reply = $this->driver->zrange($key, isset($args[2]) ? $args[1] : 0, isset($args[2]) ? $args[2] : -1, 'WITHSCORES');
             break;
         case 'hash':
             $reply = isset($args[1]) ? $this->driver->hget($key, $args[1]) : $this->driver->hgetall($key);
             break;
         default:
             $reply = null;
     }
     return $reply;
 }
开发者ID:solutionDrive,项目名称:Codeception,代码行数:75,代码来源:Redis.php

示例2: getItem

 /**
  * {@inheritdoc}
  */
 public function getItem($index)
 {
     $this->initializeRedis();
     $key = $this->getKeyForItemList();
     $item = $this->redis->lindex($key, $index);
     return $item;
 }
开发者ID:battlerattle,项目名称:shuffle-bag,代码行数:10,代码来源:RedisStorage.php

示例3: getAssociation

 /**
  * Read association from Redis. If no handle given 
  * and multiple associations found, returns latest issued
  */
 function getAssociation($server_url, $handle = null)
 {
     // simple case: handle given
     if ($handle !== null) {
         return $this->getAssociationFromServer($this->associationKey($server_url, $handle));
     }
     // no handle given, receiving the latest issued
     $serverKey = $this->associationServerKey($server_url);
     $lastKey = $this->redis->lindex($serverKey, -1);
     if (!$lastKey) {
         // no previous association with this server
         return null;
     }
     // get association, return null if failed
     return $this->getAssociationFromServer($lastKey);
 }
开发者ID:openid,项目名称:php-openid,代码行数:20,代码来源:PredisStore.php


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