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

Comments

Popular posts from this blog

How to Install and Use Wine on Ubuntu 20.04

Laravel: How to Paginate Collection