Buenas, estoy intentando incorporar Redis en Laravel y estoy teniendo problemas con el almacenamiento, no funciona y ahora mismo no sé qué más hacer.
Lo que he hecho hasta ahora es:
- Instalar extensión de PHP. Si ejecuto
extension_loaded('redis')
devuelve true
.
- Instalar con composer el paquete
predis
.
- Cambiar en el
.env
el valor de la caché por CACHE_DRIVER=redis
.
- Cambiar en el
app/config/cache.php
el valor de default por 'default' => env('CACHE_DRIVER', 'redis')
El código que tengo para almacenar en caché es este:
$projects = Cache::remember('projects.all', 60, function(){
return Project::get();
});
Pero a la hora de hacer un keys *
en la consola con Redis CLI me dice que no hay ninguna.
El caso es que en el archivo routes tengo este código para saber qué consultas se hacen en cada página
DB::listen(function($sql){
echo "<pre>".$sql->sql."</pre>";
});
Y cuando entro al listado de proyectos aparece la consulta que se los trae todos, y si recargo la página antes de 60 segundos no aparece. Entiendo que lo que está ocurriendo es que se está guardando en otro lado el resultado de la caché.
Extra info:
- Versión de PHP 7.4.2
- Versión de Redis 3.2.100
- Versión de Laravel 6.2
http://localhost/redis/?infoKey
Value
Server
Array
(
[redis_version] => 3.2.100
[redis_git_sha1] => 00000000
[redis_git_dirty] => 0
[redis_build_id] => dd26f1f93c5130ee
[redis_mode] => standalone
[os] => Windows
[arch_bits] => 64
[multiplexing_api] => WinSock_IOCP
[process_id] => 14292
[run_id] => 8e0c2fb6faab5d62ee28944d17e7b9498040a3b8
[tcp_port] => 6379
[uptime_in_seconds] => 1388
[uptime_in_days] => 0
[hz] => 10
[lru_clock] => 5488796
[executable] => C:\laragon\bin\redis\redis-x64-3.2.100\redis-server.exe
[config_file] => C:\laragon\bin\redis\redis-x64-3.2.100\redis.conf
)
Clients
Array
(
[connected_clients] => 1
[client_longest_output_list] => 0
[client_biggest_input_buf] => 0
[blocked_clients] => 0
)
Memory
Array
(
[used_memory] => 689448
[used_memory_human] => 673.29K
[used_memory_rss] => 630672
[used_memory_rss_human] => 615.89K
[used_memory_peak] => 722960
[used_memory_peak_human] => 706.02K
[total_system_memory] => 0
[total_system_memory_human] => 0B
[used_memory_lua] => 37888
[used_memory_lua_human] => 37.00K
[maxmemory] => 0
[maxmemory_human] => 0B
[maxmemory_policy] => noeviction
[mem_fragmentation_ratio] => 0.91
[mem_allocator] => jemalloc-3.6.0
)
Persistence
Array
(
[loading] => 0
[rdb_changes_since_last_save] => 2
[rdb_bgsave_in_progress] => 0
[rdb_last_save_time] => 1582546436
[rdb_last_bgsave_status] => ok
[rdb_last_bgsave_time_sec] => 0
[rdb_current_bgsave_time_sec] => -1
[aof_enabled] => 0
[aof_rewrite_in_progress] => 0
[aof_rewrite_scheduled] => 0
[aof_last_rewrite_time_sec] => -1
[aof_current_rewrite_time_sec] => -1
[aof_last_bgrewrite_status] => ok
[aof_last_write_status] => ok
)
Stats
Array
(
[total_connections_received] => 32
[total_commands_processed] => 64
[instantaneous_ops_per_sec] => 0
[total_net_input_bytes] => 75088
[total_net_output_bytes] => 35692
[instantaneous_input_kbps] => 0.01
[instantaneous_output_kbps] => 0.00
[rejected_connections] => 0
[sync_full] => 0
[sync_partial_ok] => 0
[sync_partial_err] => 0
[expired_keys] => 3
[evicted_keys] => 0
[keyspace_hits] => 13
[keyspace_misses] => 8
[pubsub_channels] => 0
[pubsub_patterns] => 0
[latest_fork_usec] => 5694
[migrate_cached_sockets] => 0
)
Replication
Array
(
[role] => master
[connected_slaves] => 0
[master_repl_offset] => 0
[repl_backlog_active] => 0
[repl_backlog_size] => 1048576
[repl_backlog_first_byte_offset] => 0
[repl_backlog_histlen] => 0
)
CPU
Array
(
[used_cpu_sys] => 0.09
[used_cpu_user] => 0.09
[used_cpu_sys_children] => 0.00
[used_cpu_user_children] => 0.00
)
Cluster
Array
(
[cluster_enabled] => 0
)
Keyspace
Array
(
)
¿Qué me falta por configurar?