Updated guide

Redis complete tutorial: Redis 8, installation, CLI and real examples

A practical Redis guide to understand cache, sessions and rate limiting, updated with Redis 8, current installation commands, licensing context and Valkey compatibility.

Redis 8ValkeyInstallationCLICachingSearch
6379default port used by Redis
PINGfastest command to verify the server is responding
TTLbasic primitive to build cache expiration

What matters before you install Redis

Content updated for Redis 8, the current installation docs, Redis Open Source licensing and the Valkey compatibility context.

Model

Redis is not used like a classic relational database

The key idea is simple: operate on keys, keep values compact and use expiration intentionally for cache, sessions and fast counters.

Install

The current official installation path changed

Redis now recommends Docker for the fastest start, official APT/RPM packages on Linux, the Redis Homebrew tap on macOS and Docker on Windows.

2026 context

Redis 8, licensing and Valkey matter before production

Redis 8 includes AGPLv3 as part of its tri-license and integrates Redis Stack-era features, while Valkey remains an important Redis OSS 7.2 compatible option.

Practice

The fastest way to learn Redis is with redis-cli

A few commands are enough to understand strings, hashes, lists, counters, expiration and common inspection patterns.

Key idea

Redis is strongest when you need very fast access by key, controlled expiration and simple data structures

It is common to use Redis for cache, sessions, rate limiting, queues, ephemeral state and counters. It can persist data, but in many projects its first practical value is reducing latency and load in front of slower systems.

The 2026 context adds two decisions before production: Redis 8 now includes technologies that used to be associated with Redis Stack, such as JSON, search/query, time series and probabilistic structures, and the Redis/Valkey split means you should check licensing, managed-service compatibility and client support before choosing a platform.

What Redis is

Redis is an in-memory data store oriented around keys. Instead of thinking in joins, you think in direct access to keys and in native structures like strings, hashes, lists, sets and sorted sets.

When it fits well

Caching database queries, storing sessions, invalidating tokens, building request counters, keeping temporary shopping cart state or protecting APIs with rate limiting.

Where to be careful

Redis is not the natural replacement for a relational model full of complex joins. If the value of the system depends on relational integrity and long historical analytics, Redis is usually complementary, not the whole database.

Redis 8 and Valkey

Redis 8 is available under a tri-license that includes AGPLv3, while Valkey keeps compatibility with Redis OSS 7.2 and earlier. For much application code the command model feels familiar, but production choices now include legal, hosting and compatibility checks.

macOS

Install with Homebrew

brew tap redis/redis
brew install --cask redis
redis-server $(brew --prefix)/etc/redis.conf
redis-cli ping

The current Redis docs use the official Homebrew tap and cask. After starting the server, `redis-cli ping` should answer `PONG`.

Linux

Use the official Redis packages

sudo apt-get install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis
redis-cli ping

On Debian or Ubuntu, prefer the official Redis repository when you want current Redis Open Source packages instead of older distribution builds.

Windows

Run Redis with Docker

docker run -d --name redis -p 6379:6379 redis
redis-cli -h localhost -p 6379 ping

The current Redis docs present Docker as the Windows path. Memurai appears as a preview compatibility route for Redis Open Source 8.2 RC1, so Docker is the safer general recommendation for development.

Source code

Compile Redis manually

wget https://download.redis.io/redis-stable.tar.gz
tar -xzvf redis-stable.tar.gz
cd redis-stable
make
sudo make install

This route is useful when you want more control, need to test source builds or work on environments where packages are not enough.

Start here

Basic commands with redis-cli

redis-cli ping
SET site:name "1938"
GET site:name
DEL site:name

This is the minimal loop: verify the server, write a key, read it and delete it.

Caching

Store data with expiration

SET page:home "<html>...</html>" EX 60
TTL page:home
GET page:home

This pattern is one of the main reasons to add Redis to a web architecture: keep fast data for a short time and let it expire automatically.

Counters

Count requests or events

INCR stats:visits
INCRBY stats:api:requests 5
GET stats:visits

Counters are trivial in Redis and are frequently used for analytics, quotas and lightweight monitoring.

Hashes

Represent a small user object

HSET user:42 name "Ana" role "admin" plan "pro"
HGET user:42 name
HGETALL user:42

Hashes are useful when several fields belong to the same key and you do not need a full relational record with joins.

Lists

Simple queue example

LPUSH queue:emails "send-welcome:42"
LPUSH queue:emails "send-reset:18"
RPOP queue:emails

A list is enough for many simple queue scenarios, especially in internal tools or small background jobs.

Practical pattern

Basic rate limiting by IP

MULTI
INCR rate:ip:203.0.113.10
EXPIRE rate:ip:203.0.113.10 60
EXEC

The idea is straightforward: count requests per IP and expire the key after one minute. If the value crosses your threshold, reject the request.

Verification and first checks

After installation, the first useful check is still `redis-cli ping`. If the answer is not `PONG`, check whether the service is started, whether the port is open and whether your local host and port match the expected values.

Security basics

Redis official docs warn against exposing an unhardened instance to the internet. In practice, keep it behind a firewall, bind only to the interfaces you need and configure authentication if clients must connect remotely.

Redis 8, search and vector features

Redis can now cover more than a simple cache: Redis Open Source documentation includes Redis Query Engine, JSON, vector search and AI/search use cases. That is useful for semantic search, metadata filtering and fast retrieval, but it does not remove the need to model memory limits, durability and the role of your primary database.

Licensing and managed services

Redis 8 and later are offered under RSALv2, SSPLv1 or AGPLv3; Redis 7.2 and earlier remain BSD-3-Clause. Valkey is relevant when you need Redis OSS 7.2 compatibility under a different project and ecosystem. For company projects, verify this with legal and with the managed provider you plan to use.

Persistence decision

Before using Redis as more than a cache, decide whether losing recent writes is acceptable. RDB snapshots, AOF and managed Redis services have different trade-offs between speed, durability and operational complexity.

Eviction and memory

Redis is fast because memory is the main resource. Configure maxmemory and an eviction policy intentionally; otherwise the first serious traffic spike can become a production incident instead of a performance improvement.