Redis is a popular structured key-value service, supported by Upsun.
Itβs frequently used for caching.
Install PhpRedis
The PhpRedis extension is available on Upsunβs PHP container images.
The extension has been known to break its API between versions when removing deprecated functionality.
The version available on each application image is the latest available at the time that PHP version was built,
which if your app is sensitive to PhpRedis versions may not be ideal.
It may happen that the version of the PhpRedis extension available for your PHP version
isnβt compatible with your app and upgrading your app isnβt feasible.
If so, use the following script as an alternative to download and compile a precise version of the extension.
Do not use this approach unless you really need to.
Using the provided PhpRedis extension is preferred in the majority of cases.
To ease the installation of a customer version of PhpRedis, use a PhpRedis install script.
Invoke this script from your build hook, specifying a version.
Any tagged version of the library is acceptable:
Install Relay
Relay is a Redis client
similar to PhpRedis and
Predis.
Itβs intended to be a drop-in replacement for those libraries.
That PHP extension is also a shared in-memory cache like APCu. All retrieved keys are held in the PHP master processβ memory, which is shared across all FPM workers.
That means if the FPM Worker #1 fetches the users:count key from Redis,
all other FPM workers instantaneously retrieve that key from Relay without having to communicate with Redis.
To ease the installation of a customer version of Relay, use the Relay install script.
Invoke this script from your build hook, specifying a version.
Any tagged version of the library is acceptable:
Change extension or version
To change the Redis extension or the version you are using, update the build hook and clear the build cache: upsun project:clear-build-cache.
The new version is not be used until you clear the build cache.
Thereβs no need to declare the extension in the runtime block.
Thatβs only for pre-built extensions.
What these scripts do
- Download the Relay/PhpRedis source code.
- Check out the version specified in the build hook.
- Compile the extension.
- Copy the resulting
relay.so/redis.so file to your app root.
- Add a line to the
php.ini file in your app root to enable the extension, creating the file if necessary.
If the script doesnβt find a $PLATFORM_CACHE_DIR directory defined, it exits silently.
So if you run the build hook locally, it has no effect.