skip to Main Content

I have redis problem in laravel, I’m using laradock to upload my containers, but I don’t know why it’s not working.
When I ran the command redis-server in the terminal inside the bash of redis I saw that I was returning this error:

C:UsersdanilOneDriveÁrea de TrabalhoBuilderAllmercaloo-sellerlaradock>docker-compose exec redis bash
root@2e4c45a362d1:/data# redis-server
25:C 12 Jun 2021 10:33:24.322 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
25:C 12 Jun 2021 10:33:24.322 # Redis version=6.2.4, bits=64, commit=00000000, modified=0, pid=25, just started
25:C 12 Jun 2021 10:33:24.322 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
25:M 12 Jun 2021 10:33:24.323 * monotonic clock: POSIX clock_gettime
25:M 12 Jun 2021 10:33:24.323 # Warning: Could not create server TCP listening socket *:6379: bind: Address already in use
25:M 12 Jun 2021 10:33:24.324 # Failed listening on port 6379 (TCP), aborting.

I don’t know if I failed to execute any commands, but to me everything seems fine.

When I try to access my endpoint it returns this one:

PredisConnectionConnectionException: `SELECT` failed: ERR value is not an integer or out of range [tcp://redis:6379] in file /var/www/vendor/predis/predis/src/Connection/AbstractConnection.php on line 155

#0 /var/www/vendor/predis/predis/src/Connection/StreamConnection.php(263): PredisConnectionAbstractConnection->onConnectionError('`SELECT` failed...', 0)
#1 /var/www/vendor/predis/predis/src/Connection/AbstractConnection.php(180): PredisConnectionStreamConnection->connect()
#2 /var/www/vendor/predis/predis/src/Connection/StreamConnection.php(288): PredisConnectionAbstractConnection->getResource()
#3 /var/www/vendor/predis/predis/src/Connection/StreamConnection.php(394): PredisConnectionStreamConnection->write('*2rn$3rnGETrn$7...')
#4 /var/www/vendor/predis/predis/src/Connection/AbstractConnection.php(110): PredisConnectionStreamConnection->writeRequest(Object(PredisCommandStringGet))
#5 /var/www/vendor/predis/predis/src/Client.php(331): PredisConnectionAbstractConnection->executeCommand(Object(PredisCommandStringGet))
#6 /var/www/vendor/predis/predis/src/Client.php(314): PredisClient->executeCommand(Object(PredisCommandStringGet))
#7 /var/www/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(116): PredisClient->__call('get', Array)
#8 /var/www/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(220): IlluminateRedisConnectionsConnection->command('get', Array)
#9 /var/www/vendor/laravel/framework/src/Illuminate/Cache/RedisStore.php(61): IlluminateRedisConnectionsConnection->__call('get', Array)
#10 /var/www/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(97): IlluminateCacheRedisStore->get('ZEFGuY6VfjzpCBC...')
#11 /var/www/vendor/laravel/framework/src/Illuminate/Session/CacheBasedSessionHandler.php(58): IlluminateCacheRepository->get('ZEFGuY6VfjzpCBC...', '')
#12 /var/www/vendor/laravel/framework/src/Illuminate/Session/Store.php(97): IlluminateSessionCacheBasedSessionHandler->read('ZEFGuY6VfjzpCBC...')
#13 /var/www/vendor/laravel/framework/src/Illuminate/Session/Store.php(87): IlluminateSessionStore->readFromHandler()
#14 /var/www/vendor/laravel/framework/src/Illuminate/Session/Store.php(71): IlluminateSessionStore->loadSession()
#15 /var/www/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(147): IlluminateSessionStore->start()
#16 /var/www/vendor/laravel/framework/src/Illuminate/Support/helpers.php(263): IlluminateSessionMiddlewareStartSession->IlluminateSessionMiddleware{closure}(Object(IlluminateSessionStore))
#17 /var/www/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(148): tap(Object(IlluminateSessionStore), Object(Closure))
#18 /var/www/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(116): IlluminateSessionMiddlewareStartSession->startSession(Object(IlluminateHttpRequest), Object(IlluminateSessionStore))
#19 /var/www/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(63): IlluminateSessionMiddlewareStartSession->handleStatefulRequest(Object(IlluminateHttpRequest), Object(IlluminateSessionStore), Object(Closure))
#20 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): IlluminateSessionMiddlewareStartSession->handle(Object(IlluminateHttpRequest), Object(Closure))
#21 /var/www/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#22 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): IlluminateCookieMiddlewareAddQueuedCookiesToResponse->handle(Object(IlluminateHttpRequest), Object(Closure))
#23 /var/www/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#24 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): IlluminateCookieMiddlewareEncryptCookies->handle(Object(IlluminateHttpRequest), Object(Closure))
#25 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#26 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(695): IlluminatePipelinePipeline->then(Object(Closure))
#27 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(670): IlluminateRoutingRouter->runRouteWithinStack(Object(IlluminateRoutingRoute), Object(IlluminateHttpRequest))
#28 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(636): IlluminateRoutingRouter->runRoute(Object(IlluminateHttpRequest), Object(IlluminateRoutingRoute))
#29 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(625): IlluminateRoutingRouter->dispatchToRoute(Object(IlluminateHttpRequest))
#30 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(166): IlluminateRoutingRouter->dispatch(Object(IlluminateHttpRequest))
#31 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): IlluminateFoundationHttpKernel->IlluminateFoundationHttp{closure}(Object(IlluminateHttpRequest))
#32 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#33 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): IlluminateFoundationHttpMiddlewareTransformsRequest->handle(Object(IlluminateHttpRequest), Object(Closure))
#34 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#35 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): IlluminateFoundationHttpMiddlewareTransformsRequest->handle(Object(IlluminateHttpRequest), Object(Closure))
#36 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#37 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): IlluminateFoundationHttpMiddlewareValidatePostSize->handle(Object(IlluminateHttpRequest), Object(Closure))
#38 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#39 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): IlluminateFoundationHttpMiddlewarePreventRequestsDuringMaintenance->handle(Object(IlluminateHttpRequest), Object(Closure))
#40 /var/www/vendor/fruitcake/laravel-cors/src/HandleCors.php(57): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#41 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): FruitcakeCorsHandleCors->handle(Object(IlluminateHttpRequest), Object(Closure))
#42 /var/www/vendor/fideloper/proxy/src/TrustProxies.php(57): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#43 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): FideloperProxyTrustProxies->handle(Object(IlluminateHttpRequest), Object(Closure))
#44 /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#45 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(141): IlluminatePipelinePipeline->then(Object(Closure))
#46 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): IlluminateFoundationHttpKernel->sendRequestThroughRouter(Object(IlluminateHttpRequest))
#47 /var/www/public/index.php(52): IlluminateFoundationHttpKernel->handle(Object(IlluminateHttpRequest))
#48 {main}

I’ll leave here how I’m configuring the redis:

.env file:

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
REDIS_URL=redis
QUEUE_CONNECTION=sync
SESSION_DRIVER=redis
SESSION_LIFETIME=126
SESSION_CONNECTION=session

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_CLIENT = predis
REDIS_PORT=6379

configdatabase.php file:

<?php

use IlluminateSupportStr;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION', 'mysql'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer body of commands than a typical key-value system
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'client' => env('REDIS_CLIENT', 'phpredis'),

        'options' => [
            'cluster' => env('REDIS_CLUSTER', 'redis'),
            'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
        ],

        'default' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_DB', '0'),
        ],

        'cache' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_CACHE_DB', '2'),
        ],

        'session' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', '6379'),
            'database' => '1',
            'prefix' => 's:'
        ],

    ],

];

configcache.php file:

<?php

use IlluminateSupportStr;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Cache Store
    |--------------------------------------------------------------------------
    |
    | This option controls the default cache connection that gets used while
    | using this caching library. This connection is used when another is
    | not explicitly specified when executing a given caching function.
    |
    */

    'default' => env('CACHE_DRIVER', 'file'),

    /*
    |--------------------------------------------------------------------------
    | Cache Stores
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the cache "stores" for your application as
    | well as their drivers. You may even define multiple stores for the
    | same cache driver to group types of items stored in your caches.
    |
    | Supported drivers: "apc", "array", "database", "file",
    |            "memcached", "redis", "dynamodb", "null"
    |
    */

    'stores' => [

        'apc' => [
            'driver' => 'apc',
        ],

        'array' => [
            'driver' => 'array',
            'serialize' => false,
        ],

        'database' => [
            'driver' => 'database',
            'table' => 'cache',
            'connection' => null,
            'lock_connection' => null,
        ],

        'file' => [
            'driver' => 'file',
            'path' => storage_path('framework/cache/data'),
        ],

        'memcached' => [
            'driver' => 'memcached',
            'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
            'sasl' => [
                env('MEMCACHED_USERNAME'),
                env('MEMCACHED_PASSWORD'),
            ],
            'options' => [
                // Memcached::OPT_CONNECT_TIMEOUT => 2000,
            ],
            'servers' => [
                [
                    'host' => env('MEMCACHED_HOST', '127.0.0.1'),
                    'port' => env('MEMCACHED_PORT', 11211),
                    'weight' => 100,
                ],
            ],
        ],

        'redis' => [
            'driver' => 'redis',
            'connection' => 'cache',
            'lock_connection' => 'default',
        ],

        'dynamodb' => [
            'driver' => 'dynamodb',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
            'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
            'endpoint' => env('DYNAMODB_ENDPOINT'),
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Cache Key Prefix
    |--------------------------------------------------------------------------
    |
    | When utilizing a RAM based store such as APC or Memcached, there might
    | be other applications utilizing the same cache. So, we'll specify a
    | value to get prefixed to all our keys so we can avoid collisions.
    |
    */

    'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'),

];

configsession.php file:

<?php

use IlluminateSupportStr;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Session Driver
    |--------------------------------------------------------------------------
    |
    | This option controls the default session "driver" that will be used on
    | requests. By default, we will use the lightweight native driver but
    | you may specify any of the other wonderful drivers provided here.
    |
    | Supported: "file", "cookie", "database", "apc",
    |            "memcached", "redis", "dynamodb", "array"
    |
    */

    'driver' => env('SESSION_DRIVER', 'file'),

    /*
    |--------------------------------------------------------------------------
    | Session Lifetime
    |--------------------------------------------------------------------------
    |
    | Here you may specify the number of minutes that you wish the session
    | to be allowed to remain idle before it expires. If you want them
    | to immediately expire on the browser closing, set that option.
    |
    */

    'lifetime' => env('SESSION_LIFETIME', 120),

    'expire_on_close' => false,

    /*
    |--------------------------------------------------------------------------
    | Session Encryption
    |--------------------------------------------------------------------------
    |
    | This option allows you to easily specify that all of your session data
    | should be encrypted before it is stored. All encryption will be run
    | automatically by Laravel and you can use the Session like normal.
    |
    */

    'encrypt' => false,

    /*
    |--------------------------------------------------------------------------
    | Session File Location
    |--------------------------------------------------------------------------
    |
    | When using the native session driver, we need a location where session
    | files may be stored. A default has been set for you but a different
    | location may be specified. This is only needed for file sessions.
    |
    */

    'files' => storage_path('framework/sessions'),

    /*
    |--------------------------------------------------------------------------
    | Session Database Connection
    |--------------------------------------------------------------------------
    |
    | When using the "database" or "redis" session drivers, you may specify a
    | connection that should be used to manage these sessions. This should
    | correspond to a connection in your database configuration options.
    |
    */

    'connection' => env('SESSION_CONNECTION', null),

    /*
    |--------------------------------------------------------------------------
    | Session Database Table
    |--------------------------------------------------------------------------
    |
    | When using the "database" session driver, you may specify the table we
    | should use to manage the sessions. Of course, a sensible default is
    | provided for you; however, you are free to change this as needed.
    |
    */

    'table' => 'sessions',

    /*
    |--------------------------------------------------------------------------
    | Session Cache Store
    |--------------------------------------------------------------------------
    |
    | While using one of the framework's cache driven session backends you may
    | list a cache store that should be used for these sessions. This value
    | must match with one of the application's configured cache "stores".
    |
    | Affects: "apc", "dynamodb", "memcached", "redis"
    |
    */

    'store' => env('SESSION_STORE', null),

    /*
    |--------------------------------------------------------------------------
    | Session Sweeping Lottery
    |--------------------------------------------------------------------------
    |
    | Some session drivers must manually sweep their storage location to get
    | rid of old sessions from storage. Here are the chances that it will
    | happen on a given request. By default, the odds are 2 out of 100.
    |
    */

    'lottery' => [2, 100],

    /*
    |--------------------------------------------------------------------------
    | Session Cookie Name
    |--------------------------------------------------------------------------
    |
    | Here you may change the name of the cookie used to identify a session
    | instance by ID. The name specified here will get used every time a
    | new session cookie is created by the framework for every driver.
    |
    */

    'cookie' => env(
        'SESSION_COOKIE',
        Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
    ),

    /*
    |--------------------------------------------------------------------------
    | Session Cookie Path
    |--------------------------------------------------------------------------
    |
    | The session cookie path determines the path for which the cookie will
    | be regarded as available. Typically, this will be the root path of
    | your application but you are free to change this when necessary.
    |
    */

    'path' => '/',

    /*
    |--------------------------------------------------------------------------
    | Session Cookie Domain
    |--------------------------------------------------------------------------
    |
    | Here you may change the domain of the cookie used to identify a session
    | in your application. This will determine which domains the cookie is
    | available to in your application. A sensible default has been set.
    |
    */

    'domain' => env('SESSION_DOMAIN', null),

    /*
    |--------------------------------------------------------------------------
    | HTTPS Only Cookies
    |--------------------------------------------------------------------------
    |
    | By setting this option to true, session cookies will only be sent back
    | to the server if the browser has a HTTPS connection. This will keep
    | the cookie from being sent to you if it can not be done securely.
    |
    */

    'secure' => env('SESSION_SECURE_COOKIE'),

    /*
    |--------------------------------------------------------------------------
    | HTTP Access Only
    |--------------------------------------------------------------------------
    |
    | Setting this value to true will prevent JavaScript from accessing the
    | value of the cookie and the cookie will only be accessible through
    | the HTTP protocol. You are free to modify this option if needed.
    |
    */

    'http_only' => true,

    /*
    |--------------------------------------------------------------------------
    | Same-Site Cookies
    |--------------------------------------------------------------------------
    |
    | This option determines how your cookies behave when cross-site requests
    | take place, and can be used to mitigate CSRF attacks. By default, we
    | will set this value to "lax" since this is a secure default value.
    |
    | Supported: "lax", "strict", "none", null
    |
    */

    'same_site' => 'lax',

];

Docker

These are the containers in the docker

Can anyone identify the problem?

2

Answers


  1. I think you could get rid of that error by either removing or maybe fixing the formatting on this line of your .env file:

    REDIS_CLIENT = predis
    

    You could try and removing the spaces, or removing it entirely, I don’t think its necessary.

    Login or Signup to reply.
  2. Maybe it will be utile someone…
    Once upon time I have the some problem on website Laravel.

    Only reinstallation redis client helped me decide this problem:

    composer remove predis/predis
    composer require predis/predis
    

    Was in composer.json:

    "predis/predis": "1.1",
    

    It became in composer.json:

    "predis/predis": "^2.2",
    

    Functionality testing in development environment:

    • PHP v7.4
    • Laravel v7.29
    • Redis v7.0
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search