Skip to content
hostcomplex

What Is Redis?

Maarten Soetens 3 min read

How Redis Stores Data in Memory

What is Redis? It is an in-memory database that stores data as key-value pairs. A key is a unique name, such as user:1042:cart, and the value is the data attached to it. Because Redis keeps its data in the server’s RAM rather than on disk, reads and writes complete much faster than in a traditional disk-based database.

Redis belongs to the wider group of NoSQL databases, which avoid fixed table structures. Its values are not limited to plain text. A value can be a list, a hash (a set of field and value pairs), a set of unique items, a sorted set ordered by score, or a stream of events.

The trade-off is capacity. Everything Redis holds has to fit in memory, so it suits data that is small, read often or temporary, rather than a complete archive of a website’s content.

Can Redis Keep Data After a Restart?

Memory is cleared when a server stops, so Redis offers two ways to save data to disk. Snapshotting writes a copy of the whole dataset at set intervals. The append-only file (AOF) records each write as it happens, so a restart can replay the record and recover recent changes. Many setups use both.

Each option trades speed against safety. Snapshots are compact but can lose the changes made since the last save. Recording every write loses less data but creates more disk activity. Whether a loss matters depends on the data: a lost shopping cart is an annoyance, while a lost payment record is not acceptable, and Redis is seldom the right home for the latter.

A Common Example: Storing User Sessions

When a visitor logs in, a website creates a session that remembers who they are across page loads. A busy site may check thousands of sessions per minute. If each check queries a disk-based database, every page view adds load to it. Storing sessions in Redis keeps those lookups in memory, and a session can be set to expire automatically after a set time, so no cleanup job is needed.

Redis is also used for job queues, where slow tasks such as sending emails are handed to a background worker, and for rate limiting, which counts requests from one visitor over a short window.

Frequently asked questions

Is Redis a replacement for a traditional database?

Not usually. Redis works best alongside a relational or document database rather than instead of one. It is fast and flexible, but it depends on available memory, and its persistence options are weaker than those of a database designed for durable records. Many applications keep core records in MySQL or PostgreSQL and use Redis for sessions, queues and temporary data.

Does Redis lose data when it restarts?

It depends on configuration. With persistence turned off, a restart clears everything. With snapshots or an append-only file enabled, Redis reloads its data from disk on startup. Even then, the newest changes may be missing if the server stopped before they were saved, so Redis suits data that can be rebuilt or safely lost. Copies on other servers are covered in database replication.

  • Two-Factor Authentication

    Two factor authentication hosting adds a second check to control panel, domain and CMS logins. Learn which methods are strongest and why 2FA helps.

  • What Is an A Record?

    What is an A record? Learn how this DNS record maps a hostname to an IPv4 address, why domains use several A records and the root and www pattern.

  • Billing and Automation Platforms

    What is WHMCS? Learn how this commercial billing and automation platform helps hosts sell plans, collect payments and create accounts automatically.