Describe the bug
we are adding a key to redis with ttl of 20 minutes(1200 seconds), after few seconds, most cases 1-2, key is disappearing from redis
To reproduce
redis:6379[1]> setex aaa 1200 aaa
OK
redis:6379[1]> ttl aaa
(integer) 1197
redis:6379[1]> ttl aaa
(integer) 1195
redis:6379[1]> ttl aaa
(integer) 1190
redis:6379[1]> ttl aaa
(integer) 1182
redis:6379[1]> ttl aaa
(integer) 1175
redis:6379[1]> ttl aaa
(integer) 1169
redis:6379[1]> ttl aaa
(integer) -2
`
**Expected behavior**
key will expire only after 20 minutes
**Comment From: oranagra**
@itzikiusa i can't reproduce this.
please tell me which redis version are you using.
any chance this key is deleted by something else (e.g. eviction)?
maybe it would help if you share your `INFO ALL` output, and specify if there is any other traffic on your redis.
another alternative to look into what's deleting this key is by listening for keyspace notifications using another clients:
127.0.0.1:6379> config set notify-keyspace-events KEA 127.0.0.1:6379> psubscribe '__key__:'
or specifically for your keys: `psubscribe '__keyspace@0__:aaa'`
**Comment From: itzikiusa**
@oranagra thanks for the quick reply - this is from INFO ALL
```INFO ALL
# Server
redis_version:5.0.3
redis_git_sha1:0
redis_git_dirty:0
redis_build_id:0
redis_mode:standalone
os:Amazon ElastiCache
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:0.0.0
process_id:1
run_id:c92b6afaba04505732b0d5ec1138b31f165273ca
tcp_port:6379
uptime_in_seconds:11244463
uptime_in_days:130
hz:10
configured_hz:10
lru_clock:7459245
executable:-
config_file:-
# Clients
connected_clients:24
client_recent_max_input_buffer:4
client_recent_max_output_buffer:0
blocked_clients:0
# Memory
used_memory:424273208
used_memory_human:404.62M
used_memory_rss:453545984
used_memory_rss_human:432.54M
used_memory_peak:645612032
used_memory_peak_human:615.70M
used_memory_peak_perc:65.72%
used_memory_overhead:39928156
used_memory_startup:3668728
used_memory_dataset:384345052
used_memory_dataset_perc:91.38%
allocator_allocated:424789792
allocator_active:425594880
allocator_resident:462901248
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:436469760
maxmemory_human:416.25M
maxmemory_policy:volatile-lru
allocator_frag_ratio:1.00
allocator_frag_bytes:805088
allocator_rss_ratio:1.09
allocator_rss_bytes:37306368
rss_overhead_ratio:0.98
rss_overhead_bytes:-9355264
mem_fragmentation_ratio:1.07
mem_fragmentation_bytes:29273696
mem_not_counted_for_evict:0
mem_replication_backlog:1048576
mem_clients_slaves:66840
mem_clients_normal:605452
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0
# Persistence
loading:0
rdb_changes_since_last_save:51883599
rdb_bgsave_in_progress:0
rdb_last_save_time:1590050302
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:5644288
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
aof_last_cow_size:0
# Stats
total_connections_received:548240
total_commands_processed:473753772
instantaneous_ops_per_sec:27
total_net_input_bytes:153903853190
total_net_output_bytes:10162335155459
instantaneous_input_kbps:1.93
instantaneous_output_kbps:13.03
rejected_connections:0
sync_full:3
sync_partial_ok:0
sync_partial_err:3
expired_keys:5138825
expired_stale_perc:0.00
expired_time_cap_reached_count:0
evicted_keys:30613
keyspace_hits:322935343
keyspace_misses:45040880
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:736
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
# Replication
role:master
connected_slaves:2
slave0:ip=10.0.1.173,port=6379,state=online,offset=355966613584,lag=1
slave1:ip=10.0.2.205,port=6379,state=online,offset=355966613584,lag=1
master_replid:6f3a55fe457c244ec309300a940cd4583e18266e
master_replid2:da5d1d72c1b04651cfd6db8afec5aecfa975dba3
master_repl_offset:355966613681
second_repl_offset:228077762596
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:355965565106
repl_backlog_histlen:1048576
# CPU
used_cpu_sys:24816.190225
used_cpu_user:14304.554125
used_cpu_sys_children:0.027175
used_cpu_user_children:0.198068
# Commandstats
cmdstat_ttl:calls=27389,usec=66492,usec_per_call=2.43
cmdstat_exec:calls=1,usec=78,usec_per_call=78.00
cmdstat_select:calls=12,usec=21,usec_per_call=1.75
cmdstat_expire:calls=550982,usec=1330689,usec_per_call=2.42
cmdstat_del:calls=11299277,usec=15238372,usec_per_call=1.35
cmdstat_multi:calls=1,usec=1,usec_per_call=1.00
cmdstat_slaveof:calls=2,usec=195,usec_per_call=97.50
cmdstat_set:calls=11714,usec=59374,usec_per_call=5.07
cmdstat_get:calls=6839692,usec=17040283,usec_per_call=2.49
cmdstat_keys:calls=3377,usec=32436189,usec_per_call=9605.03
cmdstat_client:calls=374812,usec=37944893,usec_per_call=101.24
cmdstat_ping:calls=7292149,usec=9157326,usec_per_call=1.26
cmdstat_memory:calls=4,usec=10245,usec_per_call=2561.25
cmdstat_hmset:calls=11927386,usec=92446072,usec_per_call=7.75
cmdstat_psubscribe:calls=1,usec=3,usec_per_call=3.00
cmdstat_flushall:calls=29,usec=164077,usec_per_call=5657.83
cmdstat_setex:calls=5183646,usec=27501974,usec_per_call=5.31
cmdstat_hdel:calls=46,usec=157,usec_per_call=3.41
cmdstat_psync:calls=3,usec=278,usec_per_call=92.67
cmdstat_config:calls=20479,usec=2111162,usec_per_call=103.09
cmdstat_hget:calls=336561582,usec=4930041786,usec_per_call=14.65
cmdstat_info:calls=15789381,usec=1810427758,usec_per_call=114.66
cmdstat_command:calls=13,usec=13098,usec_per_call=1007.54
cmdstat_exists:calls=2085987,usec=3087317,usec_per_call=1.48
cmdstat_hgetall:calls=22461573,usec=93029211,usec_per_call=4.14
cmdstat_replconf:calls=22358019,usec=27311694,usec_per_call=1.22
cmdstat_hset:calls=30966215,usec=110435035,usec_per_call=3.57
# SSL
ssl_enabled:no
ssl_connections_to_previous_certificate:0
ssl_connections_to_current_certificate:0
ssl_current_certificate_not_before_date:(null)
ssl_current_certificate_not_after_date:(null)
ssl_current_certificate_serial:0
# Cluster
cluster_enabled:0
# Keyspace
db0:keys=544786,expires=5,avg_ttl=896421`
**Comment From: itzikiusa**
getting this error when trying to set config -
```config set notify-keyspace-events KEA
(error) ERR unknown command `config`, with args beginning with: `set`, `notify-keyspace-events`, `KEA`
**Comment From: oranagra**
I suppose Amazon ElasticCache doesn't support keyspace notifications.
i'm guessing your key is evicted..
you're very close to the memory limit and the eviction policy allows these keys to be evicted.
used_memory_human:404.62M maxmemory_human:416.25M maxmemory_policy:volatile-lru ```
Comment From: itzikiusa
what can i do?
Comment From: oranagra
few random options:
- increase the memory limit (add memory)
- reduce memory usage by (delete something?)
- change to noeviction policy and get OOM error instead of implicit deletions
Comment From: itzikiusa
my guess is that the last one isn't recommended, will try the others, thanks!
Comment From: oranagra
closing this for now, feel free to re-open or respond if you find an issue with Redis.
Comment From: itzikiusa
yeah, thanks!