/** * {@inheritDoc} */ public function add($source, $type, $unique, array $data, \DateTime $timestamp = null) { $identifier = base64_encode(implode(':', [$source, $type, $unique])); $timestamp = $timestamp ?: new \DateTime(); $this->redis->hset('aggregator:objects', $identifier, json_encode(['source' => $source, 'type' => $type, 'unique' => $unique, 'data' => $data, 'timestamp' => $timestamp->format('U')])); $this->redis->zadd("aggregator:sources:{$source}", $timestamp->format('U'), $identifier); }
/** * @param Extension $extension * @param User $extension */ public function persist(Extension $extension, User $user) { $this->redisClient->hset(self::EXTENSION_HASH_STORE, $extension->getName(), $extension->serialize()); $this->redisClient->hset(self::EXTENSION2USER_HASH_STORE, $extension->getName(), $user->getName()); $meta = ['watchers' => $extension->getStars(), 'stars' => $extension->getWatchers()]; $this->redisClient->hset(self::EXTENSIONMETA_HASH_STORE, $extension->getName(), json_encode($meta)); }
public function createRate($key, $limit, $period) { $this->client->hset($key, 'limit', $limit); $this->client->hset($key, 'calls', 1); $this->client->hset($key, 'reset', time() + $period); $this->client->expire($key, $period); return $this->getRateInfo($key); }
/** * Writes session data. * * @param string $id A session ID * @param string $data A serialized chunk of session data * * @return bool true, if the session was written, otherwise an exception is thrown * * @throws \RuntimeException If the session data cannot be written */ public function write($key, $data) { $result = $this->db->hset($this->getHashKey(), $key, serialize($data)); $expires = (int) $this->options['lifetime']; if ($expires > 0) { $this->db->expire($this->getHashKey(), $expires); } return $result; }
/** * @param $id * @return DirectoryView */ public function getById($id) : DirectoryView { if (!($name = $this->client->hget($this->key, $id))) { $model = $this->repository->getById($id); $this->client->hset($this->key, $model->getId(), $model->getName()); return $model; } /** @var DirectoryView $viewClass */ $viewClass = $this->viewClass; return $viewClass::create($id, $name); }
/** * @param array $payload * * @return int * * @throws \InvalidArgumentException */ public function add(array $payload) { if (!isset($payload['fireTime'])) { throw new \InvalidArgumentException('payload should has key: fireTime, and >0'); } $fireTime = $payload['fireTime']; $key = $this->makeKey($fireTime); $value = json_encode($payload); $field = md5($value); $ret = $this->client->hset($key, $field, $value); // var_dump(__METHOD__ . ": key[$key] field[$field] value[$value] hset return " . var_export($ret, true)); return $ret; }
/** * Dump config array to redis. * * @param array $conf * @return $this */ public function dumpConfig($conf = null) { if (is_null($conf)) { $conf = $this->conf; } if (is_array($conf) && $this->redis) { foreach ($conf as $k => $value) { $this->redis->hset($this->key, $k, serialize($value)); } } return $this; }
/** * @param string $destination * @param string $commandName * @param string $routingKey */ public function setRoutingDestination($destination, $commandName, $routingKey) { $this->client->hset(self::COMMAND_ROUTING_KEY, $this->hashCommandRouting($commandName, $routingKey), $destination); }
public function Report() { $json = json_encode(array("worker_id" => $this->worker_id, "worker_hash" => $this->worker_hash, "worker_version" => $this->worker_version, "time_limit" => $this->time_limit, "end_time" => $this->end_time, "last_word" => $this->last_word, "last_def" => $this->last_def, "status" => $this->status)); $this->redis->hset('worker.status', $this->worker_id, $json); }
/** * @inheritdoc */ protected function doLog($ident, $originalId, array $context) { $this->predis->hset($ident, $originalId, json_encode($context)); }
/** * {@inheritdoc} */ public function add(string $alias, FeatureInterface $feature) : StorageInterface { $this->redis->hset($this->prefix, $alias, $this->feature($feature)); return $this; }
/** * @inheritdoc */ public function log($id, $originalId, array $context) { $this->predis->hset($id, $originalId, json_encode($context)); }
// create a log channel $log = new Logger('serverlog'); $log->pushHandler(new StreamHandler(dirname(__DIR__) . '/' . $config['client']['log_file'])); //get params if (!$_REQUEST['sender'] || !$_REQUEST['receiver'] || !$_REQUEST['text']) { $log->error('Invalid request'); header("HTTP/1.1 420 OK"); die("ERR 110"); } $client = new PredisClient($config['redis_conn_url']); $bulkNum = (int) $client->get(BULK_COUNTER); $bulkNum++; $client->set(BULK_COUNTER, $bulkNum); $message = json_encode($_REQUEST); //store message $client->hset(BULK_HASH, $bulkNum, $message); $client->publish('bulkmocksend', $message); $client->quit(); $messageId = BulkUtils::guid(); $smsParts = BulkUtils::getNumberOfSMSsegments($_REQUEST['text']); ob_start(); //close http conn. and flush header("HTTP/1.1 202 OK"); echo "OK {$messageId} {$smsParts}"; $log->info("Valid request and replied: OK {$messageId} {$smsParts}"); header('Connection: close'); header('Content-Length: ' . ob_get_length()); ob_end_flush(); ob_flush(); flush(); //proceed with dlr
/** * Store a value serialized into the cache. * @param string $id * @param string $method * @param array $args * @param mixed $value */ private static function remCache(Key $key, $args, $value) { self::$_redis->hset($key, 'args', serialize($args)); self::$_redis->hset($key, 'val', serialize($value)); self::remAddIndex($key); }