本文整理汇总了PHP中Predis\ClientInterface::mset方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::mset方法的具体用法?PHP ClientInterface::mset怎么用?PHP ClientInterface::mset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::mset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doSaveMultiple
/**
* {@inheritdoc}
*/
protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
{
if ($lifetime) {
$success = true;
// Keys have lifetime, use SETEX for each of them
foreach ($keysAndValues as $key => $value) {
$response = $this->client->setex($key, $lifetime, serialize($value));
if ((string) $response != 'OK') {
$success = false;
}
}
return $success;
}
// No lifetime, use MSET
$response = $this->client->mset(array_map(function ($value) {
return serialize($value);
}, $keysAndValues));
return (string) $response == 'OK';
}
示例2: setMulti
/**
* @param array $items
*
* @throws \Exception
*
* @return void
*/
public function setMulti(array $items)
{
$data = [];
foreach ($items as $key => $value) {
$dataKey = $this->getKeyName($key);
if (!is_scalar($value)) {
$value = json_encode($value);
}
$data[$dataKey] = $value;
}
if (count($data) === 0) {
return;
}
$result = $this->client->mset($data);
$this->addMultiWriteAccessStats($data);
if (!$result) {
throw new \Exception('could not set redisKeys for items: "[' . implode(',', array_keys($items)) . ']" with values: "[' . implode(',', array_values($items)) . ']"');
}
}
示例3: testMultipleGet
/**
* @group redis-strings
*/
public function testMultipleGet()
{
$this->client->mset(array('foo' => 'bar', 'hello' => 'world'));
$this->assertEquals(array('bar', 'world'), $this->client->mget('foo', 'hello'));
}