I recently added Redis as a cache for my Nextcloud instance to increase it's performance. This has mainly reduced MySQL database queries and cleared up some errors I was getting from hitting MySQL tables during locks. Although this post is written for Unraid users it can easily be applied for other setups as well.
This post assumes you already have Nextcloud installed using the container from Linuxserver. Other containers will work fine as long as they have the required PHP Redis libraries shipping with them. The Linuxserver container works out of the box and is available in the Unraid Community Applications so I recommend it if you don't know which one to use.
If you have never heard of Nextcloud it is basically a self-hosted Dropbox. I use it for backing up files from all my various computers and devices to my Unraid server for redundant storage (and have my Unraid server backup to CrashPlan for even more redundancy). I recommend checking it out: https://nextcloud.com/
Installing Redis in Unraid is super easy if you have Community Applications installed. It's as easy as searching Redis under apps and clicking install. Make sure to install the one provided from the official Redis user. Also note which port you use since you will need to reference this from the Nextcloud config file.
Configuring Nextcloud to use Redis
Getting Nextcloud to use your new Redis instance is pretty easy. All we need to do is modify the
config.php file for Nextcloud to point to our Redis instance. To do this open your
config.php file (location is
/mnt/user/appdata/nextcloud/www/nextcloud/config/config.php if using default appdata path in Unraid with the Linuxserver Nextcloud container). We want to add these lines into the
'memcache.local' => '\\OC\\Memcache\\Redis', 'memcache.locking' => '\\OC\\Memcache\\Redis', 'redis' => array ( 'host' => '192.168.1.10', 'port' => 6379, ),
Make sure to change the
port to point to match your Redis instance (this information can be found on the docker list page within Unraid).
Here is an example of what the file looks like after adding these lines (since it needs to be added within the array so it can't just be added to the start/end of the file):
<?php $CONFIG = array ( 'memcache.local' => '\\OC\\Memcache\\Redis', 'memcache.locking' => '\\OC\\Memcache\\Redis', 'redis' => array ( 'host' => '192.168.1.10', 'port' => 6379, ), ... );
Now restart the Nextcloud container and it will be using your Redis instance for cache! I recommend doing a last check to make sure you aren't getting any errors in any logs and double check that nothing broke inside Nextcloud. If you do end up having any issues feel free to comment below and I will help out the best I can.
If you have a lot of files syncing over a very fast connection you can actually start hitting MySQL database errors with table locks or other issues (you will see these errors within the Nextcloud client program when syncs are happening or from the server log). Implementing Redis for my Nextcloud instance completely resolved these errors for me and they no longer occur. Syncs are also faster now since implementing this. If you have the memory to spare (and Redis doesn't really need a lot) then I highly recommend setting this up.
I hope others find this handy. I created this post because a user requested that I create one about this topic specific for Unraid. If you have any ideas for topics you want me to cover feel free to leave a comment below.