public function markUserOnline($pageKey, $userIdent) { $thisMinute = floor(time() / 60) * 60; $key = $this->makeUsersOnlineKey($pageKey, $thisMinute); $this->redis->pipeline(function (Pipeline $p) use($key, $userIdent) { $p->sadd($key, $userIdent); $p->expire($key, self::ONLINE_MINUTES * 60); }); }
/** * @param string $queueName * @param array $workloads */ public function multiPut($queueName, array $workloads) { $pipeline = $this->predis->pipeline(); foreach ($workloads as $workload) { /** @noinspection PhpUndefinedMethodInspection */ $pipeline->lpush($queueName, serialize($workload)); } $pipeline->execute(); }
public function set($keyValue) { $pipe = $this->redis->pipeline(); foreach ($keyValue as $key => $value) { if (!is_null($value)) { $value = json_encode($value); $pipe->setex($key, 86400, $value); // 缓存 1 天 } } return $pipe->execute(); }
/** * */ private function updateValues() { $this->registeredStates = $this->redis->smembers(self::STATE_MACHINE_NAMESPACE . 'registry'); if (count($this->registeredStates) > 0) { $currentValueRedisKeys = array_map([$this, 'buildCurrentKey'], $this->registeredStates); $previousValueRedisKeys = array_map([$this, 'buildPreviousKey'], $this->registeredStates); list($currentValues, $previousValues) = $this->redis->pipeline(function (Pipeline $pipe) use($currentValueRedisKeys, $previousValueRedisKeys) { $pipe->mget($currentValueRedisKeys); $pipe->mget($previousValueRedisKeys); }); $this->currentValues = array_combine($this->registeredStates, $currentValues); $this->previousValues = array_combine($this->registeredStates, $previousValues); } }
/** * Inserts many items in the cache. * * @param array $values * @param int $minutes * * @return mixed */ public function setMany(array $values, int $minutes) { $this->predis->pipeline(function ($pipe) use($values, $minutes) { foreach ($values as $key => $value) { $value = is_numeric($value) ? $value : serialize($value); $pipe->setex($this->prefix . $key, 60 * $minutes, $value); } }); }
/** * Clear the entire cache. */ public static function remClear() { $keys = self::remAllKeys(); self::$_redis->pipeline(function ($pipe) use($keys) { foreach ($keys as $key) { Rem::remDeleteKey($key, $pipe); } }); }
/** * Batch store */ public function storePosts() { if (!$this->isValid()) { return false; } try { // would break this up i.e. only pipeline 5000 at a time $this->storage->pipeline(function ($pipe) { foreach ($this->rawpost->getData() as $data) { $postback = []; $postback['method'] = $this->rawpost->getMethod(); $postback['url'] = $this->rawpost->getUrl(); $postback['data'] = $data; $pipe->lpush('job-queue', json_encode($postback)); } }); } catch (\Exception $e) { $this->error = $e->getMessage(); return false; } return true; }
/** * @group disconnected */ public function testPipelineWithArrayAndCallableExecutesPipelineWithOptions() { $executor = $this->getMock('Predis\\Pipeline\\PipelineExecutorInterface'); $options = array('executor' => $executor); $test = $this; $mockCallback = function ($pipeline) use($executor, $test) { $reflection = new \ReflectionProperty($pipeline, 'executor'); $reflection->setAccessible(true); $test->assertSame($executor, $reflection->getValue($pipeline)); }; $callable = $this->getMock('stdClass', array('__invoke')); $callable->expects($this->once())->method('__invoke')->with($this->isInstanceOf('Predis\\Pipeline\\PipelineContext'))->will($this->returnCallback($mockCallback)); $client = new Client(); $client->pipeline($options, $callable); }
public function createPipeline() { return $this->redis->pipeline(); }
/** * @group disconnected */ public function testPipelineWithCallableExecutesPipeline() { $callable = $this->getMock('stdClass', array('__invoke')); $callable->expects($this->once())->method('__invoke')->with($this->isInstanceOf('Predis\\Pipeline\\Pipeline')); $client = new Client(); $client->pipeline($callable); }