/**
  * @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;
 }
Example #2
0
 /**
  * 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"');
     }
 }
 /**
  * @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;
 }
Example #4
0
 /**
  * @param array $userInfo
  */
 public function createSession($sessionId, $userInfo)
 {
     $this->redis->hmset('session_' . $sessionId, $userInfo);
 }
Example #5
0
 /**
  * @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()]);
 }
Example #6
0
 /**
  * 通过默认值来初始化一个 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);
 }
 *
 * 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);
}