Using redis
Shlink can take advantage of redis in multiple contexts.
- For caching purposes.
- To store shared locks.
- To publish real-time updates via Pub/Sub.
Caching purposes
Shlink can persist certain things in a faster storage for quick access.
By default, it uses APCu if available (when using a classic web server) or in-memory (when using Roadrunner as the runtimes), but it can be provided with some redis access configuration.
When doing so, Shlink will use redis as the cache persistence.
Shared locks
Note
Locks are used to make sure certain tasks are not run more than once in parallel. For example, geolocating visits.
If you plan to run multiple Shlink instances, it’s important to make sure the so-called “locks” are shared between all of them.
Redis is a good way to do so. If Shlink is provided with redis access configuration, it will use it to store shared locks.
Supported capabilities
Shlink supports multiple redis capabilities. They can be enabled by providing different connection URIs:
- Redis instance, when providing just one server (for example,
tcp://my_redis_server:6379
). - Redis cluster, when providing multiple servers (for example,
tcp://one_redis_server:6379,tcp://another_redis_server:6379
). - Redis sentinel, when providing multiple servers, together with a sentinel service name.
- Database selection (since Shlink 4.2.1), by providing the database index in the URI path (for example,
tcp://my_redis_server:6379/5
). - Credentials, that can be provided as part of the server URIs, either both username and password (
tcp://the_username:the_password@my_redis_server:6379
) or just password (tcp://:the_password@my_redis_server:6379
).Warning
Prior to Shlink 3.7.0, password-only URIs had the form
tcp://the_password@my_redis_server:6379
. Since that’s not a valid URI, it has been removed in Shlink 4.0.0
Providing configuration
As with any other configuration params, there are two main ways to provide redis options:
-
Environment variables, which allow you to enable the integration however you like.
-
The installation tool, which will, at some point, ask you if you want to integrate with redis, and request you to provide all the capabilities above if so.