我刚开始使用Redis。
在不使用我的应用程序10到12个小时之后,我发现Redis缓存中缺少密钥。
这是一个非 secret 的登台环境,因此无法获得Redis的安全性。
在2天的时间内发生了两次。
注意:redis是独立运行的。
我尝试从wildfly应用服务器进行连接,当应用服务器在夜间关闭时,该问题在早晨出现。
Redis保存到磁盘后,Redis是否会从内存中删除密钥?
我尝试获取统计信息,并检查了-1的键的TTL。
统计数字说:
expired_keys:0
evicted_keys:0
最大内存增加到6GB,无法达到,这比我的输入大小高
以下统计
Redis在CentOS上独立运行
127.0.0.1:6379> info
# Server
redis_version:3.2.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:7897e7d0e13773f
redis_mode:standalone
os:Linux 3.10.0-957.12.2.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:20830
run_id:eea4f3ccc73fc20e16ef20441393b1189050fdb8
tcp_port:6379
uptime_in_seconds:208558
uptime_in_days:2
hz:10
lru_clock:3417026
executable:not shown
config_file:not shown
# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
# Memory
used_memory:814024
used_memory_human:794.95K
used_memory_rss:8163328
used_memory_rss_human:7.79M
used_memory_peak:1250632
used_memory_peak_human:1.19M
total_system_memory:8201187328
total_system_memory_human:7.64G
used_memory_lua:40960
used_memory_lua_human:40.00K
maxmemory:6442450944
maxmemory_human:6.00G
maxmemory_policy:noeviction
mem_fragmentation_ratio:10.03
mem_allocator:jemalloc-3.6.0
# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1563697205
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
total_connections_received:119
total_commands_processed:378
instantaneous_ops_per_sec:0
total_net_input_bytes:26750
total_net_output_bytes:115176
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:165
keyspace_misses:27
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:928
migrate_cached_sockets:0
# Replication
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
used_cpu_sys:130.68
used_cpu_user:60.20
used_cpu_sys_children:0.26
used_cpu_user_children:0.04
# Cluster
cluster_enabled:0
Last action on Redis -valid hits from our application
14649:C 21 Jul 01:17:31.508 * RDB: 4 MB of memory used by copy-on-write
20830:M 21 Jul 01:17:31.605 * Background saving terminated with success
20830:M 21 Jul 01:32:32.018 * 1 changes in 900 seconds. Saving...
20830:M 21 Jul 01:32:32.019 * Background saving started by pid 14817
14817:C 21 Jul 01:32:32.021 * DB saved on disk
14817:C 21 Jul 01:32:32.021 * RDB: 4 MB of memory used by copy-on-write
20830:M 21 Jul 01:32:32.119 * Background saving terminated with success
20830:M 21 Jul 03:03:44.634 * 1 changes in 900 seconds. Saving...
20830:M 21 Jul 03:03:44.636 * Background saving started by pid 15843
15843:C 21 Jul 03:03:44.638 * DB saved on disk
15843:C 21 Jul 03:03:44.638 * RDB: 4 MB of memory used by copy-on-write
20830:M 21 Jul 03:03:44.736 * Background saving terminated with success
20830:M 21 Jul 03:18:45.076 * 1 changes in 900 seconds. Saving...
20830:M 21 Jul 03:18:45.079 * Background saving started by pid 16040
16040:C 21 Jul 03:18:45.080 * DB saved on disk
16040:C 21 Jul 03:18:45.081 * RDB: 4 MB of memory used by copy-on-write
20830:M 21 Jul 03:18:45.179 * Background saving terminated with success
实际结果我希望即使不使用Redis也会出现密钥
最佳答案
否,Redis不会在保存到磁盘时从内存中删除密钥。
您的正常运行时间还可以(因此重新启动时不会丢失数据),因此只剩下两个理论:
CLI
为所有存储的密钥检查Redis。 关于redis - Redis的按键丢失,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57131820/