本文整理汇总了PHP中Redis::getOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::getOption方法的具体用法?PHP Redis::getOption怎么用?PHP Redis::getOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::getOption方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clear
public function clear()
{
$this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_NONE);
$prefix = $this->redis->getOption(\Redis::OPT_PREFIX);
$offset = strlen($prefix);
$keys = $this->redis->keys('*');
foreach ($keys as $key) {
$this->redis->del(substr($key, $offset));
}
}
示例2: __construct
public function __construct(\Redis $redis = null)
{
$this->redis = $redis;
$maxExecutionTime = (int) ini_get('max_execution_time');
if ($maxExecutionTime > 0 && $maxExecutionTime < $this->lockExpire) {
$this->lockExpire = $maxExecutionTime;
}
if (!is_null($this->redis)) {
$this->prefix = $this->redis->getOption(\Redis::OPT_PREFIX);
}
}
示例3: pop
/**
* {@inheritdoc}
*/
public function pop()
{
$result = $this->redis->evaluate(self::SCRIPT_POP, ['items', time()], 1);
$this->assertResult($result);
if (-1 === $result) {
throw new NoItemAvailableException($this);
}
if (\Redis::SERIALIZER_NONE !== $this->redis->getOption(\Redis::OPT_SERIALIZER)) {
return $this->redis->_unserialize($result);
}
return $result;
}
示例4: castRedis
public static function castRedis(\Redis $c, array $a, Stub $stub, $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
if (defined('HHVM_VERSION_ID')) {
$ser = $a[Caster::PREFIX_PROTECTED . 'serializer'];
$a[Caster::PREFIX_PROTECTED . 'serializer'] = isset(self::$serializer[$ser]) ? new ConstStub(self::$serializer[$ser], $ser) : $ser;
return $a;
}
if (!($connected = $c->isConnected())) {
return $a + array($prefix . 'isConnected' => $connected);
}
$ser = $c->getOption(\Redis::OPT_SERIALIZER);
$retry = defined('Redis::OPT_SCAN') ? $c->getOption(\Redis::OPT_SCAN) : 0;
return $a + array($prefix . 'isConnected' => $connected, $prefix . 'host' => $c->getHost(), $prefix . 'port' => $c->getPort(), $prefix . 'auth' => $c->getAuth(), $prefix . 'dbNum' => $c->getDbNum(), $prefix . 'timeout' => $c->getTimeout(), $prefix . 'persistentId' => $c->getPersistentID(), $prefix . 'options' => new EnumStub(array('READ_TIMEOUT' => $c->getOption(\Redis::OPT_READ_TIMEOUT), 'SERIALIZER' => isset(self::$serializer[$ser]) ? new ConstStub(self::$serializer[$ser], $ser) : $ser, 'PREFIX' => $c->getOption(\Redis::OPT_PREFIX), 'SCAN' => new ConstStub($retry ? 'RETRY' : 'NORETRY', $retry))));
}
示例5: clear
protected static function clear(\Redis $redis)
{
$prefix = $redis->getOption(\Redis::OPT_PREFIX);
$offset = strlen($prefix);
$keys = $redis->keys('*');
foreach ($keys as $key) {
$redis->del(substr($key, $offset));
}
}
示例6: getRedisClient
public static function getRedisClient()
{
$redis = new \Redis();
$redis->connect(self::HOST, self::PORT);
$redis->select(self::DB_INDEX);
if ($redis->getOption(\Redis::OPT_SERIALIZER) === \Redis::SERIALIZER_NONE) {
$redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);
}
return $redis;
}
示例7: getOption
/**
* 获取redis模式参数
* @param $option array 要获取的参数数组
*/
public static function getOption($option = array())
{
$redis = new \Redis();
$redis->connect(self::_HOST, self::_PORT);
$return = null;
$return = $redis->getOption();
$redis->close();
$redis = null;
return $return;
}
示例8: getHashValueAsUnserializedString
/**
* @param string $key
* @param string $hashKey
* @param UnserializesDataToString $unserializer
*
* @return bool|string
*/
public function getHashValueAsUnserializedString($key, $hashKey, UnserializesDataToString $unserializer)
{
$serializer = $this->redis->getOption(\Redis::OPT_SERIALIZER);
$this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_NONE);
$value = $this->redis->hGet($key, $hashKey);
if ($value !== false) {
$unserializedValue = $unserializer->unserialize($value);
} else {
$unserializedValue = false;
}
$this->redis->setOption(\Redis::OPT_SERIALIZER, $serializer);
return $unserializedValue;
}
示例9: testReadTimeoutOption
public function testReadTimeoutOption()
{
$this->assertTrue(defined('Redis::OPT_READ_TIMEOUT'));
$this->redis->setOption(Redis::OPT_READ_TIMEOUT, "12.3");
$this->assertEquals(12.3, $this->redis->getOption(Redis::OPT_READ_TIMEOUT));
}
示例10: checkSerializer
private function checkSerializer($mode)
{
$this->redis->delete('key');
$this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === Redis::SERIALIZER_NONE);
// default
$this->assertTrue($this->redis->setOption(Redis::OPT_SERIALIZER, $mode) === TRUE);
// set ok
$this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === $mode);
// get ok
// lPush, rPush
$a = array('hello world', 42, TRUE, array('<tag>' => 1729));
$this->redis->delete('key');
$this->redis->lPush('key', $a[0]);
$this->redis->rPush('key', $a[1]);
$this->redis->rPush('key', $a[2]);
$this->redis->rPush('key', $a[3]);
// lGetRange
$this->assertTrue($a === $this->redis->lGetRange('key', 0, -1));
// lGet
$this->assertTrue($a[0] === $this->redis->lGet('key', 0));
$this->assertTrue($a[1] === $this->redis->lGet('key', 1));
$this->assertTrue($a[2] === $this->redis->lGet('key', 2));
$this->assertTrue($a[3] === $this->redis->lGet('key', 3));
// lRemove
$this->assertTrue($this->redis->lRemove('key', $a[3]) === 1);
$this->assertTrue(array_slice($a, 0, 3) === $this->redis->lGetRange('key', 0, -1));
// lSet
$a[0] = array('k' => 'v');
// update
$this->assertTrue(TRUE === $this->redis->lSet('key', 0, $a[0]));
$this->assertTrue($a[0] === $this->redis->lGet('key', 0));
// lInsert
$this->assertTrue($this->redis->lInsert('key', Redis::BEFORE, $a[0], array(1, 2, 3)) === 4);
$this->assertTrue($this->redis->lInsert('key', Redis::AFTER, $a[0], array(4, 5, 6)) === 5);
$a = array(array(1, 2, 3), $a[0], array(4, 5, 6), $a[1], $a[2]);
$this->assertTrue($a === $this->redis->lGetRange('key', 0, -1));
// sAdd
$this->redis->delete('key');
$s = array(1, 'a', array(1, 2, 3), array('k' => 'v'));
$this->assertTrue(1 === $this->redis->sAdd('key', $s[0]));
$this->assertTrue(1 === $this->redis->sAdd('key', $s[1]));
$this->assertTrue(1 === $this->redis->sAdd('key', $s[2]));
$this->assertTrue(1 === $this->redis->sAdd('key', $s[3]));
// variadic sAdd
$this->redis->delete('k');
$this->assertTrue(3 === $this->redis->sAdd('k', 'a', 'b', 'c'));
$this->assertTrue(1 === $this->redis->sAdd('k', 'a', 'b', 'c', 'd'));
// sRemove
$this->assertTrue(1 === $this->redis->sRemove('key', $s[3]));
$this->assertTrue(0 === $this->redis->sRemove('key', $s[3]));
// variadic
$this->redis->delete('k');
$this->redis->sAdd('k', 'a', 'b', 'c', 'd');
$this->assertTrue(2 === $this->redis->sRem('k', 'a', 'd'));
$this->assertTrue(2 === $this->redis->sRem('k', 'b', 'c', 'e'));
$this->assertTrue(FALSE === $this->redis->exists('k'));
// sContains
$this->assertTrue(TRUE === $this->redis->sContains('key', $s[0]));
$this->assertTrue(TRUE === $this->redis->sContains('key', $s[1]));
$this->assertTrue(TRUE === $this->redis->sContains('key', $s[2]));
$this->assertTrue(FALSE === $this->redis->sContains('key', $s[3]));
unset($s[3]);
// sMove
$this->redis->delete('tmp');
$this->redis->sMove('key', 'tmp', $s[0]);
$this->assertTrue(FALSE === $this->redis->sContains('key', $s[0]));
$this->assertTrue(TRUE === $this->redis->sContains('tmp', $s[0]));
unset($s[0]);
// sorted sets
$z = array('z0', array('k' => 'v'), FALSE, NULL);
$this->redis->delete('key');
// zAdd
$this->assertTrue(1 === $this->redis->zAdd('key', 0, $z[0]));
$this->assertTrue(1 === $this->redis->zAdd('key', 1, $z[1]));
$this->assertTrue(1 === $this->redis->zAdd('key', 2, $z[2]));
$this->assertTrue(1 === $this->redis->zAdd('key', 3, $z[3]));
// zDelete
$this->assertTrue(1 === $this->redis->zDelete('key', $z[3]));
$this->assertTrue(0 === $this->redis->zDelete('key', $z[3]));
unset($z[3]);
// check that zDelete doesn't crash with a missing parameter (GitHub issue #102):
$this->assertTrue(FALSE === @$this->redis->zDelete('key'));
// variadic
$this->redis->delete('k');
$this->redis->zAdd('k', 0, 'a');
$this->redis->zAdd('k', 1, 'b');
$this->redis->zAdd('k', 2, 'c');
$this->assertTrue(2 === $this->redis->zDelete('k', 'a', 'c'));
$this->assertTrue(1.0 === $this->redis->zScore('k', 'b'));
$this->assertTrue($this->redis->zRange('k', 0, -1, true) == array('b' => 1.0));
// zRange
$this->assertTrue($z === $this->redis->zRange('key', 0, -1));
// zScore
$this->assertTrue(0.0 === $this->redis->zScore('key', $z[0]));
$this->assertTrue(1.0 === $this->redis->zScore('key', $z[1]));
$this->assertTrue(2.0 === $this->redis->zScore('key', $z[2]));
// zRank
$this->assertTrue(0 === $this->redis->zRank('key', $z[0]));
$this->assertTrue(1 === $this->redis->zRank('key', $z[1]));
$this->assertTrue(2 === $this->redis->zRank('key', $z[2]));
//.........这里部分代码省略.........