本文整理汇总了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;
}
示例2: getItem
/**
* {@inheritdoc}
*/
public function getItem($index)
{
$this->initializeRedis();
$key = $this->getKeyForItemList();
$item = $this->redis->lindex($key, $index);
return $item;
}
示例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);
}