IO Model
Memcached is multi-thread, not block reuse IO net model.
it has main listen thread main worker sub thread.
‘leader’ listened net connnect, dispatch to worker thread.
In network layer, memcached use libevent package event.
But this bring concurrency and lock problem, like stats
command.
Redis reuse single thread IO model, it’s self package a AeEvent event framework.
It implements epoll
kqueue
select
event,
for simple IO operation, single thread can reach the top speed.
But for some calc operation, this affect global throughput alot.
Memory manage
Memcached use prepare way to manage memory.
In this way memory pool can avoid the cost in apply and release memory.
Redis use real-time way to manage memory.
Data consistency
Memcached provide cas
command, it can make sure data consistency.
Redis has no cas
command, but it provide transaction function.
It make sure series of commands’ atomicity, it wouldn’t be interrupted.
Storage way
Memcached only support key-value
storage,
not support enumerate / persistence/ copy and so on function.
Redis support except key-value
way, but list
set
sorted
set
hash
.
In other hand, redis support data persistence, copy and so on function.
Summary
When data in-memory use Redis is better.
Redis in alot of place play a role in replace Memcached.
When need other data structure, Redis is better.
When storage data can’t be remove, Redis is better.