I trying to cache all users into Redis. It worked well in local Redis when I try to set up with Redis cloud not worked anymore.
For setup, I followed these steps;
I subscribe Redis Cloud for a 30MB free subscription. added predis package to laravel project;
composer require predis/predis
after all, edited .env
file according to the public endpoint and default user password ;
.env ;
REDIS_CLIENT=predis
REDIS_HOST=redis-16388.c250.eu-central-1-1.ec2.cloud.redislabs.com
REDIS_PASSWORD=yH********************
REDIS_PORT=16388
Code ;
public function show()
{
if (Cache::has('users')) {
$data = Cache::get('users');
return response()->json($data, 200);
}
$data = User::all();
Cache::put('users', $data, 40);
return response()->json($data, 200);
}
Error;
Predis\Connection\ConnectionException:
SELECT
failed: ERR DB index is out of range [tcp://redis-16388.c250.eu-central-1-1.ec2.cloud.redislabs.com:16388] in file C:\xampp\htdocs\redisPro\vendor\predis\predis\src\Connection\AbstractConnection.php on line 155