LinkORB\Component\Etcd\Client::update PHP 메소드

update() 공개 메소드

Update an existing key with a given value.
public update ( strint $key, string $value, integer $ttl, array $condition = [] ) : array
$key strint
$value string
$ttl integer
$condition array The extra condition for updating
리턴 array $body
    public function update($key, $value, $ttl = 0, $condition = array())
    {
        $extra = array('prevExist' => 'true');
        if ($condition) {
            $extra = array_merge($extra, $condition);
        }
        $body = $this->set($key, $value, $ttl, $extra);
        if (isset($body['errorCode'])) {
            throw new KeyNotFoundException($body['message'], $body['errorCode']);
        }
        return $body;
    }

Usage Example

예제 #1
0
 /**
  * @covers LinkORB\Component\Etcd\Client::update
  * @expectedException \LinkORB\Component\Etcd\Exception\KeyNotFoundException
  */
 public function testUpdate()
 {
     $key = '/testupdate_key';
     $value1 = 'value1';
     $value2 = 'value2';
     $this->client->update($key, $value1);
     $this->client->set($key, $value2);
     $value = $this->client->get($key);
     $this->assertEquals('value2', $value);
 }
All Usage Examples Of LinkORB\Component\Etcd\Client::update