Configure Redis cache
3 minute read
For better performance and scalability, you can configure API Portal to cache APIs in a Redis cache. Using a Redis cache is recommended if you plan to expose hundreds of APIs, or you plan to connect API Portal to more than one API Manager.
Note
While Redis support only caching of the API catalog page, Elasticsearch also supports Applications page caching. Therefore, we recommend using Elasticsearch instead of Redis.Prerequisites
Before you configure API Portal to cache APIs in a Redis cache you must install at least one of the following Redis options:
- Install Redis server.
- Install Redis PHP extension on Red Hat 7 (RHEL 7) using RHSCL.
- Install Redis PHP extension on CentOS 7 or RHEL 8 using EPEL/Remi.
Install Redis server
To install Redis server, download a Redis 5 or 6 server from Redis.io.
Install Redis PHP extension on Red Hat 7 (RHEL 7) using RHSCL
Follow these steps to install a Redis PHP extension on RHEL 7:
-
Enable
rhel-server-rhscl-7-rpms
andrhel-7-server-optional-rpms
repositories from RHSCL:sudo subscription-manager repos --enable rhel-server-rhscl-7-rpms sudo subscription-manager repos --enable rhel-7-server-optional-rpms sudo yum clean all
-
Install
rh-php73-php-devel
andrh-php73-php-pear
to enablepecl
(which manages external PHP modules) andphpize
(which will buildredis
PHP module)`:sudo yum install rh-php73-php-devel rh-php73-php-pear sudo ln -s $(which pecl) /usr/bin
-
Install and enable
redis
PHP module:sudo pecl install redis echo "extension=redis.so" | sudo tee -a /etc/opt/rh/rh-php73/php.d/30-redis.ini
-
Verify
redis
PHP module was successfully enabled:php -m | grep redis
-
Restart Apache:
sudo systemctl restart httpd24-httpd
-
(Optional) Remove
rh-php73-php-devel
andrh-php73-php-pear
:sudo yum remove rh-php73-php-devel rh-php73-php-pear
Install Redis PHP extension on CentOS 7 or RHEL 8 using EPEL/Remi
Follow these steps to install a Redis PHP extension on CentOS 7 or RHEL 8:
-
Install
redis5
PHP module:sudo yum install php-pecl-redis5
-
Verify
redis
PHP module is enabled:php -m | grep redis
-
Restart Apache:
sudo systemctl restart httpd
Enable Redis in API Portal
After you have successfully installed Redis, you must enable it in JAI:
- In the Joomla! Administrator Interface (JAI), click System > Global Configuration.
- Click System tab.
- On the Cache section, set System Cache to ON-Conservative caching and set Cache Handler to Redis.
- Review and update the other settings if necessary.
- Click Save.
Additional cache settings in API Portal
To change how long data is preserved in the cache:
- In the JAI, click Components > API Portal > Additional Settings.
- In Cache Timeout, enter how long (in seconds) APIs are preserved in the cache.
- Click Save.
Use the Purge cache button to clear the cache at any time.
Verify Redis installation
To verify that Redis is being used by API Portal, refresh the API Catalog page and enter the following command:
redis-cli keys *_apicatalog
Further Redis configuration
You have learned how to install a basic Redis server, with no authentication or replication. For more advanced configuration, see Redis documentation.