Redis
Redis (short for Remote Dictionary Server) is an in-memory key-value data store prized for extremely low latency — individual operations complete in microseconds. Although it is called a database, in practice it usually acts as a universal layer between your application and a slower persistent store such as MySQL or PostgreSQL.
How Redis works
Redis holds all data in RAM, which makes reads and writes orders of magnitude faster than disk-backed storage. It is more than a plain cache, though: Redis understands the structure of the values it stores and ships ready-made operations for several data types:
- strings — simple values, counters, flags,
- lists — job queues (push and pop from either end),
- sets and sorted sets — unique collections and weighted leaderboards,
- hashes — multi-field objects such as a user session,
- pub/sub and streams — real-time event delivery.
So data is not lost on restart, Redis provides durability through RDB snapshots and the AOF log; it also supports master-replica replication and clustering for high availability.
Redis in practice
The most common role is offloading a relational database by acting as a caching buffer: query results or whole page fragments live in memory and are served in a fraction of a millisecond. Beyond caching, Redis serves as a web-session store, a broker for background task queues (sending mail, generating reports), a request-limit counter for rate limiting, and an event bus for real-time features. On hosting platforms and VPS servers Redis is frequently the default cache and session engine for PHP applications, measurably cutting response times under load.
Powiązane pojęcia
Najczęstsze pytania
Does Redis lose data when the server restarts?
Not necessarily. Redis keeps data in RAM but offers two durability options: periodic RDB snapshots written to disk, and an append-only file (AOF) that logs every write. Configured properly, data survives a restart — though Redis is most often used where occasional loss is acceptable.
How is Redis different from Memcached?
Both are fast in-memory stores, but Redis supports rich data types (lists, sets, hashes, sorted sets), on-disk persistence, replication and pub/sub. Memcached is simpler and holds only plain key-value pairs, which can be enough for pure caching.
