pipeline() public method

Creates a new pipeline context and returns it, or returns the results of a pipeline executed inside the optionally provided callable object.
public pipeline ( ) : Pipeline | array
return Predis\Pipeline\Pipeline | array
 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);
     });
 }
Example #2
0
 /**
  * @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();
 }
Example #3
0
 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();
 }
Example #4
0
 /**
  *
  */
 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);
         }
     });
 }
Example #6
0
 /**
  * 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;
 }
Example #8
0
 /**
  * @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);
 }
Example #9
0
 public function createPipeline()
 {
     return $this->redis->pipeline();
 }
Example #10
0
 /**
  * @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);
 }