/**
  * @param int $fireTime
  *
  * @return array
  */
 public function getList($fireTime)
 {
     $list = $this->client->hgetall($this->makeKey($fireTime));
     return array_map(function ($value) {
         return json_decode($value, true);
     }, $list);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function index() : array
 {
     $features = [];
     foreach ($this->redis->hgetall($this->prefix) as $alias => $feature) {
         $features[$alias] = unserialize($feature);
     }
     return $features;
 }
Example #3
0
 /**
  * @param int $userId
  * @return UserVO
  * @throws UserNotFoundException
  */
 public function loadUserById(int $userId) : UserVO
 {
     $redisUser = $this->redis->hgetall($this->getKey($userId));
     if (empty($redisUser)) {
         throw new UserNotFoundException(sprintf('User "%d" does not exist.', $userId));
     }
     return $this->buildUserVO($userId, $redisUser);
 }
Example #4
0
 /**
  * @param string $sessionId
  * @return array
  */
 public function getUserInfo($sessionId)
 {
     $userInfo = $this->redis->hgetall('session_' . $sessionId);
     if (!$userInfo) {
         throw new \RuntimeException('Session not found');
     }
     return $userInfo;
 }
Example #5
0
 public function getRateInfo($key)
 {
     $info = $this->client->hgetall($key);
     $rateLimitInfo = new RateLimitInfo();
     $rateLimitInfo->setLimit($info['limit']);
     $rateLimitInfo->setCalls($info['calls']);
     $rateLimitInfo->setResetTimestamp($info['reset']);
     return $rateLimitInfo;
 }
 /**
  * @param string $sid
  *
  * @return Session|null
  */
 public function get($sid)
 {
     $session = null;
     if (UUID::isValid($sid)) {
         $data = $this->redis->hgetall($this->buildKey($sid));
         if (count($data)) {
             $session = new Session($sid, $this->getRealm(), $data);
         }
     }
     return $session;
 }
Example #7
0
 /**
  * @inheritdoc
  */
 public function getById(\string $id) : CustomerView
 {
     $key = self::KEY . ':' . $id;
     if ($this->client->exists($key)) {
         $item = $this->client->hgetall($key);
         $model = $this->createViewModel($item);
     } else {
         $model = $this->repository->getById($id);
         $this->save($model);
     }
     return $model;
 }
 /**
  * @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;
 }
 public function testHandleLogWithJob()
 {
     $job = new ImageJob();
     $job->setBeginning('begin');
     $job->setEnd('end');
     $frame = new Frame('MESSAGE', array('delivery_tag' => 'delivery-' . mt_rand()), $job->toJson());
     $loop = LoopFactory::create();
     $options = array('eventloop' => $loop, 'on_error' => array($this, 'throwRedisError'));
     $redisSync = new PredisSync('tcp://127.0.0.1:6379');
     $redisSync->connect();
     $resolver = $this->getResolver();
     $resolver->expects($this->once())->method('ack');
     $done = false;
     $phpunit = $this;
     $redis = new PredisAsync('tcp://127.0.0.1:6379', $options);
     $redis->connect(function () use($phpunit, $redis, $frame, $redisSync, &$done, $resolver) {
         $component = new LogBuilderComponent();
         $component->handleLog($redis, $phpunit->getLogger(), $frame, $resolver)->then(function ($hashId) use($phpunit, $redis, $redisSync, &$done) {
             $redis->disconnect();
             $data = $redisSync->hgetall($hashId);
             $phpunit->assertGreaterThan(0, count($data));
             $phpunit->assertEquals('Gloubster\\Message\\Job\\ImageJob', $data['type']);
             $phpunit->assertTrue($redisSync->sismember('jobs', $hashId));
             $done = true;
         });
     });
     $loop->run();
     $this->assertTrue($done);
 }
 /**
  * @return array|null
  */
 public function getAll()
 {
     $extensionsSerialize = $this->redisClient->hgetall(self::EXTENSION_HASH_STORE);
     if (!$extensionsSerialize) {
         return;
     }
     $result = [];
     foreach ($extensionsSerialize as $serialized) {
         $extension = new Extension();
         $extension->unserialize($serialized);
         $meta = json_decode($this->redisClient->hget(self::EXTENSIONMETA_HASH_STORE, $extension->getName()), true);
         $extension->setWatchers($meta['watchers']);
         $extension->setStars($meta['stars']);
         $result[$extension->getName()] = $extension;
     }
     return $result;
 }
Example #11
0
 /**
  * @param mixed $id
  *
  * @return object
  */
 public function find($id)
 {
     $metadata = $this->getMetadataFor($this->className);
     $key = $this->keyNamingStrategy->getKeyName(array($metadata->getPrefix(), $id));
     $data = $this->redis->hgetall($key);
     if (empty($data)) {
         return;
     }
     return $this->hydrator->hydrate($this->newObject(), $data, $metadata);
 }
Example #12
0
 /**
  * @param $key
  * @param bool $valToInt
  * @return array
  */
 public function htGetAll($key, $valToInt = false)
 {
     $data = $this->redis->hgetall($key);
     if ($valToInt) {
         array_walk($data, function (&$val) {
             $val = (int) $val;
         });
     }
     return $data;
 }
Example #13
0
 public function home()
 {
     $redis = new Client();
     $date = $redis->hget('update', 'index');
     $index = $redis->hgetall('index');
     $sorts = array_values(BiliBiliHelper::getSorts());
     foreach ($sorts as $sort) {
         $index[$sort] = json_decode($index[$sort], true);
     }
     return view('index')->with('content', $index)->with('sorts', $sorts)->with('update_time', $date);
 }
Example #14
0
 /**
  * Get distributions given an event and a set of dates
  *
  * [
  *      "value3": 24,
  *      "value7": 13,
  *      "value8": 9,
  * ]
  *
  * @param string $token Event
  * @param string $event Token
  * @param array  $dates Dates
  *
  * @return array Distribution with totals
  */
 public function getDistributions($token, $event, array $dates)
 {
     $distributions = [];
     foreach ($dates as $date) {
         $key = $this->generateEntryKey($token, $event, $date);
         $partials = $this->redis->hgetall($key . '_distr');
         foreach ($partials as $key => $value) {
             $distributions[$key] = isset($partialTotals[$key]) ? $distributions[$key] + $value : $value;
         }
     }
     arsort($distributions);
     return $distributions;
 }
 /**
  * @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 #16
0
 /**
  * Checks whether a key exists and, optionally, whether it has a given $value
  *
  * @param string $key   The key name
  * @param mixed  $value Optional. If specified, also checks the key has this
  * value. Booleans will be converted to 1 and 0 (even inside arrays)
  *
  * @return bool
  */
 private function checkKeyExists($key, $value = null)
 {
     $type = $this->driver->type($key);
     if (is_null($value)) {
         return $type != 'none';
     }
     $value = $this->boolToString($value);
     switch ($type) {
         case 'string':
             $reply = $this->driver->get($key);
             // Allow non strict equality (2 equals '2')
             $result = $reply == $value;
             break;
         case 'list':
             $reply = $this->driver->lrange($key, 0, -1);
             // Check both arrays have the same key/value pairs + same order
             $result = $reply === $value;
             break;
         case 'set':
             $reply = $this->driver->smembers($key);
             // Only check both arrays have the same values
             sort($reply);
             sort($value);
             $result = $reply === $value;
             break;
         case 'zset':
             $reply = $this->driver->zrange($key, 0, -1, 'WITHSCORES');
             // Check both arrays have the same key/value pairs + same order
             $reply = $this->scoresToFloat($reply);
             $value = $this->scoresToFloat($value);
             $result = $reply === $value;
             break;
         case 'hash':
             $reply = $this->driver->hgetall($key);
             // Only check both arrays have the same key/value pairs (==)
             $result = $reply == $value;
             break;
         default:
             $result = false;
     }
     return $result;
 }
 /**
  * @inheritdoc
  */
 public function all($id)
 {
     return array_map(function ($val) {
         return json_decode($val, true);
     }, $this->predis->hgetall($id));
 }
 * read data from redis by passing a key
 * it returns corresponding value stored
 *
 * Created by PhpStorm.
 * User: ShrutiJain
 * Date: 9/7/15
 * Time: 1:11 PM
 */
include "SearchPage-view.php";
require_once 'vendor/autoload.php';
use Predis;
Predis\Autoloader::register();
$client = new Predis\Client(["hosts" => "localhost", "port" => "6379"]);
if (isset($_GET['id'])) {
    $q = $_GET['id'];
    $value = $client->hgetall('Laptop_Specification');
    $single_value = $value[$q];
    $unserialised_data = unserialize($single_value);
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<div class="outer" style="padding-top: 30px ">

    <div class="image" style="width: 50px ;" >
        <img src="<?php 
Example #19
0
<?php

use Slim\Slim;
use Predis\Client as PredisClient;
const BULK_COUNTER = 'bulk_num';
const BULK_HASH = 'bulk_hash';
require __DIR__ . '/../vendor/autoload.php';
$config = (require dirname(__DIR__) . '/config.php');
$predis = new PredisClient($config['redis_conn_arr']);
Slim::registerAutoloader();
$app = new Slim();
$app->get('/messages', function () use($predis, $app) {
    $data = $predis->hgetall(BULK_HASH);
    $result = [];
    foreach ($data as $id => $message) {
        $messageArr = json_decode($message, true);
        $messageArr['id'] = $id;
        $result[] = $messageArr;
    }
    usort($result, function ($a, $b) {
        if ($a['id'] == $b['id']) {
            return 0;
        }
        return $a['id'] < $b['id'] ? -1 : 1;
    });
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->setStatus(200);
    echo json_encode($result);
});
$app->get('/messages/:id', function ($id) use($predis, $app) {
    $data = $predis->hget(BULK_HASH, $id);