[Request] Redis object cache pro wordpress plugin

Legolas

Active member
Trusted Uploader
Feb 26, 2019
175
216
43
It doesn't work with PHP 8.0. It crashes and can't be installed. At least this 1.13.1 version. I don't know if newer versions do work fine
 

tarek110

Member
Aug 24, 2020
72
43
18
In file "License.php" located in "redis-cache-pro\src\License.php" change the lines from 130 to 163 to the following:

Code:
public function isCanceled()
    {
        return $this->state === self::Valid;
    }

    /**
     * Whether the license is unpaid.
     *
     * @return bool
     */
    public function isUnpaid()
    {
        return $this->state === self::Valid;
    }

    /**
     * Whether the license is invalid.
     *
     * @return bool
     */
    public function isInvalid()
    {
        return $this->state === self::Valid;
    }

    /**
     * Whether the license was deauthorized.
     *
     * @return bool
     */
    public function isDeauthorized()
    {
        return $this->state === self::Valid;
    }
Hope that i helped :geek:🌹
 

lehaophuc83

Member
Jun 10, 2020
56
35
18
SaiGon, VN
is.gd
In file "License.php" located in "redis-cache-pro\src\License.php" change the lines from 130 to 163 to the following:

Code:
public function isCanceled()
    {
        return $this->state === self::Valid;
    }

    /**
     * Whether the license is unpaid.
     *
     * @return bool
     */
    public function isUnpaid()
    {
        return $this->state === self::Valid;
    }

    /**
     * Whether the license is invalid.
     *
     * @return bool
     */
    public function isInvalid()
    {
        return $this->state === self::Valid;
    }

    /**
     * Whether the license was deauthorized.
     *
     * @return bool
     */
    public function isDeauthorized()
    {
        return $this->state === self::Valid;
    }
Hope that i helped :geek:🌹
I think this way does not solve the problem.
This code: calls the "WP_Error" function... You changed the error message only , It doesn't run the main function that creates "Cache"

Check by plugin "query-monitor" here:

Error-REDIS.jpg
 
Last edited:

lectora

Member
Nov 1, 2019
57
5
8
Use the same mu-plugin.php file from this pach!
IN WP-CONFIG.PHP-> NO token is neded! (no license needed)


define( 'WP_CACHE', true);
define('WP_REDIS_CONFIG', [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 1, // change for each site
'timeout' => 1,
'read_timeout' => 0.5,
'async_flush' => true,
'split_alloptions' => true,
'prefetch' => true,
'debug' => false,
'save_commands' => false,
]);
define('WP_REDIS_DISABLED', getenv('WP_REDIS_DISABLED') ?: false);
define( 'WP_REDIS_PREFIX', 'domain' );
define( 'WP_REDIS_SELECTIVE_FLUSH', true);
nice job)) can you update to latest version?
 

ckeeper

Well-known member
Nov 8, 2019
623
376
63
It works if you just replace the License.php from the previously nulled version. Put the code below under src/License.php, replace the existing content with the attached one. That should do it.

PHP:
<?php

declare(strict_types=1);

namespace RedisCachePro;

use WP_Error;

class License
{
    /**
     * The license is valid.
     *
     * @var string
     */
    const Valid = 'valid';

    /**
     * The license was canceled.
     *
     * @var string
     */
    const Canceled = 'canceled';

    /**
     * The license is unpaid.
     *
     * @var string
     */
    const Unpaid = 'unpaid';

    /**
     * The license is invalid.
     *
     * @var string
     */
    const Invalid = 'invalid';

    /**
     * The license was deauthorized.
     *
     * @var string
     */
    const Deauthorized = 'deauthorized';

    /**
     * The license plan.
     *
     * @var string
     */
    protected $plan;

    /**
     * The license plan.
     *
     * @var string
     */
    protected $state;

    /**
     * The license plan.
     *
     * @var string
     */
    protected $token;

    /**
     * The license plan.
     *
     * @var array
     */
    protected $organization;

    /**
     * The last time the license was checked.
     *
     * @var int
     */
    protected $last_check;

    /**
     * The last time the license was verified.
     *
     * @var int
     */
    protected $valid_as_of;

    /**
     * The last error associated with the license.
     *
     * @var \WP_Error
     */
    protected $_error;

    /**
     * The license token.
     *
     * @return bool
     */
    public function token()
    {
        return $this->token;
    }

    /**
     * The license state.
     *
     * @return bool
     */
    public function state()
    {
        return $this->state;
    }

    /**
     * Whether the license is valid.
     *
     * @return bool
     */
    public function isValid()
    {
        return $this->state === self::Valid;
    }

    /**
     * Whether the license was canceled.
     *
     * @return bool
     */
    public function isCanceled()
    {
        return $this->state === self::Valid;
    }

    /**
     * Whether the license is unpaid.
     *
     * @return bool
     */
    public function isUnpaid()
    {
        return $this->state === self::Valid;
    }

    /**
     * Whether the license is invalid.
     *
     * @return bool
     */
    public function isInvalid()
    {
        return $this->state === self::Valid;
    }

    /**
     * Whether the license was deauthorized.
     *
     * @return bool
     */
    public function isDeauthorized()
    {
        return $this->state === self::Valid;
    }

    /**
     * Whether the license token matches the given token.
     *
     * @return bool
     */
    public function isToken($token)
    {
        return $this->token === $token;
    }

    /**
     * Load the plugin's license from the database.
     *
     * @return self|null
     */
    public static function load()
    {
        $license = get_site_option('rediscache_license');

        if (
            is_object($license) &&
            property_exists($license, 'token') &&
            property_exists($license, 'state') &&
            property_exists($license, 'last_check')
        ) {
            return static::fromObject($license);
        }
    }

    /**
     * Transform the license into a generic object.
     *
     * @return object
     */
    protected function toObject()
    {
        return (object) [
            'plan' => $this->plan,
            'state' => $this->state,
            'token' => $this->token,
            'organization' => $this->organization,
            'last_check' => $this->last_check,
            'valid_as_of' => $this->valid_as_of,
        ];
    }

    /**
     * Instanciate a new license from the given generic object.
     *
     * @param  object  $object
     * @return self
     */
    public static function fromObject(object $object)
    {
        $license = new self;

        foreach (get_object_vars($object) as $key => $value) {
            property_exists($license, $key) && $license->{$key} = $value;
        }

        return $license;
    }

    /**
     * Instanciate a new license from the given response object.
     *
     * @param  object  $response
     * @return self
     */
    public static function fromResponse(object $response)
    {
        $license = static::fromObject($response);
        $license->last_check = current_time('timestamp');

        if ($license->isValid()) {
            $license->valid_as_of = current_time('timestamp');
        }

        if (is_null($license->state)) {
            $license->state = self::Invalid;
        }

        return $license->save();
    }

    /**
     * Instanciate a new license from the given response object.
     *
     * @param  object  $response
     * @return self
     */
    public static function fromError(WP_Error $error)
    {
        $license = new self;

        foreach ($error->get_error_data() as $key => $value) {
            property_exists($license, $key) && $license->{$key} = $value;
        }

        $license->_error = $error;
        $license->last_check = current_time('timestamp');

        error_log('objectcache.warning: ' . $error->get_error_message());

        return $license->save();
    }

    /**
     * Persist the license as a network option.
     *
     * @return self
     */
    public function save()
    {
        update_site_option('rediscache_license', $this->toObject());

        return $this;
    }

    /**
     * Deauthorize the license.
     *
     * @return self
     */
    public function deauthorize()
    {
        $this->valid_as_of = null;
        $this->state = self::Deauthorized;

        return $this->save();
    }

    /**
     * Bump the `last_check` timestamp on the license.
     *
     * @return self
     */
    public function checkFailed(WP_Error $error)
    {
        $this->_error = $error;
        $this->last_check = current_time('timestamp');

        error_log('objectcache.notice: ' . $error->get_error_message());

        return $this->save();
    }

    /**
     * Whether it's been given minutes since the last check.
     *
     * @return bool
     */
    public function minutesSinceLastCheck(int $minutes)
    {
        if (! $this->last_check) {
            delete_site_option('rediscache_license_last_check');

            return true;
        }

        $validUntil = $this->last_check + ($minutes * MINUTE_IN_SECONDS);

        return $validUntil < current_time('timestamp');
    }

    /**
     * Whether it's been given hours since the license was successfully verified.
     *
     * @return bool
     */
    public function hoursSinceVerification(int $hours)
    {
        if (! $this->valid_as_of) {
            return true;
        }

        $validUntil = $this->valid_as_of + ($hours * HOUR_IN_SECONDS);

        return $validUntil < current_time('timestamp');
    }
}
 
Last edited:
  • Like
Reactions: far_47

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu