Skip to content

Commit

Permalink
Added rename command (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: Erik Bohony <bohony@efabrica.sk>
  • Loading branch information
erko185 and Erik Bohony authored Jan 31, 2024
1 parent c320f5d commit a884d59
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### [Unreleased][unreleased]
#### Added
- added rename command
- Added srem, sismember commands

### [1.0.0] - 2023-09-06
Expand Down
14 changes: 14 additions & 0 deletions src/RedisProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,20 @@ public function zrevrank(string $key, string $member): ?int
return $this->convertFalseToNull($result);
}

/**
* Renames key to newkey
*/
public function rename(string $key, string $newKey): bool
{
$this->init();
try {
$result = $this->driver->call('rename', [$key, $newKey]);
} catch (RedisProxyException $exception) {
return false;
}
return $result;
}

/**
* Create array from input array - odd keys are used as keys, even keys are used as values
* @param array $dictionary
Expand Down
12 changes: 12 additions & 0 deletions tests/BaseDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1343,4 +1343,16 @@ public function testType(): void
$this->redisProxy->zadd('my_sorted_set_key', 1, 'my_value');
self::assertEquals(RedisProxy::TYPE_SORTED_SET, $this->redisProxy->type('my_sorted_set_key'));
}

public function testRename():void
{
self::assertNull($this->redisProxy->get('my_key'));
self::assertTrue($this->redisProxy->set('my_key', 'my_value'));
self::assertTrue($this->redisProxy->rename('my_key', 'new_key'));
self::assertTrue($this->redisProxy->rename('new_key', 'new_new_key'));
}

public function testWrongRename(){
self::assertFalse($this->redisProxy->rename('my_keyaaa', 'new_key'));
}
}

0 comments on commit a884d59

Please sign in to comment.