Redis
Redis is an open-source, in-memory data structure store, often used as a database, cache, and message broker, distinguished by its support for diverse data type...
Redis (Remote Dictionary Server) - это open-source in-memory data structure store, используемый как database, cache и message broker. Он поддерживает различные data structures, такие как strings, hashes, lists, sets, sorted sets с range queries, bitmaps, hyperloglogs, geospatial indexes с radius queries и streams. Redis известен своей скоростью, так как он в основном работает in memory, обеспечивая latency менее миллисекунды для read и write операций. Его persistence может быть сконфигурирован через различные mechanisms: Snapshotting (RDB), который сохраняет point-in-time snapshots датасета, и Append Only File (AOF), который логирует каждую write операцию, полученную сервером. Redis также предлагает high availability и fault tolerance через Redis Sentinel, который обеспечивает monitoring, notification и automatic failover, и Redis Cluster, который предоставляет способ запуска установки Redis, где данные sharded между несколькими nodes, предлагая horizontal scalability и high availability. Его publish/subscribe возможности делают его подходящим для real-time messaging systems и event-driven architectures. Redis широко используется для таких use cases, как session management, real-time leaderboards, caching frequently accessed data и message queuing.
graph LR
Center["Redis"]:::main
Pre_nosql["nosql"]:::pre --> Center
click Pre_nosql "/terms/nosql"
Rel_cache["cache"]:::related -.-> Center
click Rel_cache "/terms/cache"
Rel_nginx["nginx"]:::related -.-> Center
click Rel_nginx "/terms/nginx"
classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
linkStyle default stroke:#4b5563,stroke-width:2px;
🧒 Простыми словами
Redis — это как кратковременная память вашего компьютера, но для общих данных. Он запоминает вещи невероятно быстро, потому что ему не нужно каждый раз записывать их в постоянный блокнот (жесткий диск).
🤓 Expert Deep Dive
Redis's performance is largely attributed to its single-threaded, event-driven architecture, which efficiently handles I/O multiplexing using mechanisms like epoll or kqueue. While the core operations are single-threaded to ensure atomicity and simplify development, background threads handle I/O and slow operations like disk persistence. Data structures are optimized for in-memory access; for example, hashes are implemented as hash tables, and sorted sets use a combination of hash tables and skip lists. The RDB persistence mechanism involves forking the main process, which can be I/O intensive but provides a compact snapshot. AOF persistence, while more durable, can lead to larger files and slower restarts. Redis Sentinel provides high availability by monitoring master and replica nodes and orchestrating failover. Redis Cluster shards data across multiple nodes, distributing keyspace and providing resilience against node failures, though it introduces complexity in managing distributed transactions and cross-slot operations. Security considerations include network access control (e.g., firewalls, ACLs) and authentication mechanisms.