mercredi 28 octobre 2020

Redis / Homestead / Laravel 7 - Connection Refused

I am trying to get Redis working whilst following the Let's build a forum with TDD series. I have got to Episode 66 which introduces Redis and written the first test...and then boom, it blows up. Have done a lot of googling around but the answers do not seem to correlate.

I am using homestead and thus redis should be installed in the environment - using a Vagrant box on Windows.

I have installed predis and confirm this is pulling in via the vendor library and compose package

I have SSH'd into the homestead box and run redis-cli and performed ping /pong test to confirm that the redis server is infact running.

I have also run a redis-server --version version test.

Redis server v=5.0.8 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=129cf1a0751f12a

Following the tutorial I have written the first test

public function test_it_increments_a_threads_score_each_time_it_is_read()
    {

        $this->assertEmpty( Redis::zrevrange('trending_threads', 0, -1));

        $thread = create('App\Thread');

        $this->call('GET', $thread->path());

        Redis::zrevrange('trending_threads', 0, -1);

        $this->assertCount(1,  Redis::zrevrange('trending_threads', 0, -1));


    }

and all I get is

Predis\Connection\ConnectionException : No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]

I am really struggling to work out why/how this message is persisting when I have followed everything line by line, I am not using Xamp or anything other than Homestead yet still getting this error.

The config is the standard config, updated to the predis library

    'redis' => [

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

        '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', 'localhost'),
            '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', '1'),
        ],

    ],

My Homestead Yaml

---
ip: "10.100.110.10"
memory: 2048
cpus: 2
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/code
      to: /home/vagrant/code

sites:

    - map: tweety.test.com
      to: /home/vagrant/code/tweety/public

    - map: bird.test.com
      to: /home/vagrant/code/birdboard/public

    - map: ecosystem.test.com
      to: /home/vagrant/code/ecosystem/public

    - map: multiform.test.com
      to: /home/vagrant/code/multi_upload/public


databases:
    - tweety
    - birdboard
    - ecosystem
    - multi_upload

features:
    - mariadb: false
    - ohmyzsh: false
    - webdriver: false

# ports:
#     - send: 50000
#       to: 5000
#     - send: 7777
#       to: 777
#       protocol: udp

Has anybody come across this before or have any idea on direction? It is driving me bonkers and is quite a big blocker in the series.

For reference - I am running Laravel 7 on Homestead via a Vagrant Box on my windows laptop. :)

Cheers all

Aucun commentaire:

Enregistrer un commentaire