0
0
Redisquery~5 mins

Maxmemory setting in Redis

Choose your learning style9 modes available
Introduction

The maxmemory setting limits how much memory Redis can use. This helps keep your server stable and prevents Redis from using too much memory.

You want to make sure Redis does not use more memory than your server can handle.
You run Redis on a shared server and need to avoid affecting other applications.
You want Redis to automatically remove old data when memory is full.
You want to control costs by limiting memory usage on cloud servers.
Syntax
Redis
maxmemory <bytes>

maxmemory is set in bytes, but you can use suffixes like k, mb, gb for kilobytes, megabytes, and gigabytes.

You set this in the Redis configuration file (redis.conf) or at runtime with the CONFIG SET command.

Examples
Limits Redis memory usage to 100 megabytes.
Redis
maxmemory 100mb
Sets maxmemory to 512 megabytes (512 * 1024 * 1024 bytes) at runtime.
Redis
CONFIG SET maxmemory 536870912
Sample Program

This example sets the maxmemory to 100 megabytes (100 * 1024 * 1024 = 104857600 bytes) and then retrieves the current maxmemory setting.

Redis
CONFIG SET maxmemory 104857600
CONFIG GET maxmemory
OutputSuccess
Important Notes

If maxmemory is not set, Redis can use all available memory on the server.

Setting maxmemory alone does not control what Redis does when memory is full. You also need to set maxmemory-policy to decide how Redis evicts data.

Summary

maxmemory limits Redis memory use to keep your server stable.

You can set it in bytes or with size suffixes like mb or gb.

Use CONFIG SET to change it while Redis is running.