Question: Is Redis in memory?

Answer

Yes, Redis is an in-memory data structure store. This means that all the data it manages is stored in RAM (Random Access Memory) and not on disk. This design decision allows Redis to provide extremely fast read and write performance, making it an ideal choice for use cases where low latency is crucial.

Redis also provides persistence options to ensure that data is not lost despite being stored in memory. These options include both snapshotting and journaling. Snapshotting takes a point-in-time snapshot of the entire dataset and writes it to disk, while journaling appends every write operation to a file on disk, allowing Redis to rebuild the dataset from the journal in the event of a system failure.

To demonstrate that Redis is an in-memory database, you can use the INFO command to obtain information about Redis, including its memory usage:

> redis-cli INFO memory
# Memory
used_memory:1009552
used_memory_human:985.95K
used_memory_rss:2850816
used_memory_rss_human:2.72M
used_memory_peak:1011520
used_memory_peak_human:987.50K
used_memory_peak_perc:99.81%
used_memory_overhead:984056
used_memory_startup:973312
used_memory_dataset:25496
used_memory_dataset_perc:10.75%
allocator_allocated:1051208
allocator_active:1146880
allocator_resident:4775936
total_system_memory:17027414016
total_system_memory_human:15.87G
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:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.09
allocator_frag_bytes:954672
allocator_rss_ratio:4.17
allocator_rss_bytes:3629056
rss_overhead_ratio:0.60
rss_overhead_bytes:-1925120
mem_fragmentation_ratio:2.83
mem_fragmentation_bytes:1846752
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:4817
mem_aof_buffer:0
mem_allocator:jemalloc-5.2.1
active_defrag_running:0
lazyfree_pending_objects:0

The output includes several memory-related fields, such as used_memory, which reports the amount of memory used by Redis's data structures in bytes. In the example above, Redis is using around 985KB of memory.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.