Skip to content

Instantly share code, notes, and snippets.

@lnfel
Created April 23, 2021 02:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save lnfel/ab04028d6b115304ca5daef145710ac0 to your computer and use it in GitHub Desktop.
Save lnfel/ab04028d6b115304ca5daef145710ac0 to your computer and use it in GitHub Desktop.
Laravel 8 Redis setup on Windows with xampp
Laravel 8 Redis setup on Windows with xampp
Note: test done using windows 7
1. Install predis on your project
https://laravel.com/docs/8.x/redis#introduction
composer require predis/predis
- un-comment 'Redis' => Illuminate\Support\Facades\Redis::class, in your config/app.php
- on your .env make sure you have the following variables:
REDIS_CLIENT=predis
REDIS_PORT=6379
2. Download php_redis.dll on pecl
https://pecl.php.net/package/redis
- extract the zip file and move php_redis.dll to your xampp php ext folder
- usually is at C:\xampp\php\ext
- edit C:\xampp\php\php.ini and make sure it has the extension enabled or add the following line:
[Redis]
extension=php_redis.dll
3. Download or install Redis-x64-3.2.100 for Windows
https://github.com/MicrosoftArchive/redis/releases/
- if your downloaded the zip don't forget to add the path to your environment variables
4. Restart xampp server
- make sure APP_DEBUG=true in your .env to see any errors
- refresh your laravel config by running the following commands
php artisan config:clear
php artisan config:cache
5. Test the following code in your controller
use Redis;
class YourController extends Controller
{
public function index()
{
$redis = new Redis();
$redis->connect('localhost', 6379);
$redis->set('user', 'John Doe');
$value = $redis->get('user');
dd($value);
}
}
- you should see the output "John Doe" when browsing the app on localhost
@ImanAslani666
Copy link

Hi
I have this error
Call to undefined method Illuminate\Support\Facades\Redis::connect()

@zoya-mtp
Copy link

i got this error
No connection could be made because the target machine actively refused it [tls://127.0.0.1:6380]

@LukasCCB
Copy link

Config/database.php

'redis' => [

    'client' => 'predis',

    'default' => [
        'scheme' => 'unix',
        //'path' => '/var/run/redis/redis.sock'
        // 'host' => env('REDIS_HOST', '127.0.0.1'),
        // 'password' => env('REDIS_PASSWORD', null),
        // 'port' => env('REDIS_PORT', 6379),
        // 'database' => 0,
        // 'unix-socket' => '/var/run/redis/redis.sock'
    ],

Problem with 'Path' on Windows.
Missing UNIX domain socket path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment