protected $lastError = self::ERR_NONE;
/** Possible values for getLastError() */
- const ERR_NONE = 0; // no error
+ const ERR_NONE = 0; // no error
const ERR_NO_RESPONSE = 1; // no response
const ERR_UNREACHABLE = 2; // can't connect
- const ERR_UNEXPECTED = 3; // response gave some error
+ const ERR_UNEXPECTED = 3; // response gave some error
/**
* @param bool $bool
}
/**
- * @param string $key
- * @param mixed $value
- * @param int $exptime
+ * Batch insertion
+ * @param array $data $key => $value assoc array
+ * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
* @return bool Success
+ * @since 1.24
*/
- public function add( $key, $value, $exptime = 0 ) {
- if ( $this->get( $key ) === false ) {
- return $this->set( $key, $value, $exptime );
+ public function setMulti( array $data, $exptime = 0 ) {
+ $res = true;
+ foreach ( $data as $key => $value ) {
+ if ( !$this->set( $key, $value, $exptime ) ) {
+ $res = false;
+ }
}
- return false; // key already set
+ return $res;
}
/**
* @param mixed $value
* @param int $exptime
* @return bool Success
- * @deprecated since 1.23
*/
- public function replace( $key, $value, $exptime = 0 ) {
- wfDeprecated( __METHOD__, '1.23' );
- if ( $this->get( $key ) !== false ) {
+ public function add( $key, $value, $exptime = 0 ) {
+ if ( $this->get( $key ) === false ) {
return $this->set( $key, $value, $exptime );
}
- return false; // key not already set
+ return false; // key already set
}
/**
* This will create the key with value $init and TTL $ttl if not present
*
* @param string $key
- * @param integer $ttl
- * @param integer $value
- * @param integer $init
+ * @param int $ttl
+ * @param int $value
+ * @param int $init
* @return bool
* @since 1.24
*/
public function incrWithInit( $key, $ttl, $value = 1, $init = 1 ) {
return $this->incr( $key, $value ) ||
- $this->add( $key, $init, $ttl ) || $this->incr( $key, $value );
+ $this->add( $key, (int)$init, $ttl ) || $this->incr( $key, $value );
}
/**