Permalink
Browse files

Fix implementation for hash tags extraction from keys.

We now fully comply with the specifications defined by Redis.
  • Loading branch information...
1 parent ab6cbe7 commit 809f76a7b3fd0e510a29753528e954a33fa597db @nrk committed Feb 11, 2014
@@ -303,8 +303,8 @@ public function getKeyHash($key)
protected function extractKeyTag($key)
{
if (false !== $start = strpos($key, '{')) {
- if (false !== $end = strpos($key, '}', $start)) {
- $key = substr($key, ++$start, $end - $start);
+ if (false !== ($end = strpos($key, '}', $start)) && $end !== ++$start) {
+ $key = substr($key, $start, $end - $start);
}
}
@@ -29,7 +29,14 @@ public function testSupportsKeyTags()
$this->assertSame(44950, $strategy->getKeyHash('{foo}'));
$this->assertSame(44950, $strategy->getKeyHash('{foo}:bar'));
$this->assertSame(44950, $strategy->getKeyHash('{foo}:baz'));
- $this->assertSame(44950, $strategy->getKeyHash('bar:{foo}:bar'));
+ $this->assertSame(44950, $strategy->getKeyHash('bar:{foo}:baz'));
+ $this->assertSame(44950, $strategy->getKeyHash('bar:{foo}:{baz}'));
+
+ $this->assertSame(44950, $strategy->getKeyHash('bar:{foo}:baz{}'));
+ $this->assertSame(9415, $strategy->getKeyHash('{}bar:{foo}:baz'));
+
+ $this->assertSame(0, $strategy->getKeyHash(''));
+ $this->assertSame(31641, $strategy->getKeyHash('{}'));
}
/**

0 comments on commit 809f76a

Please sign in to comment.