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

[laravel] Redis uses predis instead of php-redis and ignores all configured environment variables #289

Closed
renepardon opened this issue Jul 29, 2020 · 5 comments

Comments

@renepardon
Copy link
Contributor

Describe the bug

Obviously the environment variables (see below) are ignored when Redis is used for caching:

production.ERROR: Connection refused [tcp://127.0.0.1:6379] {"userId":2,"exception":"[object] (Predis\\Connection\\ConnectionException(code: 111): Connection refused [tcp://127.0.0.1:6379] at /var/www/html/app/vendor/predis/predis/src/Connection/AbstractConnection.php:155)

To Reproduce
Steps to reproduce the behavior:

  1. install tus-php into your project with redis (pecl install redis) and deploy this to k8s

Expected behavior
all works with php-redis extension instead of predis ;)

Additional context

server singleton:

        $this->app->singleton('tus-server', function (Application $app) {
            $server = new TusServer('redis');
            $server->setApiPath('/api/uploader/files');
            $server->setUploadDir(Storage::disk('uploads')->path(''));
            $server->middleware()
                // ->skip([Cors::class]) // We already use CORS implementation - don't need headers to be sent twice
                ->add(FileTypeValidator::class);

            return $server;
        });

my versions:

        "php": ">=7.4",
        "ext-json": "*",
        "ext-redis": "*",
        "ankitpokhrel/tus-php": "^2.0",
        "laravel/framework": "^7.0",

.env:

    CACHE_DRIVER="redis"
    QUEUE_CONNECTION="redis"
    SESSION_DRIVER="redis"
    SESSION_LIFETIME="120"
    REDIS_HOST="redis-redis-ha-haproxy"
    REDIS_PASSWORD="..."
    REDIS_PORT="6379"
    REDIS_CLIENT="phpredis"
    REDIS_PREFIX="whatever_database_"

stacktrace:

production.ERROR: Connection refused [tcp://127.0.0.1:6379] {"userId":2,"exception":"[object] (Predis\\Connection\\ConnectionException(code: 111): Connection refused [tcp://127.0.0.1:6379] at /var/www/html/app/vendor/predis/predis/src/Connection/AbstractConnection.php:155)
[stacktrace]
#0 /var/www/html/app/vendor/predis/predis/src/Connection/StreamConnection.php(128): Predis\\Connection\\AbstractConnection->onConnectionError()
#1 /var/www/html/app/vendor/predis/predis/src/Connection/StreamConnection.php(178): Predis\\Connection\\StreamConnection->createStreamSocket()
#2 /var/www/html/app/vendor/predis/predis/src/Connection/StreamConnection.php(100): Predis\\Connection\\StreamConnection->tcpStreamInitializer()
#3 /var/www/html/app/vendor/predis/predis/src/Connection/AbstractConnection.php(81): Predis\\Connection\\StreamConnection->createResource()
#4 /var/www/html/app/vendor/predis/predis/src/Connection/StreamConnection.php(258): Predis\\Connection\\AbstractConnection->connect()
#5 /var/www/html/app/vendor/predis/predis/src/Connection/AbstractConnection.php(180): Predis\\Connection\\StreamConnection->connect()
#6 /var/www/html/app/vendor/predis/predis/src/Connection/StreamConnection.php(288): Predis\\Connection\\AbstractConnection->getResource()
#7 /var/www/html/app/vendor/predis/predis/src/Connection/StreamConnection.php(394): Predis\\Connection\\StreamConnection->write()
#8 /var/www/html/app/vendor/predis/predis/src/Connection/AbstractConnection.php(110): Predis\\Connection\\StreamConnection->writeRequest()
#9 /var/www/html/app/vendor/predis/predis/src/Client.php(331): Predis\\Connection\\AbstractConnection->executeCommand()
#10 /var/www/html/app/vendor/predis/predis/src/Client.php(314): Predis\\Client->executeCommand()
#11 /var/www/html/app/vendor/ankitpokhrel/tus-php/src/Cache/RedisStore.php(47): Predis\\Client->__call()
#12 /var/www/html/app/vendor/ankitpokhrel/tus-php/src/Cache/RedisStore.php(68): TusPhp\\Cache\\RedisStore->get()
#13 /var/www/html/app/vendor/ankitpokhrel/tus-php/src/Tus/Server.php(378): TusPhp\\Cache\\RedisStore->set()
#14 /var/www/html/app/vendor/ankitpokhrel/tus-php/src/Tus/Server.php(275): TusPhp\\Tus\\Server->handlePost()
#15 /var/www/html/app/Modules/Uploader/Http/Controllers/Api/UploaderController.php(47): TusPhp\\Tus\\Server->serve()
@ankitpokhrel
Copy link
Owner

@renepardon this seems related to #287 and updating RedisStore constructor to accept an instance of redis client would probably solve this issue as well.

@renepardon
Copy link
Contributor Author

@ankitpokhrel ok, if this helps would be nice. I'll keep the file cache for this time. But the env vars should be used instead of static configuration like 127.0.0.1?

@ankitpokhrel
Copy link
Owner

Correct, we need to get it from env if it is defined.

'redis' => [
'host' => getenv('REDIS_HOST') !== false ? getenv('REDIS_HOST') : '127.0.0.1',
'port' => getenv('REDIS_PORT') !== false ? getenv('REDIS_PORT') : '6379',
'database' => getenv('REDIS_DB') !== false ? getenv('REDIS_DB') : 0,
],

@ankitpokhrel
Copy link
Owner

Closing this as a duplicate of #287

@muhamedRadwan
Copy link

@ankitpokhrel how I can pass the redis password?
can I make pull request for it?

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

No branches or pull requests

3 participants