/** * @param int $userId */ public function followOrUnfollow($userId) { if ($this->sessionUserId === $userId) { return; } if (!$this->redisClient->sismember("uid:" . $this->sessionUserId . ":following", $userId)) { $this->follow($userId); } else { $this->unfollow($userId); } }
/** * Checks whether a key contains a given item * * @param string $key The key * @param mixed $item The item * @param null $itemValue Optional and only used for zsets and hashes. If * specified, the method will also check that the $item has this value/score * * @return bool * * @throws ModuleException */ private function checkKeyContains($key, $item, $itemValue = null) { $result = null; if (!is_scalar($item)) { throw new ModuleException($this, "All arguments of [dont]seeRedisKeyContains() must be scalars"); } switch ($this->driver->type($key)) { case 'string': $reply = $this->driver->get($key); $result = strpos($reply, $item) !== false; break; case 'list': $reply = $this->driver->lrange($key, 0, -1); $result = in_array($item, $reply); break; case 'set': $result = $this->driver->sismember($key, $item); break; case 'zset': $reply = $this->driver->zscore($key, $item); if (is_null($reply)) { $result = false; } elseif (!is_null($itemValue)) { $result = (double) $reply === (double) $itemValue; } else { $result = true; } break; case 'hash': $reply = $this->driver->hget($key, $item); $result = is_null($itemValue) ? !is_null($reply) : (string) $reply === (string) $itemValue; break; case 'none': throw new ModuleException($this, "Key \"{$key}\" does not exist"); break; } return $result; }
/** * @param $sid * * @return int */ private function isBlacklisted($sid) { return $this->redis->sismember('session:blacklist:OracleHookedRedisSessionProvider', $sid); }
/** * Check if specific identifier is in set * @param $identifier * @return int */ public function isOnline($identifier) { return $this->redisClient->sismember($this->setName, $identifier); }
/** * 集合是否存在元素 $member * @param $key * @param $member * @return bool */ public function existsInSet($key, $member) { return (bool) $this->redis->sismember($key, $member); }
/** * @param int $keyId * @param int $searchId * @return bool */ private function isExistsRequest($keyId, $searchId) { return $this->redis->sismember($this->getFormattedKey($keyId), $searchId); }
public function existsInSet($key, $value) { return $this->_client->sismember($key, $value); }
private static function remKeyInIndex(Key $key) { return self::$_redis->sismember(Key::getIndexKey(), $key->getPrefix()) && self::$_redis->sismember($key->getPrefix(), $key->getSuffix()); }
public function testHandleLogWithGoodMessageNotImplementingJobInterface() { $worker = new WorkerPresence(); $worker->setMemory(12345); $frame = new Frame('MESSAGE', array('delivery_tag' => 'delivery-' . mt_rand()), $worker->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($resolver, $phpunit, $redis, $frame, $redisSync, &$done, $worker) { $component = new LogBuilderComponent(); $component->handleLog($redis, $phpunit->getLogger(), $frame, $resolver)->then(function ($hashId) use($phpunit, $redis, $redisSync, &$done, $worker) { $redis->disconnect(); $phpunit->assertEquals($worker->toJson(), $redisSync->get($hashId)); $phpunit->assertTrue($redisSync->sismember('garbages', $hashId)); $done = true; }); }); $loop->run(); $this->assertTrue($done); }