Menu Close

    Using Redis Cache In Opencart

    Nowadays, caching has become a hot topic of discussion as everyone wants to maintain their website’s speed even on handling millions of users at a time. Opencart is using caching since its initial days like used file cache in version 1.5, then added APC (Alternative PHP Cache) and Memcache in version 2 and now in version 3 added Redis library.

    Redis Introduction

    Redis has its own advantages. According to its website, Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

    Redis is an in-memory data structure server. You can add any values to Redis cache like integers, string etc.

    How to use Redis with Opencart?

    Searching for an experienced
    Opencart Company ?
    Read More

    In order to use Redis with Opencart, you have to first install Redis to your server. Here is the Download Link.

    Then you have to install phpredis to your server.

    You can check Redis in phpinfo().

    Now, you have to make some changes to your opencart system. You have to edit system->config->default.php and change the value of $_[‘cache_type’].

    $_['cache_engine']         = 'redis';

    You also need to define a few constants. Either you can make changes in both config.php and admin->config.php or you can perform change either in system->startup.php or system->framework.php (before cache object in this case). You have to define following constants.

    define('CACHE_HOSTNAME', '');
    define('CACHE_PORT', '6379');
    define('CACHE_PREFIX', 'redis_');

    Now, you are complete with the changes in Opencart and you can make use of Redis on your website.

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


  • Abhishek Jain


    • Neelesh Singh (Moderator)
      Hello There,

      It can be developed through customization. Please email us your complete requirements at [email protected] and we will get back to you accordingly.

      Thank You
      Webkul Team

  • Martin Koch
    i did try to install redis on my website it’s active on the server changed the default.php file and put the code into both config files but what i get is a white screen
    • Govinda (Moderator)
      Hello Martin,

      The socket connection to the host may not be opened on your server so here you may get the Fatal error: Uncaught RedisException: Connection refused in /home/users/demo/www/html/system/library/cache/redis.php:12.

      To show this error, add this code in the index.php file-

      ini_set(‘display_errors’, TRUE);

      To check the socket connection –
      if (@fsockopen(CACHE_HOSTNAME, CACHE_PORT, $errno, $errstr, 30)) {
      echo “Connected”;
      } else {
      echo “Not Connected”;

      Still, you have any query, you can ask in the comment.

  • Back to Top