本文整理汇总了PHP中Predis\Client::hmset方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::hmset方法的具体用法?PHP Client::hmset怎么用?PHP Client::hmset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::hmset方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAllIndexed
/**
* @inheritDoc
*/
public function getAllIndexed() : array
{
if (!$this->client->exists($this->key)) {
$data = $this->repository->getAllIndexed();
if ($data) {
$this->client->hmset($this->key, $data);
}
} else {
$data = $this->client->hgetall($this->key);
}
return $data;
}
示例2: haveInRedis
/**
* Creates or modifies keys
*
* If $key already exists:
*
* - Strings: its value will be overwritten with $value
* - Other types: $value items will be appended to its value
*
* Examples:
*
* ``` php
* <?php
* // Strings: $value must be a scalar
* $I->haveInRedis('string', 'Obladi Oblada');
*
* // Lists: $value can be a scalar or an array
* $I->haveInRedis('list', ['riri', 'fifi', 'loulou']);
*
* // Sets: $value can be a scalar or an array
* $I->haveInRedis('set', ['riri', 'fifi', 'loulou']);
*
* // ZSets: $value must be an associative array with scores
* $I->haveInRedis('set', ['riri' => 1, 'fifi' => 2, 'loulou' => 3]);
*
* // Hashes: $value must be an associative array
* $I->haveInRedis('hash', ['obladi' => 'oblada']);
* ```
*
* @param string $type The type of the key
* @param string $key The key name
* @param mixed $value The value
*
* @throws ModuleException
*/
public function haveInRedis($type, $key, $value)
{
switch (strtolower($type)) {
case 'string':
if (!is_scalar($value)) {
throw new ModuleException($this, 'If second argument of haveInRedis() method is "string", ' . 'third argument must be a scalar');
}
$this->driver->set($key, $value);
break;
case 'list':
$this->driver->rpush($key, $value);
break;
case 'set':
$this->driver->sadd($key, $value);
break;
case 'zset':
if (!is_array($value)) {
throw new ModuleException($this, 'If second argument of haveInRedis() method is "zset", ' . 'third argument must be an (associative) array');
}
$this->driver->zadd($key, $value);
break;
case 'hash':
if (!is_array($value)) {
throw new ModuleException($this, 'If second argument of haveInRedis() method is "hash", ' . 'third argument must be an array');
}
$this->driver->hmset($key, $value);
break;
default:
throw new ModuleException($this, "Unknown type \"{$type}\" for key \"{$key}\". Allowed types are " . '"string", "list", "set", "zset", "hash"');
}
}
示例3: recoverByRemoteAddress
/**
* @param string $remoteAddress
*
* @return Session|null
*/
public function recoverByRemoteAddress($remoteAddress)
{
$session = null;
$oracleData = $this->findSessionInOracleByRemoteAddress($remoteAddress);
if (count($oracleData) === 1) {
$sid = $oracleData[0]['sid'];
$redisKey = $this->buildKey($sid);
$data = $this->redis->hgetall($redisKey);
if (!$data) {
$data['userId'] = (int) $oracleData[0]['userId'];
$data['userScreenname'] = $oracleData[0]['userScreenname'];
}
$this->redis->hmset($redisKey, $data);
$this->redis->expire($redisKey, $this->getExpires());
$session = new Session($sid, $this->getRealm(), $data);
}
return $session;
}
示例4: createSession
/**
* @param array $userInfo
*/
public function createSession($sessionId, $userInfo)
{
$this->redis->hmset('session_' . $sessionId, $userInfo);
}
示例5: save
/**
* @inheritDoc
*/
public function save(CustomerView $view)
{
$this->client->hmset(self::KEY . ':' . $view->getId(), ['id' => $view->getId(), 'email' => $view->getEmail(), 'country' => $view->getCountry(), 'city' => $view->getCity(), 'street' => $view->getStreet(), 'zipCode' => $view->getZipCode()]);
}
示例6: htInitByDefault
/**
* 通过默认值来初始化一个 hash table
* @param $key
* @param array $fields
* @param int $default
* @return mixed
*/
public function htInitByDefault($key, array $fields, $default = 0)
{
$data = array_fill_keys($fields, $default);
return $this->redis->hmset($key, $data);
}
示例7: serialize
*
* Created by PhpStorm.
* User: shruti
* Date: 8/7/15
* Time: 12:32 PM
*/
include "Utils.php";
//Class for Data cleaning
require_once 'vendor/autoload.php';
use Predis;
Predis\Autoloader::register();
$client = new Predis\Client(["hosts" => "localhost", "port" => "6379"]);
//store file contents in data variable
$json_data = file_get_contents('./Crawled-data.json');
//decode the json data into array variable
$json_array = json_decode($json_data, true);
//Clean entire file data
for ($i = 0; $i < count($json_array); $i++) {
$json_array[$i] = Utils::cleanData($json_array[$i]);
}
//Creating Hashmap in redis
foreach ($json_array as $element) {
//serialize each element before storing as redis accept string
$serial_data = serialize($element);
//store partnumber in key var
$key = $element['ModelId'];
//replace spaces in partnumber field
$key = str_replace(" ", "", $key);
//create hashmap using partnumber as key
$client->hmset('Laptop_Specification', $key, $serial_data);
}