Sure - I'll try to explain better :)
> If a key has a TTL set, then it CAN be evicted anytime with this policy, even if the TTL is non-zero.
Yes. A non-zero TTL means that the key 1) exists (i.e. yet to expire) and 2) it is marked as volatile.
All eviction policies are triggered by memory pressure and operate only on existing keys. The `volatile-*` subgroup of eviction policies operate solely on volatile existing keys.
`volatile-ttl` picks the shortest-to-live keys from the candidates it samples (sample size is configurable), but small samples (default is 5 iirc) and significant percentages of long-lived keys in the keyspace increase the probability of these being evicted (instead of shorter-lived ones).
> Assuming all expired keys are already evicted, then it is possible that soon to be expired keys (which are still alive) can still be evicted.
Exactly! Expired keys are "evicted" first, but that's not really eviction because they don't (logically) exist anymore. If all memory was reclaimed and reallocated to existing keys, that's when the `maxmemory-policy` that is used kicks into action.
> Wondering if there is a policy that can decide not to evict keys which still have a positive TTL?
Actually, there is - it is called `noeviction` and it is the default. I hope this makes sense.