1

Im using Opencart 2.0 and trying to setup Redis cache by following this Guide

But im getting error that i do not understand why, can someone tell me how to fix the problem ?

Error

Fatal error: Uncaught Error: Class 'Redis' not found in /system/library/cache/redis.php:8 Stack 
trace: #0 /system/library/cache.php(9): Cache\Redis->__construct(3600) #1 /system
/framework.php(49): Cache->__construct('redis', 3600) #2 /system/startup.php(124): 
require_once('/home/system/...') #3 /public_html/index.php(19): start('catalog') #4 {main}
thrown in /system/library/cache/redis.php on line 8

Redis.php

<?php
namespace Cache;

class Redis {
    private $expire;
    private $cache;
    public function __construct($expire) {
        $this->expire = $expire;
        $this->cache = new \Redis();
        $this->cache->pconnect(CACHE_HOSTNAME, CACHE_PORT);
    }
    public function get($key) {
        $data = $this->cache->get(CACHE_PREFIX . $key);
        return json_decode($data, true);
    }
    public function set($key, $value) {
        $status = $this->cache->set(CACHE_PREFIX . $key, json_encode($value));
        if ($status) {
            $this->cache->expire(CACHE_PREFIX . $key, $this->expire);
        }
        return $status;
    }
    public function delete($key) {
        $this->cache->delete(CACHE_PREFIX . $key);
    }
}

Cache.php

<?php
class Cache {
    private $cache;

    public function __construct($driver, $expire = 3600) {
        $class = 'Cache\\' . $driver;

        if (class_exists($class)) {
            $this->cache = new $class($expire);
        } else {
            exit('Error: Could not load cache driver ' . $driver . ' cache!');
        }
    }

    public function get($key) {
        return $this->cache->get($key);
    }

    public function set($key, $value) {
        return $this->cache->set($key, $value);
    }

    public function delete($key) {
        return $this->cache->delete($key);
    }
}
vee
  • 4,506
  • 5
  • 44
  • 81
  • Make sure that Redis is installed. – vee Dec 12 '21 at 18:43
  • @vee What you mean ? How do I check if is installed ? –  Dec 12 '21 at 19:21
  • On the guide page that you provided, there is a link to [Redis page](https://hosting.xyz/wiki/hosting/extra/redis/). That is about it on that hosting provider. Or use it somewhere else, see [1](https://stackoverflow.com/questions/21555942/how-to-check-redis-instance-version), [2](https://stackoverflow.com/questions/61168156/logicexception-please-make-sure-the-php-redis-extension-is-installed-and-enable) – vee Dec 12 '21 at 19:28
  • @vee Redis is installed, what else I can do ? –  Dec 12 '21 at 21:13

0 Answers0