X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Fobjectcache%2FRESTBagOStuff.php;h=c127ec6910fd69ee9597395440c7c6d212a7edf0;hb=b8e0ca16aa743581f5fac5cef8bed5ac2bf6e7cb;hp=b0b82d86ed50ae6dfbfcf1a55b95af97a1eef7f4;hpb=e9a27a78e455de664144d0c3cfc789bcc411fab2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/objectcache/RESTBagOStuff.php b/includes/libs/objectcache/RESTBagOStuff.php index b0b82d86ed..c127ec6910 100644 --- a/includes/libs/objectcache/RESTBagOStuff.php +++ b/includes/libs/objectcache/RESTBagOStuff.php @@ -126,6 +126,7 @@ class RESTBagOStuff extends BagOStuff { public function set( $key, $value, $exptime = 0, $flags = 0 ) { // @TODO: respect WRITE_SYNC (e.g. EACH_QUORUM) + // @TODO: respect $exptime $req = [ 'method' => 'PUT', 'url' => $this->url . rawurlencode( $key ), @@ -138,6 +139,15 @@ class RESTBagOStuff extends BagOStuff { return $this->handleError( "Failed to store $key", $rcode, $rerr ); } + public function add( $key, $value, $exptime = 0, $flags = 0 ) { + // @TODO: make this atomic + if ( $this->get( $key ) === false ) { + return $this->set( $key, $value, $exptime, $flags ); + } + + return false; // key already set + } + public function delete( $key, $flags = 0 ) { // @TODO: respect WRITE_SYNC (e.g. EACH_QUORUM) $req = [ @@ -150,4 +160,16 @@ class RESTBagOStuff extends BagOStuff { } return $this->handleError( "Failed to delete $key", $rcode, $rerr ); } + + public function incr( $key, $value = 1 ) { + // @TODO: make this atomic + $n = $this->get( $key, self::READ_LATEST ); + if ( $this->isInteger( $n ) ) { // key exists? + $n = max( $n + intval( $value ), 0 ); + // @TODO: respect $exptime + return $this->set( $key, $n ) ? $n : false; + } + + return false; + } }