Example #1
0
 /**
  * @param $hostUid
  * @param $key
  * @return null|UserText
  */
 public function getTextsByUser($hostUid, $cached = true)
 {
     if ($cached) {
         $pattern = $this->buildKey($hostUid, '*', '*');
         $prefix = $this->redis->getOptions()->prefix;
         $redisKeys = array_map(function ($redisKey) use($prefix) {
             if (substr($redisKey, 0, strlen($prefix)) == $prefix) {
                 $redisKey = substr($redisKey, strlen($prefix));
             }
             return $redisKey;
         }, $this->redis->keys($pattern));
         if (count($redisKeys) > 0) {
             $result = array_combine($redisKeys, $this->redis->mget($redisKeys));
             foreach ($result as $redisKey => $text) {
                 list(, , $userId, , $key, $lang) = explode(':', $redisKey);
                 $this->texts[$userId][$key][$lang] = $text;
             }
         }
     }
     if (!$cached || !isset($this->texts[$hostUid]) || !$this->texts[$hostUid]) {
         $this->texts[$hostUid] = $this->getTextsByHostFromMysql($hostUid);
         $mset = [];
         foreach ($this->texts[$hostUid] as $key => $langs) {
             foreach ($langs as $lang => $text) {
                 $mset[$this->buildKey($hostUid, $key, $lang)] = $text;
             }
         }
         if ($mset) {
             $this->redis->mset($mset);
         }
     }
     return $this->texts[$hostUid];
 }
 /**
  * Retrieves many item from the cache.
  *
  * @param array $keys
  *
  * @return mixed
  */
 public function getMany(array $keys) : array
 {
     // Retrieve all keys
     $items = $this->predis->mget(array_map(function ($key) {
         return $this->prefix . $key;
     }, $keys));
     // Unserialize items
     return array_map(function ($item) {
         return is_numeric($item) ? $item : unserialize($item);
     }, $items);
 }
Example #3
0
 /**
  * Get multiple values from the cache.
  *
  * @param array $keys An array of keys to get
  *
  * @return array An array of JSON objects
  */
 public function mget(array $keys = array())
 {
     $values = $this->client->mget($keys);
     $rtn = [];
     // The Redis extension returns false not null for nonexistent
     // values. For consistency's sake, we spoof that here
     foreach ($keys as $index => $key) {
         $value = $values[$index];
         $rtn[$this->instance->unkey($key)] = $value;
     }
     return $rtn;
 }
Example #4
0
 public function get($keys)
 {
     if (!$keys) {
         return [];
     }
     $keyValue = array_combine($keys, $this->redis->mget($keys));
     array_walk($keyValue, function (&$item) {
         $item = json_decode($item);
     });
     $keyValue = array_filter($keyValue, function ($value) {
         return !is_null($value);
     });
     return $keyValue;
 }
 function getStatusQueue()
 {
     //$iterator = new Iterator\Keyspace($this->redisClient, $this->taskListKey . "*", 2000);
     $iterator = new Iterator\Keyspace($this->redisClient, "*", 2000);
     //$iterator = new Iterator\Keyspace($this->redisClient, $this->statusKey . "*", 2000);
     $keys = [];
     foreach ($iterator as $key) {
         $keys[] = $key;
     }
     if (!count($keys)) {
         return [];
     }
     $values = $this->redisClient->mget($keys);
     return array_combine($keys, $values);
 }
Example #6
0
 public function multiRead($keys)
 {
     if ($prefix = $this->prefix) {
         $prefixed = array_map(function ($v) use($prefix) {
             return $prefix . $v;
         }, $keys);
     } else {
         $prefixed = $keys;
     }
     $values = $this->store->mget($prefixed);
     foreach ($values as &$v) {
         if ($v !== null) {
             $v = unserialize($v);
         }
     }
     return array_combine($keys, $values);
 }
Example #7
0
 /**
  * @param string $namespace
  * @param array  $keys
  *
  * @return array
  */
 public function getStates($namespace, array $keys)
 {
     $values = [];
     $namespaceKeys = array_map(function ($key) use($namespace) {
         return $this->buildCurrentKey($this->buildNamespaceKey($namespace, $key));
     }, $keys);
     if (count($namespaceKeys) > 0) {
         $values = array_combine($keys, $this->redis->mget($namespaceKeys));
     }
     return $values;
 }
 private function getQueueEntries($keyStub)
 {
     $iterator = new Iterator\Keyspace($this->redisClient, $keyStub . "*", 2000);
     $keyList = [];
     foreach ($iterator as $key) {
         $keyList[] = $key;
     }
     if (!count($keyList)) {
         return [];
     }
     $values = $this->redisClient->mget($keyList);
     return array_combine($keyList, $values);
 }
 /**
  * @param $namespace
  * @param array $uids
  */
 protected function getUsersFromRedis($namespace, array $uids = [])
 {
     $users = [];
     $keys = array_map(function ($uid) use($namespace) {
         return 'users:' . $namespace . ':' . $uid;
     }, $uids);
     if (count($keys) > 0) {
         $data = $this->redis->mget($keys);
         foreach ($data as $serializedUserModel) {
             /** @var $userModel Model\User */
             if ($serializedUserModel) {
                 $userModel = unserialize($serializedUserModel);
                 $users[$userModel->getUid()] = $userModel;
             }
         }
     }
     return $users;
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 protected function read(array $keys)
 {
     $values = $this->client->mget($keys);
     return array_combine($keys, $values);
 }