@@ -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,170 @@ 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 ``KeyValueCache `` 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 ``.
166+
167+ .. note ::
168+ When the cache server is not located on the same machine the performance
169+ may be impacted due to network overhead compared to the ``php-redis `` based backend.
170+ In those cases it may be preferable to use the ``php-redis `` backend instead.
171+
172+ On Debian/Ubuntu/Mint, install ``valkey-server `` or ``redis-server ``. On CentOS and Fedora,
173+ install ``valkey `` or ``redis ``. Depending on your distribution the server might not start
174+ automatically, so you may need to use your service manager to start the server, and to launch it
175+ at boot as a daemon.
176+
177+ You can verify that the daemon is running with ``ps ax ``::
178+
179+ ps ax | grep valkey
180+ 22203 ? Ssl 0:00 /usr/bin/valkey-server 127.0.0.1:6379
181+
182+ Add the appropriate entries to your ``config.php ``, and refresh your Nextcloud admin page.
183+
184+ .. _keyvalue_cache_configuration :
185+
186+ KeyValueCache configuration in Nextcloud (config.php)
187+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
188+
189+ For best performance, use the ``KeyValueCache `` for file locking by adding this::
190+
191+ 'memcache.locking' => '\OC\Memcache\KeyValueCache',
192+
193+ Additionally, you should use it for the distributed server cache::
194+
195+ 'memcache.distributed' => '\OC\Memcache\KeyValueCache',
196+
197+ Furthermore, you could use it for the local cache like so, but it's not recommended (see
198+ warning below)::
199+
200+ 'memcache.local' => '\OC\Memcache\KeyValueCache',
201+
202+ .. warning :: Using a key-value store server for local cache on a multi-server setup can cause
203+ issues. Also, even on a single-server setup, APCu (see section above) should be faster.
204+
205+ When using the ``keyvalue `` cache for any of the above cache settings, you also need to specify
206+ the ``memcache.kvstore `` configuration in ``config.php ``. Three topologies are supported: a single
207+ server (``server ``), a Sentinel managed replication set (``sentinel ``), and a server cluster
208+ (``seeds ``). Configure exactly one of them.
209+
210+ The following options are available when using a single server (all but ``server `` are
211+ optional)::
212+
213+ 'memcache.locking' => '\OC\Memcache\KeyValueCache',
214+ 'memcache.distributed' => '\OC\Memcache\KeyValueCache',
215+ 'memcache_customprefix' => 'mynextcloudprefix',
216+ 'memcache.kvstore' => [
217+ 'server' => [
218+ 'host' => 'cache-host.example.com',
219+ 'port' => 6379,
220+ // Protocol used to connect. One of 'tcp', 'tls' or 'unix'.
221+ // When omitted it is derived from the host (a leading '/' means 'unix').
222+ 'protocol' => 'tcp',
223+ ],
224+ 'user' => 'nextcloud', // only sent when the server uses ACLs
225+ 'password' => 'password',
226+ 'dbindex' => 0,
227+ 'timeout' => 1.5,
228+ 'read_timeout' => 1.5,
229+ 'persistent' => false, // keep the connection open across requests
230+ ],
231+
232+ The same optional parameters are available for the Sentinel and cluster topologies below and are
233+ applied to every node.
234+
235+ For a Sentinel managed replication setup, provide the name of the monitored service and one seed
236+ entry per Sentinel node (each seed uses the same format as the ``server `` entry above)::
237+
238+ 'memcache.kvstore' => [
239+ 'sentinel' => [
240+ 'service' => 'mymaster',
241+ 'seeds' => [
242+ ['host' => 'sentinel1.example.com', 'port' => 26379],
243+ ['host' => 'sentinel2.example.com', 'port' => 26379],
244+ ['host' => 'sentinel3.example.com', 'port' => 26379],
245+ ],
246+ ],
247+ ],
248+
249+ For a cluster, provide some or all of the cluster nodes to bootstrap discovery::
250+
251+ 'memcache.kvstore' => [
252+ 'seeds' => [
253+ ['host' => 'cache-cluster.example.com', 'port' => 7000],
254+ ['host' => 'cache-cluster.example.com', 'port' => 7001],
255+ ],
256+ ],
257+
258+ .. note :: Selecting a numbered database with ``dbindex`` is only supported for single servers and
259+ 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 >`_.
260+
261+ Connecting over TLS
262+ ^^^^^^^^^^^^^^^^^^^
263+
264+ To connect via TCP over TLS, set the ``protocol `` of the server (or of each seed) to ``tls `` and
265+ provide the SSL context (`SSL context options
266+ <https://www.php.net/manual/en/context.ssl.php> `_)::
267+
268+ 'memcache.kvstore' => [
269+ 'server' => [
270+ 'host' => 'cache-host.example.com',
271+ 'port' => 6379,
272+ 'protocol' => 'tls',
273+ ],
274+ 'ssl_context' => [
275+ 'local_cert' => '/certs/cache.crt',
276+ 'local_pk' => '/certs/cache.key',
277+ 'cafile' => '/certs/ca.crt',
278+ ],
279+ ],
280+
281+ Connecting over UNIX socket
282+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
283+
284+ If you want to connect to a server configured to listen on a Unix socket (which is recommended if
285+ the server is running on the same system as Nextcloud), pass the socket path as the host. A
286+ leading slash in the host is automatically detected as a Unix socket, so no ``protocol `` or
287+ ``port `` is needed::
288+
289+ 'memcache.kvstore' => [
290+ 'server' => [
291+ 'host' => '/run/valkey/valkey.sock',
292+ ],
293+ ],
294+
295+ Update the server configuration (for example ``/etc/valkey/valkey.conf ``) accordingly: uncomment
296+ the Unix socket options and ensure the socket path matches your Nextcloud configuration.
297+
298+ Be sure to set the right permissions on the socket so that your web server can read and write to
299+ it. For this you typically have to add the web server user to the ``valkey `` (or ``redis ``)
300+ group::
301+
302+ usermod -a -G valkey www-data
303+
304+ And modify the ``unixsocketperm `` setting of the server configuration accordingly::
305+
306+ unixsocketperm 770
307+
308+ You might need to restart your web server and the cache server for the changes to take effect.
309+
310+ Redis using the phpredis PHP extension
311+ --------------------------------------
147312
148313Redis is an excellent modern memcache to use for distributed caching, and
149314as a key-value store for :doc: `Transactional File Locking
0 commit comments