Caching with Redis
If you find yourself in a situation with a huge site, small amount of memory, and static caching isn’t an option, using a Redis cache may be a great way to increase site performance.
What is Redis?
Redis is a NoSQL key/value store, much like our flat file system based on YAML, that is held in memory. This results in very fast I/O response times and lets you scale to much larger and handle heavier traffic. It’s a perfect fit for taking Statamic to the next-level.
If you’re not sure if you have Redis installed, you can run the following command from the command line.
If you don’t get an error and see something similar to this, you’ve got yourself some Redis.
If Redis isn’t already installed on your server, or you want to get it running locally for testing, here are a few articles that can help:
Enabling Statamic’s Redis Cache driver
.env file set the following:
That’s it. If you need to change the host, port, or database (not common), you have access to the following options as well, shown with their defaults.
REDIS_HOST=127.0.0.1 REDIS_PORT=6379 REDIS_DATABASE=0
How to confirm Redis is actually working
monitor command and visit a page of the site in your browser. If it’s working you’ll see a number of events trigger as Redis does its thing.
$ redis-cli monitor