Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahm750's avatar

How many items can Redis cache (or the max storage)?

I have enabled caching of database queries with Laravel using Redis. But how can I find out the maximum storage of Redis, e.g how many items it can cache?

0 likes
8 replies
sesser's avatar
sesser
Best Answer
Level 1

In general, if you're using Redis as a cache (i.e. memory based cache or LRU), you're limited by the size of the cache and not how many items are in the cache. Setting the maxmemory and an eviction policy will control how much information is cached. Read more here: http://redis.io/topics/lru-cache

That said, I'm not sure how Laravel handles caching queries. If it's setting an EXPIRE time, then the items will get dropped based on the time regardless of the maximum amount of memory allowed (except in the case where the maxmemory is greater than 0 and the limit has been reached).

You can see if your server has a max memory by looking in the configuration file for Redis, or by connecting to the server with redis-cli and issuing the INFO memory command:

127.0.0.1:6379> INFO memory
# Memory
used_memory:1008192
used_memory_human:984.56K
used_memory_rss:1183744
used_memory_rss_human:1.13M
used_memory_peak:1010256
used_memory_peak_human:986.58K
total_system_memory:17179869184
total_system_memory_human:16.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.17
mem_allocator:libc
ahm750's avatar

@sesser When I run the 'INFO memory' command, it doesnt mention anything about maxmemory. Also, how can I view the size of the cache AKA the memory it is occupying?

# Memory
used_memory:642328
used_memory_human:627.27K
used_memory_rss:3719168
used_memory_peak:1114904
used_memory_peak_human:1.06M
used_memory_lua:36864
mem_fragmentation_ratio:5.79
mem_allocator:jemalloc-3.6.0
sesser's avatar

@ahm750 Ah, must have been added in server version >= 3.x. I have access to a 2.8 server and it reports the same. You'll have to gain access to the redis.conf on your system... grep maxmemory /etc/redis.conf (or wherever it may be). You can find where the conf file is using INFO server

ahm750's avatar

@sesser Checked the file. maxmemory has been commented out. So I guess it means that it will use as much memory as it can?

Also the maxmemory policy hasn't been set. I think that volatile-lru will be good (remove the key with an expire set using an LRU algorithm)?

sesser's avatar

Yes. This is the default behavior in terms of maxmemory. I haven't tested the different eviction policies and I would think it depends on your use cases, but for queries, it would make sense to evict the queries that are less used first (rather than a FIFO pattern).

ahm750's avatar

@sesser Ok got it. Thanks :) So used_memory indicates the total memory that Redis is consuming including the caches?

Please or to participate in this conversation.