Skip to content
This repository has been archived by the owner. It is now read-only.

Redis queue prefix #848

Open
Snake231088 opened this issue Oct 20, 2017 · 11 comments
Open

Redis queue prefix #848

Snake231088 opened this issue Oct 20, 2017 · 11 comments

Comments

@Snake231088
Copy link

@Snake231088 Snake231088 commented Oct 20, 2017

Laravel Version: 5.5
PHP Version: 7.1
Description:

add possibility to specify a prefix for queues with redis driver. Now the key on redis is:
queues:#QUEUE_NAME#
Thx

@dstensnes
Copy link

@dstensnes dstensnes commented Oct 27, 2017

+1

@dstensnes
Copy link

@dstensnes dstensnes commented Oct 27, 2017

Never mind. Fixed it with this in config/database.php:

    'redis' => [
        'cluster' => false,
        'client'  => 'phpredis',
        'default' => [
            'host'     => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port'     => env('REDIS_PORT', 6379),
            'database' => 0,
            'prefix'   => 'cc5home3:',
        ],
    ],

This "redis" key (shown above) should be in the outermost array directly following the "return" statement. This requires the php-redis dpkg to be installed though, but that is probably fine

@Snake231088
Copy link
Author

@Snake231088 Snake231088 commented Jan 8, 2018

+1

@mfn
Copy link

@mfn mfn commented Jan 8, 2018

The proposed fix in #848 (comment) matches the official docs at https://laravel.com/docs/5.5/redis

PhpRedis supports the following additional connection parameters: persistent, prefix, read_timeout and timeout.

IMHO there's nothing else to be done => what the user wanted to talk about is supported.

@f3cp
Copy link

@f3cp f3cp commented May 3, 2018

The config example by @dstensnes for adding the prefix only works with the phpredis client.

If you want to add a prefix using the predis client the config is different. You must add the prefix within the options key of the redis config e.g.

'redis' => [
        'client' => 'predis',
        'cluster' => false,
        'options'=>[
            'prefix' => 'YOUR_PREFIX_HERE'
        ],
        'default' => [
            'host'     => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port'     => env('REDIS_PORT', 6379),
            'database' => 0,
        ],
    ],

@gerardnll
Copy link

@gerardnll gerardnll commented Jun 13, 2018

@f3cp this adds the prefix to all redis keys before the one specified in cache.php, so it's like a double prefix in sessions and cache databases.

I really don't understand why sessions and cache have prefix (only listed in cache.php) but the queue service doesn't...

@crazyfree
Copy link

@crazyfree crazyfree commented Jun 15, 2018

I also wanna separate cache prefix and session prefix out, using predis. Any solution?

@erlangparasu
Copy link

@erlangparasu erlangparasu commented Sep 13, 2018

+1

@sisve
Copy link

@sisve sisve commented Sep 14, 2018

We can set the session prefix separately by extending the SessionManager and through some slightly unclean code interact with the store. You would also need to extend the SessionServiceProvider to use this Much Cooler (tm) implementation. Change your config/app.php to use your CustomSessionServiceProvider instead of original one. The following example is based on Laravel 5.5, but I presume it would be very similar in newer releases too.

class CustomSessionManager extends SessionManager {
    protected function createCacheHandler($driver) {
        $handler = parent::createCacheHandler($driver);

        $repository = $handler->getCache();
        $store = $repository->getStore();

        if ($store instanceof RedisStore) {
            $store->setPrefix('prefix-goes-here');
        }

        return $handler;
    }
}

class CustomSessionServiceProvider extends SessionServiceProvider {
    protected function registerSessionManager() {
        $this->app->singleton('session', function ($app) {
            return new CustomSessionManager($app);
        });
    }
}

@paras-malhotra
Copy link

@paras-malhotra paras-malhotra commented Sep 24, 2018

+1 for queue Redis prefix. We definitely need this for servers running multiple Laravel apps with queues

@atrauzzi
Copy link

@atrauzzi atrauzzi commented Jan 21, 2019

It would be nice to be able to enforce a prefix at the queue level rather than the connection level.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
10 participants