Steady-Entertainment
7 months ago
368
1
General

REDIS

Posted 7 months ago by Steady-Entertainment

It is very confusing I have REDIS installed gloablly in my development environment

it is booted up and running.

I have the following test which runns successfully ... easy no problem

namespace Tests\Feature;

use Illuminate\Support\Facades\Redis;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class TrendingThreadsTest extends TestCase {

    use DatabaseMigrations;

    protected function setUp(): void
    {
        parent::setUp();

        Redis::del('trending_threads');
    }

    /** @test */
    public function 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());
        $trending = Redis::zrevrange('trending_threads', 0, -1);
        $this->assertCount(1, $trending);
        $this->assertEquals($thread->title, json_decode($trending[0])->title);
    }
}

the controller is very simpe as well

public function show($channel, Thread $thread)
    {
        if (auth()->check()) {
            auth()->user()->read($thread);
        }

        Redis::zincrby('trending_threads', 1, json_encode([
            'title' => $thread->title,
            'path' => $thread->path()
        ]));

        return view('threads.show', compact('thread'));
    }

so in the end I am just increasing redis 'trending_threads' zsorted list whenever I visit my thread.

no problem so far ....

but when I hit the url for threads controller @ show a few times I have no entries in the zrange 'trending_threads' list .... it returns

127.0.0.1:6379> zrevrange trending_threads 0 -1
(empty list or set)

this makes absolutley no sence since the test is returning green

Please sign in or create an account to participate in this conversation.