• Resolved hwsiew

    (@hwsiew)


    I was trying to get woocommerce(WC) session data using their api function. I checked the documentation of WC, it try to get the session data from cache if available or return false otherwise. I saw an error when doing so with object cache enabled, but it return false(it supposes to be) when object cache is disable. Error information is as follow.

    Predis\Response\ServerException: ERR invalid expire time in setex in /var/www/html/wp-content/plugins/redis-cache/includes/predis/src/Client.php:370

    Thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Till Krüss

    (@tillkruess)

    Did you set a MAX_TTL? If not, the error is caused by WC or another plugin.

    This is just a drop-in that doesn’t actually cache anything.

    jomo

    (@jonathanmoorebcsorg)

    I saw this issue while searching so I thought I’d log my own investigation for anyone else who sees this.

    tldr: woocommerce does have a feature to clear sessions under /wp-admin/admin.php?page=wc-status&tab=tools or if you can get the start of the problem session from the log you can track down and delete it in the woocommerce sessions table.

    That’s a solution but not a full diagnosis of the root cause.
    I am equally sure it isn’t an issue with this plugin as such.

    The call stack looks fairly clear, and when I look at the call stack
    WP_Object_Cache->add_or_replace(true, 'wc_cache_2_0880...', 'a:7:{s:4:"cart"...', 'wc_session_id', <strong>-10330591</strong>)
    and the woocommerce code:
    wp_cache_add( $this->get_cache_prefix() . $customer_id, $value, WC_SESSION_CACHE_GROUP, $this->_session_expiration - time() );
    it looks like an old session is being picked up and then being requested to cache with a negative cache lifetime as the session has already expired.

    
    [02-Jun-2019 04:21:59 UTC] Predis\Response\ServerException: ERR invalid expire time in setex in wp-content/plugins/redis-cache/includes/predis/src/Client.php:370
    Stack trace:
    #0 wp-content/plugins/redis-cache/includes/predis/src/Client.php(335): Predis\Client->onErrorResponse(Object(Predis\Command\StringSetExpire), Object(Predis\Response\Error))
    #1 wp-content/plugins/redis-cache/includes/predis/src/Client.php(314): Predis\Client->executeCommand(Object(Predis\Command\StringSetExpire))
    #2 wp-content/object-cache.php(621): Predis\Client->__call('setex', Array)
    #3 wp-content/object-cache.php(564): WP_Object_Cache->add_or_replace(true, 'wc_cache_2_0b80...', 'a:7:{s:4:"cart"...', 'wc_session_id', -10330591)
    #4 wp-content/object-cache.php(37): WP_Object_Cache->add('wc_cache_2_0880...', 'a:7:{s:4:"cart"...', 'wc_session_id', -10330591)
    #5 wp-content/plugins/woocommerce/includes/class-wc-session-handler.php(327): wp_cache_add('wc_cache_2_0880...', 'a:7:{s:4:"cart"...', 'wc_session_id', -10330591)
    #6 wp-content/plugins/woocommerce/includes/class-wc-session-handler.php(224): WC_Session_Handler->get_session('xxxxxxxxxx...', Array)
    #7 wp-content/plugins/woocommerce/includes/class-wc-session-handler.php(93): WC_Session_Handler->get_session_data()
    #8 wp-content/plugins/woocommerce/includes/class-wc-session-handler.php(69): WC_Session_Handler->init_session_cookie()
    #9 wp-content/plugins/woocommerce/includes/class-woocommerce.php(747): WC_Session_Handler->init()
    #10 wp-content/plugins/woocommerce/includes/wc-core-functions.php(2266): WooCommerce->initialize_session()
    #11 wp-content/plugins/woocommerce/includes/class-woocommerce.php(549): wc_load_cart()
    #12 wp-includes/class-wp-hook.php(286): WooCommerce->init('')
    #13 wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
    #14 wp-includes/plugin.php(465): WP_Hook->do_action(Array)
    #15 wp-settings.php(525): do_action('init')
    #16 wp-config.php(135): require_once('/xxxx/p...')
    #17 wp-load.php(37): require_once('/xxxx/p...')
    #18 wp-blog-header.php(13): require_once('/xxxx/p...')
    #19 index.php(17): require('/xxxx/p...')
    
    Plugin Author Till Krüss

    (@tillkruess)

    @jonathanmoorebcsorg: It looks like WC is passing in -10330591 as the expiration time. Can you report this to the WC team, so they can fix it on their end?

    jomo

    (@jonathanmoorebcsorg)

    Yes ok fair enough, I submitted a pull request to woocommerce:
    https://github.com/woocommerce/woocommerce/pull/23863

    But it is tricky to get such a request accepted without reproducible root cause though.

    WC is passing in
    _session_expiration – time()

    Which is normally fine but something (possibly some other plugin reading sessions) has caused it to try to cache a session which is already expired.
    Which. should. normally. never. happen.

    In terms of this plugin though: I am checking the WordPress cache.php and it looks like the api here would not raise any error about a negative expiry, in fact the set() has:
    * @param int $expire Not Used.
    so such issue would be ignored until exposed by enabling this plugin.

    So, while it seems correct to draw attention to the negative cache, it might be more correct that this redis plugin should be interface compatible with the default implementation by ignoring any negative expiry.

    I haven’t checked through this area of code before so I may have missed something.

    Plugin Author Till Krüss

    (@tillkruess)

    Can you open an issue about it? https://github.com/tillkruss/redis-cache

    The WP default cache doesn’t use any sort of expiration, because it’s all in-memory, per request.

    jomo

    (@jonathanmoorebcsorg)

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Error When trying to get a get a cache not available’ is closed to new replies.