nhayder's avatar
Level 13

Connection refused [tcp://127.0.0.1:6379] after installing predis

Im getting this error after i installed predis like this ----> composer require predis/predis

Predis \ Connection \ ConnectionException (61) Connection refused [tcp://127.0.0.1:6379]

all what i did' is to change the cache driver in .env file like this

...
BROADCAST_DRIVER=pusher
CACHE_DRIVER=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=database
...

my config/cache.php remains unchanged and never touched

<?php

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.
    |
    | Supported: "apc", "array", "database", "file", "memcached", "redis"
    |
    */

    '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.
    |
    */

    'stores' => [

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

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

        'database' => [
            'driver' => 'database',
            'table' => 'cache',
            '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' => 'default',
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | 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', 'myapp'), '_').'_cache'
    ),

];

the error appeared after i attempted to clear previous cached files ( previously my cache driver was set to file )

composer dump-auto

Not sure what is causing this error? Any Ideas

0 likes
4 replies
anton_khan's avatar

check your bootstrap/cache/ and delete config.php, or just run php artisan config:cache

4 likes
AnderBRA's avatar

You need to start redis server

redis-server &

redis-cli &

4 likes
leturfiste's avatar

The errors message shows that the Redis server isn't always running or is not accepting connections. The mistakes occurs inside the PredisConnectionAbstractConnection::onConnectionError() method, that's called while a connection errors happens.

The errors message also shows that the connection is making an attempt to connect to the Redis server on 127.0.0.1, which is the localhost cope with. This indicates that the Redis server is both no longer running at the neighborhood device or that it is not configured to just accept connections at the default port (6379).

To remedy this issue, you could strive the subsequent steps:

  1. Check if Redis is running: Use the playstation grep redis command to test if the Redis server is going for walks. If it is not running, start the Redis server the usage of the right approach for your running machine.

  2. Check Redis configuration: Check the Redis configuration file to make certain that it's far listening on the perfect port (6379) and that it isn't configured to bind to a specific IP cope with.

Three. Firewall: Check in case your firewall is blocking connections to the Redis port (6379). If vital, add a rule to permit connections to the Redis server.

Four. Network connectivity: Verify that the network connection is running nicely and that the gadget running the Redis server can speak with the device trying to connect with it.

Five. Predis model: Ensure you're the use of the state-of-the-art version of Predis, as older variations may additionally have compatibility troubles with more moderen Redis variations.

Please or to participate in this conversation.