Redis configuration
P4 Code Review uses Redis or Valkey to manage its caches.
By default, P4 Code Review uses the Redis server included with the P4 Code Review tarball installation. Cache data is used to improve the performance of common searches and reduce the load on the P4 Server.
Valkey is not bundled with P4 Code Review. If you want to use Valkey, see Valkey support.
You can also configure P4 Code Review to use your own Redis server instead of the bundled Redis server. For details, see Use your own Redis server.
This section describes how to configure the bundled Redis service. If you are using the bundled Redis server, do not change the default values unless directed to do so.
On this page:
Redis binaries
P4 Code Review includes the following Redis binaries in the following location:
-
SWARM_ROOT/p4-bin/bin.linux26x86_64/
These binaries are:
-
redis-server-swarm -
redis-cli-swarm
Configure the Redis server
Configure the Redis cache database in:
/opt/perforce/etc/redis-server.conf
Default configuration:
bind 127.0.0.1
port 7379
supervised auto
save ""
dir /opt/perforce/swarm/redis
Default settings
| Setting | Description |
|---|---|
|
|
Redis server IP address (loopback interface). |
|
|
Redis server port number. |
|
|
Automatically detects systemd or upstart and signals when the service is ready. |
|
|
Disables background saves. This is the recommended setting. |
|
|
Directory where the Redis cache database is stored. |
The redis-server.conf file contains additional information about Redis configuration options.
For example, on systems with a large number of users, groups, and projects, startup time can be improved by persisting the memory cache. You can do this by disabling background saves and enabling append saves. For more information, see the comments in the redis-server.conf file.
Fine-tuning Redis
To fine-tune your Redis server settings, make your changes in the Laminas Redis adapter. For information about the Laminas Redis adapter, see the Laminas Redis Adapter documentation.
Configure Redis as a service
The Redis cache database must be running before P4 Code Review starts. We recommend configuring Redis as a service so that it starts automatically when the server boots.
The following example service:
-
Runs Redis as the perforce user.
-
Uses the configuration file
/opt/perforce/etc/redis-server.conf. -
Assumes the Redis binaries are installed in
/opt/perforce/swarm/p4-bin/bin.linux26x86_64/.
Create the following file in /etc/systemd/system/redis-server-swarm.service.
[Unit]
Description=Redis Server for Swarm
After=network.target
[Service]
ExecStart=/opt/perforce/swarm/p4-bin/bin.linux26x86_64/redis-server-swarm /opt/perforce/etc/redis-server.conf
ExecStop=/opt/perforce/swarm/p4-bin/bin.linux26x86_64/redis-cli-swarm shutdown
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=redis
User=perforce
Group=perforce
[Install]
WantedBy=multi-user.target
Configure the Redis connection
Create the SWARM_ROOT/data/config.php file if it does not already exist.
The redis block defines the connection details for the Redis server, including the password, namespace, host, and port.
<?php
// this block should be a peer of 'p4'
'redis' => array(
'options' => array(
'password' => null,
'namespace' => 'Swarm',
'server' => array(
'host' => 'localhost',
'port' => '7379',
),
),
'items_batch_size' => 100000,
'check_integrity' => '03:00',
'population_lock_timeout' => 300,
),
Redis configuration options
password
Specifies the Redis server password.
Default value:
'password' => null
Leave this at the default value when using the bundled P4 Code Review Redis server.
namespace
Specifies the prefix used for keys stored in the Redis cache.
Default value:
'namespace' => 'Swarm'
Leave this at the default value when using the bundled P4 Code Review Redis server.
If multiple P4 Code Review instances use the same Redis server, each instance must use a different namespace. This allows cache data for each instance to be identified separately.
The namespace is limited to 128 characters or fewer.
If one or more P4 Code Review instances connect to multiple P4 Servers, the namespace includes the server label and the limit is reduced to 127 characters or fewer. For details, see Multiple P4 Server instances.
host
Specifies the Redis server hostname.
Default value:
'host' => 'localhost'
Leave this at the default value when using the bundled P4 Code Review Redis server.
port
Specifies the Redis server port number.
Default value:
'port' => '7379'
P4 Code Review uses port 7379 by default to avoid conflicts with other Redis servers that might already be running on your network.
Leave this value unchanged when using the bundled Redis server.
The default port for a standard Redis installation is 6379.
items_batch_size
Specifies the maximum number of key/value pairs included in a single Redis mset operation.
Default value:
'items_batch_size' => 100000
If a set exceeds this value, P4 Code Review divides the operation into batches.
The default value was selected to balance performance and project data complexity. You should not normally need to change this setting. Contact Perforce Support before modifying it.
check_integrity
Specifies when P4 Code Review runs cache integrity checks.
Default value:
'check_integrity' => '03:00'
In some situations, Redis cache data can become out of sync with the P4 Server. For example:
-
Changes are made directly in the P4 Server while P4 Code Review is offline.
-
An error occurs during a cache update.
The integrity check verifies that cached data matches the P4 Server. If an out-of-sync cache is detected, P4 Code Review automatically updates the cache.
You can specify:
-
A time of day in 24-hour format (
HH:MM). -
A positive integer representing the number of seconds between checks.
-
0to disable integrity checks.
population_lock_timeout
Specifies the timeout, in seconds, for initial cache population.
Default value:
'population_lock_timeout' => 300
If you have a large P4 Code Review deployment and the initial cache population times out, increase this value.
Valkey support
P4 Code Review also supports Valkey as a cache backend.
Valkey is an open source fork of Redis and can be used as a drop-in replacement for P4 Code Review caching.
P4 Code Review does not bundle a Valkey server. If you want to use Valkey, you must install and manage your own Valkey server.
Configure Valkey using the existing redis block in SWARM_ROOT/data/config.php, just as you would when connecting to a user-managed Redis server.
No configuration key changes are required for Valkey support:
-
Continue using the existing
redisblock inconfig.php. -
Set the host and port values for your Valkey server.
-
Keep the existing namespace and cache settings unless you have a specific reason to change them.
Example Valkey configuration
<?php
// this block should be a peer of 'p4'
'redis' => array(
'options' => array(
'password' => null,
'namespace' => 'Swarm',
'server' => array(
'host' => 'your-valkey-host',
'port' => '6379',
),
),
'items_batch_size' => 100000,
'check_integrity' => '03:00',
'population_lock_timeout' => 300,
),
Use the same guidance described for a user-managed Redis server when configuring passwords, namespaces, and connection details.
Expected behavior
The P4 Code Review administration UI may continue to display Redis-related labels when Valkey is in use. This does not affect cache operation.
Next steps
After you have configured your cache server, configure Apache. To learn more, see Apache configuration.