Skip to content

[10.x] Remove serializer and compression for RedisQueue #48180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/Illuminate/Queue/RedisQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Contracts\Queue\Queue as QueueContract;
use Illuminate\Contracts\Redis\Factory as Redis;
use Illuminate\Queue\Jobs\RedisJob;
use Illuminate\Redis\Connections\PhpRedisConnection;
use Illuminate\Support\Str;

class RedisQueue extends Queue implements QueueContract, ClearableQueue
Expand Down Expand Up @@ -54,6 +55,13 @@ class RedisQueue extends Queue implements QueueContract, ClearableQueue
*/
protected $migrationBatchSize = -1;

/**
* The redis connection instance.
*
* @var \Illuminate\Redis\Connections\Connection
*/
protected $redisConnection;

/**
* Create a new Redis queue instance.
*
Expand Down Expand Up @@ -367,7 +375,24 @@ public function getQueue($queue)
*/
public function getConnection()
{
return $this->redis->connection($this->connection);
if (isset($this->redisConnection)) {
return $this->redisConnection;
}

$this->redisConnection = $this->redis->connection($this->connection);

if ($this->redisConnection instanceof PhpRedisConnection) {
$this->redisConnection = $this->redis->resolve($this->connection);

if (defined('\Redis::OPT_COMPRESSION') && $this->redisConnection->client()->getOption(\Redis::OPT_COMPRESSION) !== \Redis::COMPRESSION_NONE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPT_COMPRESSION is always defined.

$this->redisConnection->client()->setOption(\Redis::OPT_COMPRESSION, \Redis::COMPRESSION_NONE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't access \Redis directly here, you can make $this->redisConnection->client() a variable and reference the constant on it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your input. Since I will have to change that code, I will wait for Taylors answer.
Maybe you can give me/us a hint why the MULTI (transaction) would be better than the currently used Lua script.
Thanks again!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because multi() works with serializer and compression.

}
if (defined('\Redis::OPT_SERIALIZER') && $this->redisConnection->client()->getOption(\Redis::OPT_SERIALIZER) !== \Redis::SERIALIZER_NONE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPT_SERIALIZER is always defined, so is SERIALIZER_NONE and COMPRESSION_NONE.

$this->redisConnection->client()->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_NONE);
}
}

return $this->redisConnection;
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/Queue/RedisQueueIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,23 @@ public function testBulkJobQueuedEvent($driver)
]);
}

public function testUnsettingCompressionAndSerializer()
{
$this->redis['phpredis']->connection()->setOption(\Redis::OPT_SERIALIZER, 1);
$this->redis['phpredis']->connection()->setOption(\Redis::OPT_COMPRESSION, 1);

$queue = new RedisQueue($this->redis['phpredis']);

$cleanConnection = $queue->getConnection();

$this->assertEquals(0, $cleanConnection->getOption(\Redis::OPT_SERIALIZER));
$this->assertEquals(0, $cleanConnection->getOption(\Redis::OPT_COMPRESSION));

// don't change the original connection so cache can still use compression or serialization
$this->assertEquals(1, $this->redis['phpredis']->connection()->getOption(\Redis::OPT_SERIALIZER));
$this->assertEquals(1, $this->redis['phpredis']->connection()->getOption(\Redis::OPT_COMPRESSION));
}

/**
* @param string $driver
* @param string $default
Expand Down