示例#1
0
文件: PredisTest.php 项目: gmo/cache
 /**
  * @group redis-keys
  */
 public function testRenameNx()
 {
     try {
         $this->client->renamenx('foo', 'bar');
         $this->fail('rename should throw exception when source does not exist');
     } catch (Predis\Response\ServerException $e) {
         if ($e->getMessage() !== 'ERR no such key') {
             throw $e;
         }
     }
     $this->client->set('hello', 'world');
     $this->client->set('foo', 'bar');
     try {
         $this->assertEquals('OK', $this->client->renamenx('foo', 'foo'));
         $this->fail('rename should throw exception when source and destination are the same');
     } catch (Predis\Response\ServerException $e) {
         if ($e->getMessage() !== 'ERR source and destination objects are the same') {
             throw $e;
         }
     }
     $this->assertFalse($this->client->renamenx('foo', 'hello'));
     $this->assertTrue($this->client->renamenx('foo', 'baz'));
     $this->assertTrue($this->client->exists('baz'));
     $this->assertFalse($this->client->exists('foo'));
 }