@@ -29,7 +29,10 @@ needs. The supported caching backends are:
2929* `Redis <https://redis.io/open-source/ >`__ (4.0.0 and up required);
3030 `Valkey <https://valkey.io/ >`__ and `KeyDB <https://docs.keydb.dev/ >`__ are expected to work as Redis-compatible backends.
3131
32- .. note :: Automated/formal testing currently only occurs against Redis Open Source.
32+ .. note ::
33+ Automated/formal testing currently only occurs against Redis Open Source using the `redis ` PHP extension
34+ and against Valkey using the Nextcloud `keyvalue ` cache provider.
35+ KeyDB is expected to work as compatible backends as well, but are not formally tested.
3336
3437 For local and distributed caching, as well as transactional file locking.
3538
@@ -47,7 +50,7 @@ Recommendations based on type of deployment
4750-------------------------------------------
4851
4952You may use both a local and a distributed cache. Recommended caches are APCu
50- and Redis. After installing and enabling your chosen memcache (data cache),
53+ and Redis or Valkey . After installing and enabling your chosen memcache (data cache),
5154verify that it is active by running :ref: `label-phpinfo `.
5255
5356.. note :: See specific cache configuration options under the appropriate section further down.
@@ -142,8 +145,166 @@ increase the size. `APCu provides a script
142145otherwise the `serverinfo app <https://github.com/nextcloud/serverinfo >`_ in
143146Nextcloud can also show the APCu cache status.
144147
145- Redis
146- -----
148+ .. _keyvalue_cache_label :
149+
150+ Redis / Valkey using the Nextcloud ``KeyValueCache ``
151+ ----------------------------------------------------
152+
153+ .. note ::
154+ The KeyValueCache was added with Nextcloud 34.0.2.
155+
156+ The ``KeyValueCache `` cache is a brand-independent cache backend for key-value stores like
157+ `Valkey <https://valkey.io/ >`__ or `Redis <https://redis.io/open-source/ >`__. These are excellent
158+ modern memcaches to use for distributed caching, and as a key-value store for
159+ :doc: `Transactional File Locking <../configuration_files/files_locking_transactional >` because they
160+ guarantee that cached objects are available for as long as they are needed.
161+
162+ Unlike the ``phpredis `` backend described in the next section, the ``keyvalue `` cache does not require
163+ a PHP extension: it is built on the `predis <https://github.com/predis/predis >`__ library which is
164+ bundled with Nextcloud. You only need to install and run a Valkey or Redis compatible server and
165+ configure it in ``config.php ``. It is the successor of the phpredis backend, and the related
166+ ``memcache.kvstore `` option replaces the deprecated ``redis `` and ``redis.cluster `` options.
167+
168+ On Debian/Ubuntu/Mint, install ``valkey-server `` or ``redis-server ``. On CentOS and Fedora,
169+ install ``valkey `` or ``redis ``. Depending on your distribution the server might not start
170+ automatically, so you may need to use your service manager to start the server, and to launch it
171+ at boot as a daemon.
172+
173+ You can verify that the daemon is running with ``ps ax ``::
174+
175+ ps ax | grep valkey
176+ 22203 ? Ssl 0:00 /usr/bin/valkey-server 127.0.0.1:6379
177+
178+ Add the appropriate entries to your ``config.php ``, and refresh your Nextcloud admin page.
179+
180+ .. _keyvalue_cache_configuration :
181+
182+ KeyValueCache configuration in Nextcloud (config.php)
183+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
184+
185+ For best performance, use the ``KeyValueCache `` for file locking by adding this::
186+
187+ 'memcache.locking' => '\OC\Memcache\KeyValueCache',
188+
189+ Additionally, you should use it for the distributed server cache::
190+
191+ 'memcache.distributed' => '\OC\Memcache\KeyValueCache',
192+
193+ Furthermore, you could use it for the local cache like so, but it's not recommended (see
194+ warning below)::
195+
196+ 'memcache.local' => '\OC\Memcache\KeyValueCache',
197+
198+ .. warning :: Using a key-value store server for local cache on a multi-server setup can cause
199+ issues. Also, even on a single-server setup, APCu (see section above) should be faster.
200+
201+ When using the ``keyvalue `` cache for any of the above cache settings, you also need to specify
202+ the ``memcache.kvstore `` configuration in ``config.php ``. Three topologies are supported: a single
203+ server (``server ``), a Sentinel managed replication set (``sentinel ``), and a server cluster
204+ (``seeds ``). Configure exactly one of them.
205+
206+ The following options are available when using a single server (all but ``server `` are
207+ optional)::
208+
209+ 'memcache.locking' => '\OC\Memcache\KeyValueCache',
210+ 'memcache.distributed' => '\OC\Memcache\KeyValueCache',
211+ 'memcache_customprefix' => 'mynextcloudprefix',
212+ 'memcache.kvstore' => [
213+ 'server' => [
214+ 'host' => 'cache-host.example.com',
215+ 'port' => 6379,
216+ // Protocol used to connect. One of 'tcp', 'tls' or 'unix'.
217+ // When omitted it is derived from the host (a leading '/' means 'unix').
218+ 'protocol' => 'tcp',
219+ ],
220+ 'user' => 'nextcloud', // only sent when the server uses ACLs
221+ 'password' => 'password',
222+ 'dbindex' => 0,
223+ 'timeout' => 1.5,
224+ 'read_timeout' => 1.5,
225+ 'persistent' => false, // keep the connection open across requests
226+ ],
227+
228+ The same optional parameters are available for the Sentinel and cluster topologies below and are
229+ applied to every node.
230+
231+ For a Sentinel managed replication setup, provide the name of the monitored service and one seed
232+ entry per Sentinel node (each seed uses the same format as the ``server `` entry above)::
233+
234+ 'memcache.kvstore' => [
235+ 'sentinel' => [
236+ 'service' => 'mymaster',
237+ 'seeds' => [
238+ ['host' => 'sentinel1.example.com', 'port' => 26379],
239+ ['host' => 'sentinel2.example.com', 'port' => 26379],
240+ ['host' => 'sentinel3.example.com', 'port' => 26379],
241+ ],
242+ ],
243+ ],
244+
245+ For a cluster, provide some or all of the cluster nodes to bootstrap discovery::
246+
247+ 'memcache.kvstore' => [
248+ 'seeds' => [
249+ ['host' => 'cache-cluster.example.com', 'port' => 7000],
250+ ['host' => 'cache-cluster.example.com', 'port' => 7001],
251+ ],
252+ ],
253+
254+ .. note :: Selecting a numbered database with ``dbindex`` is only supported for single servers and
255+ Sentinel setups; clusters always use database 0, the support for numbered databases added with Valkey v9 is pending `upstream <https://github.com/predis/predis/issues/1696 >`_.
256+
257+ Connecting over TLS
258+ ^^^^^^^^^^^^^^^^^^^
259+
260+ To connect via TCP over TLS, set the ``protocol `` of the server (or of each seed) to ``tls `` and
261+ provide the SSL context (`SSL context options
262+ <https://www.php.net/manual/en/context.ssl.php> `_)::
263+
264+ 'memcache.kvstore' => [
265+ 'server' => [
266+ 'host' => 'cache-host.example.com',
267+ 'port' => 6379,
268+ 'protocol' => 'tls',
269+ ],
270+ 'ssl_context' => [
271+ 'local_cert' => '/certs/cache.crt',
272+ 'local_pk' => '/certs/cache.key',
273+ 'cafile' => '/certs/ca.crt',
274+ ],
275+ ],
276+
277+ Connecting over UNIX socket
278+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
279+
280+ If you want to connect to a server configured to listen on a Unix socket (which is recommended if
281+ the server is running on the same system as Nextcloud), pass the socket path as the host. A
282+ leading slash in the host is automatically detected as a Unix socket, so no ``protocol `` or
283+ ``port `` is needed::
284+
285+ 'memcache.kvstore' => [
286+ 'server' => [
287+ 'host' => '/run/valkey/valkey.sock',
288+ ],
289+ ],
290+
291+ Update the server configuration (for example ``/etc/valkey/valkey.conf ``) accordingly: uncomment
292+ the Unix socket options and ensure the socket path matches your Nextcloud configuration.
293+
294+ Be sure to set the right permissions on the socket so that your web server can read and write to
295+ it. For this you typically have to add the web server user to the ``valkey `` (or ``redis ``)
296+ group::
297+
298+ usermod -a -G valkey www-data
299+
300+ And modify the ``unixsocketperm `` setting of the server configuration accordingly::
301+
302+ unixsocketperm 770
303+
304+ You might need to restart your web server and the cache server for the changes to take effect.
305+
306+ Redis using the phpredis PHP extension
307+ --------------------------------------
147308
148309Redis is an excellent modern memcache to use for distributed caching, and
149310as a key-value store for :doc: `Transactional File Locking
0 commit comments