Skip to content
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

[5.3] ARGV for Lua scripts #14802

Merged
merged 1 commit into from
Aug 13, 2016
Merged

[5.3] ARGV for Lua scripts #14802

merged 1 commit into from
Aug 13, 2016

Conversation

halaei
Copy link
Contributor

@halaei halaei commented Aug 13, 2016

According to Redis documentations, this commit makes things compatible with Redis Clusters.

  • The LuaScripts::size() should not dynamically generate key names.
  • For LuaScripts::pop,release, and migrateExpiredJobs(), there is no reason to pass non-key arguments as KEYS - unnecessary overhead I think.

Note: I have not tested Redis clusters yet. Sorry about that.

@GrahamCampbell GrahamCampbell changed the title ARGV for Lua scripts [5.3] ARGV for Lua scripts Aug 13, 2016
@taylorotwell taylorotwell merged commit a493384 into laravel:5.3 Aug 13, 2016
tillkruss pushed a commit to tillkruss/framework that referenced this pull request Aug 30, 2016
@hopher
Copy link

hopher commented Dec 12, 2016

In order to connect to a cluster managed by redis-cluster, the client requires a list of its nodes (not necessarily complete since it will automatically discover new nodes if necessary) and the cluster client options set to redis, so we need config config/database.php, add

        'cluster' => true,
        'options' => [
            'cluster' => 'redis'
        ]

example

    'redis' => [

        'cluster' => true,

        'default' => [
            'host' => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],
        
        'redis1' => [
            'host' => env('REDIS_HOST_1', 'localhost'),
            'password' => env('REDIS_PASSWORD_1', null),
            'port' => env('REDIS_PORT_1', 6379),
            'database' => 0,
        ],        
        'options' => [
            'cluster' => 'redis'
        ]
    ],

but they can't be work on queue:work, because redis-cluster can't support multi key for lua script.
eval() function can't be work ( more than one args)

// in Redis Cluster
// $this->getConnection() == Predis\Connection\Aggregate\RedisCluster
// in Single Redis 
// $this->getConnection() == Predis\Connection\StreamConnection
$this->getConnection()->eval(
            LuaScripts::pop(), 2, $queue, $queue.':reserved', $this->getTime() + $this->expire
);

relation two classes and function

Illuminate\Queue\RedisQueue
Illuminate\Queue\LuaScripts


    public function pop($queue = null)
    {
        $original = $queue ?: $this->default;

        $queue = $this->getQueue($queue);

        $this->migrateExpiredJobs($queue.':delayed', $queue);

        if (! is_null($this->expire)) {
            $this->migrateExpiredJobs($queue.':reserved', $queue);
        }

        list($job, $reserved) = $this->getConnection()->eval(
            LuaScripts::pop(), 2, $queue, $queue.':reserved', $this->getTime() + $this->expire
        );

        if ($reserved) {
            return new RedisJob($this->container, $this, $job, $reserved, $original);
        }
    }

@hopher
Copy link

hopher commented Dec 12, 2016

All we need to do is , change Illuminate\Queue\RedisQueue

add '{}' to queue key, make the redis keys hash tags same in redis-cluster

    // line 224
    protected function getQueue($queue)
    {
        return '{queues}:'.($queue ?: $this->default);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants