HiBlog Linux and Windows Server

What Is Redis? Uses of Redis for Caching, Sessions and Queues

  • Ali GhanimatiAuthor
  • Last updated
  • 6 minutesReading time
  • 716Views
  • Ali Ghanimati
  • Last updated:
  • 6 min read
  • 716 views
What Is Redis? Uses of Redis for Caching, Sessions and Queues

Your online shop slows down on sale night. Every visitor who opens a product page sends several queries to the database, and the database, which reads from disk, starts gasping under the load. Your developer suggests “let’s add Redis”, and you’re left wondering what on earth that is!

In this article we explain what Redis is, how it works, where its data lives, what it’s used for and how to use it on cPanel hosting or a virtual server.

Short answer: Redis is a key-value database that keeps its data in RAM, which is why it usually answers in under a millisecond. Its most common use is as a cache in front of the main database; storing user sessions, job queues and counters are common uses too. Redis doesn’t replace MySQL; it works next to it so the database has to touch the disk less often.

What is Redis?

Redis, short for Remote Dictionary Server, is a database that Salvatore Sanfilippo created in 2009. In Redis every piece of data is stored under a key, such as product:125 or session:abc, and because everything is in RAM, reads and writes are much faster than in databases that work on disk.

A key’s value isn’t just plain text. Redis has ready-made data structures: String for text and numbers, Hash for objects like a user profile, List for queues, Set for collections without duplicates, Sorted Set for rankings and Stream for event logs. By default, the Redis service listens for applications on port 6379.

How does Redis work?

The most common pattern is a cache next to the database (cache-aside):

  1. The application, your site for example, asks Redis for the data first.
  2. If the data is there (a cache hit), it gets it in the blink of an eye.
  3. If it isn’t (a cache miss), the application itself reads it from the main database, shows it to the user and puts a copy with an expiry time in Redis so the next request is answered from RAM.

Note that Redis doesn’t go to the main database by itself; the application does that. WordPress caching plugins automate exactly this round trip for you.

Does Redis lose its data on restart?

Not necessarily. Redis has two ways to keep data on disk:

  • RDB: takes a snapshot of all the data every so often. It’s light, but changes made after the last snapshot can be lost.
  • AOF: writes every write command to a file so it can be replayed after a restart. Less data is lost, but the file is bigger.

For a cache, losing data doesn’t matter, because it’s rebuilt from the database. But if you keep data only in Redis, such as an order queue, turn persistence on. Another important setting is maxmemory: when RAM fills up, Redis uses a policy such as allkeys-lru to evict the least-used keys so the server doesn’t fall over.

What is Redis used for?

The most common use of Redis is caching, but it can do a lot more:

  • Query and page caching: keeps the results of heavy queries or whole pages so the database does less work. In WordPress this is called an object cache.
  • User sessions: keeps shopping carts and login state fast, even when the site runs on several servers.
  • Job queues: queues tasks like sending emails, building invoices or processing images so users don’t have to wait; frameworks like Laravel use Redis for queues.
  • Counters and rate limiting: counts page views or login attempts with the INCR command; great for stopping password-guessing attacks.
  • Leaderboards: a Sorted Set keeps player rankings or best-selling products in order in real time.
  • Real-time messaging: with Pub/Sub, one part of an application sends a message and other parts receive it instantly; good for notifications and chat.

Redis pros and limits

The biggest advantage of Redis is speed, followed by its ready-made data structures and how simple it is to use. But know its limits too:

  • The amount of data is limited by RAM, and RAM costs more than disk.
  • Redis doesn’t replace a relational database and has no complex queries or JOINs.
  • Without persistence settings, data is gone after a restart.
  • Redis must never be open to the internet without a password and a firewall; unprotected Redis servers are a constant target for attack bots.

A quick test with redis-cli

If Redis is installed on your server, try these commands with its command-line tool:

redis-cli ping
redis-cli SET greeting "salam" EX 60
redis-cli GET greeting
redis-cli TTL greeting

The answer to ping should be PONG. The second command creates the key greeting with a 60-second lifetime, GET returns its value and TTL tells you how many seconds it has left; a minute later the key deletes itself.

Redis on hosting or on a virtual server?

On a virtual server you install and configure Redis yourself and have full control; we show how in How to Install Redis on Ubuntu. If your site is on cPanel hosting, see How to Connect PHP and WordPress to Redis in cPanel.

FAQ

Is Redis free?

Yes. Since version 8, released in 2025, Redis is also available under the open-source AGPLv3 license, and installing it on your own server costs nothing. Valkey is an open-source fork of Redis that understands the same commands.

What’s the difference between Redis and Memcached?

Both are in-memory caches, but Memcached only has simple keys and values and doesn’t keep data on disk. Redis has more data structures, persistence on disk and replication, which is why it has found many more uses.

Will Redis always make my site faster?

If your site is slow because of repeated database queries, yes, and noticeably! But if the problem is heavy images or slow code, Redis won’t work miracles; measure your speed first, then go through How to Speed Up a Website with Hosting Settings.

Redis on a HiData virtual server

On HiData’s virtual servers you have root access, so you can install Redis with a few commands and pick a plan with as much RAM as you need; your virtual server’s RAM is yours alone and isn’t shared with anyone. Wherever you get stuck, our 24/7 ticket support has your back!

Share Post

hidata.org/en/blog/what-is-redis-server-and-why-is-it-important/
In Social Media

Add Comment

Related Articles