Commit f6634dfe authored by Erick Hitter's avatar Erick Hitter
Browse files

Add handling for the various responses Predis returns after performing an...

Add handling for the various responses Predis returns after performing an action, ensuring a boolean always results.
parent 277e59e6
......@@ -372,9 +372,9 @@ class WP_Object_Cache {
// Save to Redis
$expiration = absint( $expiration );
if ( $expiration ) {
$result = $this->redis->setex( $derived_key, $expiration, $this->prepare_value_for_redis( $value ) );
$result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, $this->prepare_value_for_redis( $value ) ) );
} else {
$result = $this->redis->set( $derived_key, $this->prepare_value_for_redis( $value ) );
$result = $this->parse_predis_response( $this->redis->set( $derived_key, $this->prepare_value_for_redis( $value ) ) );
}
return $result;
......@@ -399,7 +399,7 @@ class WP_Object_Cache {
}
}
$result = $this->redis->del( $derived_key );
$result = $this->parse_predis_response( $this->redis->del( $derived_key ) );
unset( $this->cache[$derived_key] );
......@@ -420,7 +420,7 @@ class WP_Object_Cache {
}
$this->cache = array();
$result = $this->redis->flushall();
$result = $this->parse_predis_response( $this->redis->flushall() );
return $result;
}
......@@ -486,9 +486,9 @@ class WP_Object_Cache {
// Save to Redis
$expiration = absint( $expiration );
if ( $expiration ) {
$result = $this->redis->setex( $derived_key, $expiration, $this->prepare_value_for_redis( $value ) );
$result = $this->parse_predis_response( $this->redis->setex( $derived_key, $expiration, $this->prepare_value_for_redis( $value ) ) );
} else {
$result = $this->redis->set( $derived_key, $this->prepare_value_for_redis( $value ) );
$result = $this->parse_predis_response( $this->redis->set( $derived_key, $this->prepare_value_for_redis( $value ) ) );
}
return $result;
......@@ -516,7 +516,7 @@ class WP_Object_Cache {
}
// Save to Redis
$result = $this->redis->incrBy( $derived_key, $offset );
$result = $this->parse_predis_response( $this->redis->incrBy( $derived_key, $offset ) );
$this->add_to_internal_cache( $derived_key, (int) $this->redis->get( $derived_key ) );
......@@ -545,7 +545,7 @@ class WP_Object_Cache {
}
// Save to Redis
$result = $this->redis->decrBy( $derived_key, $offset );
$result = $this->parse_predis_response( $this->redis->decrBy( $derived_key, $offset ) );
$this->add_to_internal_cache( $derived_key, (int) $this->redis->get( $derived_key ) );
......@@ -621,6 +621,28 @@ class WP_Object_Cache {
return $value;
}
/**
* Convert the response fro Predis into something meaningful
*
* @param mixed $response
* @return mixed
*/
protected function parse_predis_response( $response ) {
if ( is_bool( $response ) ) {
return $response;
}
if ( is_numeric( $response ) ) {
return (bool) $response;
}
if ( is_object( $response ) && method_exists( $response, 'getPayload' ) ) {
return 'OK' === $response->getPayload();
}
return false;
}
/**
* Simple wrapper for saving object to the internal cache.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment