I have a Laravel application that I am integrating a Redis Server into to handle the application caching. However I am having issues with the Redis configuration, as I am not able to access the Redis interface using the Laravel cache facade.
I set up a redis-server and comfirmed that it is working on the server:
> redis-cli
127.0.0.1:6379 > ping
PONG
I then followed the integration documentation for Redis/Laravel from here: https://laravel.com/docs/5.7/redis
I installed the composer predis/predis package...
I set it up in Laravel to use the default redis config:
app/config/cache.php:
'default' => env('CACHE_DRIVER', 'redis'),
app/config/database.php:
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],
'cache' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
],
]
Now when I test I can access Redis via the Redis Facade...
use Illuminate\Support\Facades\Redis;
...but not from the Cache Facade.
use Illuminate\Support\Facades\Cache;
// ************* this works
Redis::set('testFromRedisSet', 'RedisSet');
// ************* none of these work...
Cache::add('testFromCachePut', 'CachePut', 60);
Cache::remember('testFromCacheRemember', 60, function() {
return "CacheRemember";
});
Cache::rememberForever('testFromCacheRememberForever', function() {
return "CacheRememberForever";
});
127.0.0.1:6379> KEYS '*'
1) "testFromRedisSet"
127.0.0.1:6379>
Why is the Cache Facade not available when using Redis for the cache?
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2IFpLTK
via IFTTT
Aucun commentaire:
Enregistrer un commentaire