本文整理汇总了PHP中Redis::rPush方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::rPush方法的具体用法?PHP Redis::rPush怎么用?PHP Redis::rPush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::rPush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: requeueOldWorkingTasks
private function requeueOldWorkingTasks()
{
$taskIds = array_unique($this->redis->lRange($this->getTaskRunKey(), 0, -1));
foreach ($taskIds as $taskId) {
$time = $this->redis->hGet($this->getTaskStartTimeKey(), $taskId);
if (!empty($time) && time() > $this->taskTimeout + (int) $time) {
$this->redis->multi();
$this->redis->rPush($this->getTaskQueueKey(), $taskId);
$this->redis->lRem($this->getTaskRunKey(), $taskId, 1);
$this->redis->hDel($this->getTaskStartTimeKey(), $taskId);
}
}
}
示例2: rPush
/**
* Append a value to a list
*
* @param string $key
* @param string $value
* @throws CM_Exception_Invalid
*/
public function rPush($key, $value)
{
$length = $this->_redis->rPush($key, $value);
if (false === $length) {
throw new CM_Exception_Invalid('Cannot push to list `' . $key . '`.');
}
}
示例3: set
/**
* Saves data in the cache.
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param string $data The data to be stored
* @param array $tags Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
* @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @throws \RuntimeException
* @return void
* @api
*/
public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
{
if ($this->isFrozen()) {
throw new \RuntimeException(sprintf('Cannot add or modify cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
}
if ($lifetime === null) {
$lifetime = $this->defaultLifetime;
}
$setOptions = [];
if ($lifetime > 0) {
$setOptions['ex'] = $lifetime;
}
$this->redis->multi();
$result = $this->redis->set($this->buildKey('entry:' . $entryIdentifier), $this->compress($data), $setOptions);
if (!$result instanceof \Redis) {
$this->verifyRedisVersionIsSupported();
}
$this->redis->lRem($this->buildKey('entries'), $entryIdentifier, 0);
$this->redis->rPush($this->buildKey('entries'), $entryIdentifier);
foreach ($tags as $tag) {
$this->redis->sAdd($this->buildKey('tag:' . $tag), $entryIdentifier);
$this->redis->sAdd($this->buildKey('tags:' . $entryIdentifier), $tag);
}
$this->redis->exec();
}
示例4: addMessage
/**
* Add message to queue
*
* @param MessageInterface $message
*
* @return bool
*
* @throws \RuntimeException
*/
public function addMessage(MessageInterface $message)
{
if (!$this->listKey) {
throw new \RuntimeException('Can\'t send message. Undefined list key.');
}
if (null === $this->redis) {
throw new \RuntimeException('Can\'t send message. Not found redis instance.');
}
return $this->redis->rPush($this->listKey, serialize($message));
}
示例5: requeueOldWorkingMessages
private function requeueOldWorkingMessages($type)
{
$messageIds = array_unique($this->redis->lRange($this->getMessageRunKey($type), 0, -1));
foreach ($messageIds as $messageId) {
$time = $this->redis->hGet($this->getMessageStartTimeKey($type), $messageId);
if (!empty($time) && time() > $this->messageTimeout + (int) $time) {
$this->redis->multi();
$this->redis->rPush($this->getMessageQueueKey($type), $messageId);
$this->redis->lRem($this->getMessageRunKey($type), $messageId, 1);
$this->redis->hDel($this->getMessageStartTimeKey($type), $messageId);
$this->redis->exec();
}
}
}
示例6: testlGet
public function testlGet()
{
$this->redis->delete('list');
$this->redis->lPush('list', 'val');
$this->redis->lPush('list', 'val2');
$this->redis->lPush('list', 'val3');
$this->assertEquals('val3', $this->redis->lGet('list', 0));
$this->assertEquals('val2', $this->redis->lGet('list', 1));
$this->assertEquals('val', $this->redis->lGet('list', 2));
$this->assertEquals('val', $this->redis->lGet('list', -1));
$this->assertEquals('val2', $this->redis->lGet('list', -2));
$this->assertEquals('val3', $this->redis->lGet('list', -3));
$this->assertEquals(FALSE, $this->redis->lGet('list', -4));
$this->redis->rPush('list', 'val4');
$this->assertEquals('val4', $this->redis->lGet('list', 3));
$this->assertEquals('val4', $this->redis->lGet('list', -1));
}
示例7: set
/**
* Saves data in the cache.
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param string $data The data to be stored
* @param array $tags Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
* @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @throws \RuntimeException
* @return void
* @api
*/
public function set($entryIdentifier, $data, array $tags = array(), $lifetime = NULL)
{
if ($this->isFrozen()) {
throw new \RuntimeException(sprintf('Cannot add or modify cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
}
if ($lifetime === NULL) {
$lifetime = $this->defaultLifetime;
}
$setOptions = array();
if ($lifetime > 0) {
$setOptions['ex'] = $lifetime;
}
$this->redis->multi();
$this->redis->set($this->buildKey('entry:' . $entryIdentifier), $data, $setOptions);
$this->redis->rPush($this->buildKey('entries'), $entryIdentifier);
foreach ($tags as $tag) {
$this->redis->sAdd($this->buildKey('tag:' . $tag), $entryIdentifier);
$this->redis->sAdd($this->buildKey('tags:' . $entryIdentifier), $tag);
}
$this->redis->exec();
}
示例8: write
/**
* Write to redis
*
* @return mixed|void
*/
public function write()
{
foreach ($this->formattedMessages() as $message) {
$this->client->rPush($this->injectors['key'], $message);
}
}
示例9: reloadServer
public function reloadServer()
{
if (!$this->checkIfRunning()) {
$settings = $this->__setupPubServer();
} else {
$settings = $this->__getSetSettings();
$redis = new Redis();
$redis->connect($settings['redis_host'], $settings['redis_port']);
$redis->select($settings['redis_database']);
$redis->rPush($settings['redis_namespace'] . ':command', 'reload');
}
if (!$this->checkIfRunning()) {
return 'Setting saved, but something is wrong with the ZeroMQ server. Please check the diagnostics page for more information.';
}
return true;
}
示例10: rpush
/**
* rpush a raw value
*
* @param string $key Cache ID
* @param string $value value
* @return mixed New value on success or FALSE on failure
*/
public function rpush($key, $value)
{
return $this->_redis->rPush($key, $value);
}
示例11: send
/**
* @param int $key
* @param mixed $message
* @return bool
*/
public function send($key, $message)
{
$result = 0 < $this->client->rPush($key, $message);
return $result;
}
示例12: listPush
/**
* 入队列
* @param $list string 队列名
* @param $value mixed 入队元素值
* @param $deriction int 0:数据入队列头(左) 1:数据入队列尾(右) 默认为0
* @param $repeat int 判断value是否存在 0:不判断存在 1:判断存在 如果value存在则不入队列
*/
public static function listPush($list, $value, $direction = 0, $repeat = 0)
{
$redis = new \Redis();
$redis->connect(self::_HOST, self::_PORT);
$return = null;
switch ($direction) {
case 0:
if ($repeat) {
$return = $redis->lPushx($list, $value);
} else {
$return = $redis->lPush($list, $value);
}
break;
case 1:
if ($repeat) {
$return = $redis->rPushx($list, $value);
} else {
$return = $redis->rPush($list, $value);
}
break;
default:
$return = false;
break;
}
$redis->close();
$redis = null;
return $return;
}
示例13: 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]));
//.........这里部分代码省略.........
示例14: push
/**
* @inheritdoc
*/
public function push($data)
{
is_scalar($data) or $data = json_encode($data);
return (bool) $this->redis->rPush($this->name, $data);
}
示例15: push
/**
* 数据入队列
* @param string $key KEY名称
* @param string|array $value 获取得到的数据
* @param bool $right 是否从右边开始入
* @return int
*/
public function push($key, $value, $right = true)
{
$value = json_encode($value);
return $right ? parent::rPush($key, $value) : parent::lPush($key, $value);
}