Eloquent model for Redis

2.8k views Asked by At

I have installed Laravel 5.1 with Redis and when I have tested it, I got error Database [redis] not configured.. Than I have tested it from routes using Redis instead of Eloquent model:

Route::get('/', function () {
    Redis::set("key", "testValue");
    return Redis::get("key");
});

And success...

After this i have searched and founded just it - Laravel Redis configuration

there is no support for Redis there

What to do If i want to use Redis ?

1

There are 1 answers

0
Farid Movsumov On

There is redis support for Laravel

First you should install redis server and start it as service.

config/database.php

'redis' => [

    'cluster' => false,

    'default' => [
        'host'     => '127.0.0.1',
        'port'     => 6379,
        'database' => 0,
    ],

],

Usage example:

\Cache::store('redis')->get('key', 'value', 10);
\Cache::store('redis')->get('key');

Official Documentation: https://laravel.com/docs/5.1/redis