|
@@ -75,7 +75,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
$callback = $this->getExecuteCallback($expected, $commands);
|
|
$callback = $this->getExecuteCallback($expected, $commands);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
|
|
|
|
- $replies = $tx->execute(function($tx) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) {
|
|
$tx->echo('one');
|
|
$tx->echo('one');
|
|
$tx->echo('two');
|
|
$tx->echo('two');
|
|
$tx->echo('three');
|
|
$tx->echo('three');
|
|
@@ -98,9 +98,10 @@ class MultiExecContextTest extends StandardTestCase
|
|
$exception = null;
|
|
$exception = null;
|
|
|
|
|
|
try {
|
|
try {
|
|
- $tx->echo('foo')->execute(function($tx) { $tx->echo('bar'); });
|
|
|
|
- }
|
|
|
|
- catch (\Exception $ex) {
|
|
|
|
|
|
+ $tx->echo('foo')->execute(function ($tx) {
|
|
|
|
+ $tx->echo('bar');
|
|
|
|
+ });
|
|
|
|
+ } catch (\Exception $ex) {
|
|
$exception = $ex;
|
|
$exception = $ex;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -118,7 +119,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
$callback = $this->getExecuteCallback(null, $commands);
|
|
$callback = $this->getExecuteCallback(null, $commands);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
|
|
|
|
- $replies = $tx->execute(function($tx) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) {
|
|
// NOOP
|
|
// NOOP
|
|
});
|
|
});
|
|
|
|
|
|
@@ -138,7 +139,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
$callback = $this->getExecuteCallback(null, $commands);
|
|
$callback = $this->getExecuteCallback(null, $commands);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
|
|
|
|
- $replies = $tx->execute(function($tx) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) {
|
|
$tx->exec();
|
|
$tx->exec();
|
|
});
|
|
});
|
|
|
|
|
|
@@ -156,7 +157,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
$callback = $this->getExecuteCallback(null, $commands);
|
|
$callback = $this->getExecuteCallback(null, $commands);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
|
|
|
|
- $replies = $tx->execute(function($tx) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) {
|
|
$tx->discard();
|
|
$tx->discard();
|
|
});
|
|
});
|
|
|
|
|
|
@@ -174,7 +175,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
$callback = $this->getExecuteCallback(null, $commands);
|
|
$callback = $this->getExecuteCallback(null, $commands);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
|
|
|
|
- $replies = $tx->execute(function($tx) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) {
|
|
$tx->set('foo', 'bar');
|
|
$tx->set('foo', 'bar');
|
|
$tx->get('foo');
|
|
$tx->get('foo');
|
|
$tx->discard();
|
|
$tx->discard();
|
|
@@ -195,7 +196,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
$callback = $this->getExecuteCallback($expected, $commands);
|
|
$callback = $this->getExecuteCallback($expected, $commands);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
|
|
|
|
- $replies = $tx->execute(function($tx) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) {
|
|
$tx->echo('before DISCARD');
|
|
$tx->echo('before DISCARD');
|
|
$tx->discard();
|
|
$tx->discard();
|
|
$tx->echo('after DISCARD');
|
|
$tx->echo('after DISCARD');
|
|
@@ -245,7 +246,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
$callback = $this->getExecuteCallback($expected, $txCommands, $casCommands);
|
|
$callback = $this->getExecuteCallback($expected, $txCommands, $casCommands);
|
|
$tx = $this->getMockedTransaction($callback, $options);
|
|
$tx = $this->getMockedTransaction($callback, $options);
|
|
|
|
|
|
- $replies = $tx->execute(function($tx) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) {
|
|
$tx->get('foo');
|
|
$tx->get('foo');
|
|
$tx->get('hoge');
|
|
$tx->get('hoge');
|
|
});
|
|
});
|
|
@@ -294,7 +295,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
$tx = $this->getMockedTransaction($callback, $options);
|
|
$tx = $this->getMockedTransaction($callback, $options);
|
|
|
|
|
|
$test = $this;
|
|
$test = $this;
|
|
- $replies = $tx->execute(function($tx) use($test) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) use ($test) {
|
|
$tx->watch('foobar');
|
|
$tx->watch('foobar');
|
|
|
|
|
|
$reply1 = $tx->get('foo');
|
|
$reply1 = $tx->get('foo');
|
|
@@ -325,7 +326,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
$callback = $this->getExecuteCallback(array(), $txCommands, $casCommands);
|
|
$callback = $this->getExecuteCallback(array(), $txCommands, $casCommands);
|
|
$tx = $this->getMockedTransaction($callback, $options);
|
|
$tx = $this->getMockedTransaction($callback, $options);
|
|
|
|
|
|
- $tx->execute(function($tx) {
|
|
|
|
|
|
+ $tx->execute(function ($tx) {
|
|
$tx->multi();
|
|
$tx->multi();
|
|
});
|
|
});
|
|
|
|
|
|
@@ -344,7 +345,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
$callback = $this->getExecuteCallback(array(), $txCommands, $casCommands);
|
|
$callback = $this->getExecuteCallback(array(), $txCommands, $casCommands);
|
|
$tx = $this->getMockedTransaction($callback, $options);
|
|
$tx = $this->getMockedTransaction($callback, $options);
|
|
|
|
|
|
- $tx->execute(function($tx) {
|
|
|
|
|
|
+ $tx->execute(function ($tx) {
|
|
$bar = $tx->get('foo');
|
|
$bar = $tx->get('foo');
|
|
$tx->set('hoge', 'piyo');
|
|
$tx->set('hoge', 'piyo');
|
|
});
|
|
});
|
|
@@ -383,11 +384,13 @@ class MultiExecContextTest extends StandardTestCase
|
|
$callback = $this->getExecuteCallback($expected, $txCommands, $casCommands);
|
|
$callback = $this->getExecuteCallback($expected, $txCommands, $casCommands);
|
|
$tx = $this->getMockedTransaction($callback, $options);
|
|
$tx = $this->getMockedTransaction($callback, $options);
|
|
|
|
|
|
- $replies = $tx->execute(function($tx) use($sentinel, &$attempts) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) use ($sentinel, &$attempts) {
|
|
$tx->get('foo');
|
|
$tx->get('foo');
|
|
|
|
+
|
|
if ($attempts > 0) {
|
|
if ($attempts > 0) {
|
|
$attempts -= 1;
|
|
$attempts -= 1;
|
|
$sentinel->signal();
|
|
$sentinel->signal();
|
|
|
|
+
|
|
$tx->echo('!!ABORT!!');
|
|
$tx->echo('!!ABORT!!');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -407,7 +410,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
$callback = $this->getExecuteCallback();
|
|
$callback = $this->getExecuteCallback();
|
|
$tx = $this->getMockedTransaction($callback);
|
|
$tx = $this->getMockedTransaction($callback);
|
|
|
|
|
|
- $replies = $tx->execute(function($tx) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) {
|
|
$tx->echo('!!ABORT!!');
|
|
$tx->echo('!!ABORT!!');
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -426,13 +429,13 @@ class MultiExecContextTest extends StandardTestCase
|
|
$replies = null;
|
|
$replies = null;
|
|
|
|
|
|
try {
|
|
try {
|
|
- $replies = $tx->execute(function($tx) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) {
|
|
$tx->set('foo', 'bar');
|
|
$tx->set('foo', 'bar');
|
|
$tx->get('foo');
|
|
$tx->get('foo');
|
|
|
|
+
|
|
throw new \RuntimeException('TEST');
|
|
throw new \RuntimeException('TEST');
|
|
});
|
|
});
|
|
- }
|
|
|
|
- catch (\Exception $ex) {
|
|
|
|
|
|
+ } catch (\Exception $ex) {
|
|
// NOOP
|
|
// NOOP
|
|
}
|
|
}
|
|
|
|
|
|
@@ -454,13 +457,12 @@ class MultiExecContextTest extends StandardTestCase
|
|
$replies = null;
|
|
$replies = null;
|
|
|
|
|
|
try {
|
|
try {
|
|
- $replies = $tx->execute(function($tx) {
|
|
|
|
|
|
+ $replies = $tx->execute(function ($tx) {
|
|
$tx->set('foo', 'bar');
|
|
$tx->set('foo', 'bar');
|
|
$tx->echo('ERR Invalid operation');
|
|
$tx->echo('ERR Invalid operation');
|
|
$tx->get('foo');
|
|
$tx->get('foo');
|
|
});
|
|
});
|
|
- }
|
|
|
|
- catch (ServerException $ex) {
|
|
|
|
|
|
+ } catch (ServerException $ex) {
|
|
$tx->discard();
|
|
$tx->discard();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -481,12 +483,11 @@ class MultiExecContextTest extends StandardTestCase
|
|
$exception = null;
|
|
$exception = null;
|
|
|
|
|
|
try {
|
|
try {
|
|
- $client->multiExec(function($tx) {
|
|
|
|
|
|
+ $client->multiExec(function ($tx) {
|
|
$tx->set('foo', 'bar');
|
|
$tx->set('foo', 'bar');
|
|
throw new \RuntimeException("TEST");
|
|
throw new \RuntimeException("TEST");
|
|
});
|
|
});
|
|
- }
|
|
|
|
- catch (\Exception $ex) {
|
|
|
|
|
|
+ } catch (\Exception $ex) {
|
|
$exception = $ex;
|
|
$exception = $ex;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -504,13 +505,12 @@ class MultiExecContextTest extends StandardTestCase
|
|
$value = (string) rand();
|
|
$value = (string) rand();
|
|
|
|
|
|
try {
|
|
try {
|
|
- $client->multiExec(function($tx) use($value) {
|
|
|
|
|
|
+ $client->multiExec(function ($tx) use ($value) {
|
|
$tx->set('foo', 'bar');
|
|
$tx->set('foo', 'bar');
|
|
$tx->lpush('foo', 'bar');
|
|
$tx->lpush('foo', 'bar');
|
|
$tx->set('foo', $value);
|
|
$tx->set('foo', $value);
|
|
});
|
|
});
|
|
- }
|
|
|
|
- catch (ServerException $ex) {
|
|
|
|
|
|
+ } catch (ServerException $ex) {
|
|
$exception = $ex;
|
|
$exception = $ex;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -525,7 +525,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
{
|
|
{
|
|
$client = $this->getClient(array(), array('exceptions' => false));
|
|
$client = $this->getClient(array(), array('exceptions' => false));
|
|
|
|
|
|
- $replies = $client->multiExec(function($tx) {
|
|
|
|
|
|
+ $replies = $client->multiExec(function ($tx) {
|
|
$tx->set('foo', 'bar');
|
|
$tx->set('foo', 'bar');
|
|
$tx->lpush('foo', 'bar');
|
|
$tx->lpush('foo', 'bar');
|
|
$tx->echo('foobar');
|
|
$tx->echo('foobar');
|
|
@@ -543,7 +543,7 @@ class MultiExecContextTest extends StandardTestCase
|
|
{
|
|
{
|
|
$client = $this->getClient();
|
|
$client = $this->getClient();
|
|
|
|
|
|
- $replies = $client->multiExec(function($tx) {
|
|
|
|
|
|
+ $replies = $client->multiExec(function ($tx) {
|
|
$tx->set('foo', 'bar');
|
|
$tx->set('foo', 'bar');
|
|
$tx->discard();
|
|
$tx->discard();
|
|
$tx->set('hoge', 'piyo');
|
|
$tx->set('hoge', 'piyo');
|
|
@@ -564,13 +564,12 @@ class MultiExecContextTest extends StandardTestCase
|
|
$client2 = $this->getClient();
|
|
$client2 = $this->getClient();
|
|
|
|
|
|
try {
|
|
try {
|
|
- $client1->multiExec(array('watch' => 'sentinel'), function($tx) use($client2) {
|
|
|
|
|
|
+ $client1->multiExec(array('watch' => 'sentinel'), function ($tx) use ($client2) {
|
|
$tx->set('sentinel', 'client1');
|
|
$tx->set('sentinel', 'client1');
|
|
$tx->get('sentinel');
|
|
$tx->get('sentinel');
|
|
$client2->set('sentinel', 'client2');
|
|
$client2->set('sentinel', 'client2');
|
|
});
|
|
});
|
|
- }
|
|
|
|
- catch (AbortedMultiExecException $ex) {
|
|
|
|
|
|
+ } catch (AbortedMultiExecException $ex) {
|
|
$exception = $ex;
|
|
$exception = $ex;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -588,9 +587,10 @@ class MultiExecContextTest extends StandardTestCase
|
|
$client->set('foo', 'bar');
|
|
$client->set('foo', 'bar');
|
|
$options = array('watch' => 'foo', 'cas' => true);
|
|
$options = array('watch' => 'foo', 'cas' => true);
|
|
|
|
|
|
- $replies = $client->multiExec($options, function($tx) {
|
|
|
|
|
|
+ $replies = $client->multiExec($options, function ($tx) {
|
|
$tx->watch('foobar');
|
|
$tx->watch('foobar');
|
|
$foo = $tx->get('foo');
|
|
$foo = $tx->get('foo');
|
|
|
|
+
|
|
$tx->multi();
|
|
$tx->multi();
|
|
$tx->set('foobar', $foo);
|
|
$tx->set('foobar', $foo);
|
|
$tx->discard();
|
|
$tx->discard();
|
|
@@ -605,15 +605,18 @@ class MultiExecContextTest extends StandardTestCase
|
|
$client->set('foo', 'bar');
|
|
$client->set('foo', 'bar');
|
|
|
|
|
|
$options = array('watch' => 'foo', 'cas' => true, 'retry' => 1);
|
|
$options = array('watch' => 'foo', 'cas' => true, 'retry' => 1);
|
|
- $replies = $client->multiExec($options, function($tx) use($client2, &$hijack) {
|
|
|
|
|
|
+ $replies = $client->multiExec($options, function ($tx) use ($client2, &$hijack) {
|
|
$foo = $tx->get('foo');
|
|
$foo = $tx->get('foo');
|
|
$tx->multi();
|
|
$tx->multi();
|
|
|
|
+
|
|
$tx->set('foobar', $foo);
|
|
$tx->set('foobar', $foo);
|
|
$tx->discard();
|
|
$tx->discard();
|
|
|
|
+
|
|
if ($hijack) {
|
|
if ($hijack) {
|
|
$hijack = false;
|
|
$hijack = false;
|
|
$client2->set('foo', 'hijacked!');
|
|
$client2->set('foo', 'hijacked!');
|
|
}
|
|
}
|
|
|
|
+
|
|
$tx->mget('foo', 'foobar');
|
|
$tx->mget('foo', 'foobar');
|
|
});
|
|
});
|
|
|
|
|
|
@@ -670,13 +673,12 @@ class MultiExecContextTest extends StandardTestCase
|
|
{
|
|
{
|
|
$multi = $watch = $abort = false;
|
|
$multi = $watch = $abort = false;
|
|
|
|
|
|
- return function(CommandInterface $command) use(&$expected, &$commands, &$cas, &$multi, &$watch, &$abort) {
|
|
|
|
|
|
+ return function (CommandInterface $command) use (&$expected, &$commands, &$cas, &$multi, &$watch, &$abort) {
|
|
$cmd = $command->getId();
|
|
$cmd = $command->getId();
|
|
|
|
|
|
if ($multi || $cmd === 'MULTI') {
|
|
if ($multi || $cmd === 'MULTI') {
|
|
$commands[] = $command;
|
|
$commands[] = $command;
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
$cas[] = $command;
|
|
$cas[] = $command;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -685,31 +687,38 @@ class MultiExecContextTest extends StandardTestCase
|
|
if ($multi) {
|
|
if ($multi) {
|
|
throw new ServerException("ERR $cmd inside MULTI is not allowed");
|
|
throw new ServerException("ERR $cmd inside MULTI is not allowed");
|
|
}
|
|
}
|
|
|
|
+
|
|
return $watch = true;
|
|
return $watch = true;
|
|
|
|
|
|
case 'MULTI':
|
|
case 'MULTI':
|
|
if ($multi) {
|
|
if ($multi) {
|
|
throw new ServerException("ERR MULTI calls can not be nested");
|
|
throw new ServerException("ERR MULTI calls can not be nested");
|
|
}
|
|
}
|
|
|
|
+
|
|
return $multi = true;
|
|
return $multi = true;
|
|
|
|
|
|
case 'EXEC':
|
|
case 'EXEC':
|
|
if (!$multi) {
|
|
if (!$multi) {
|
|
throw new ServerException("ERR $cmd without MULTI");
|
|
throw new ServerException("ERR $cmd without MULTI");
|
|
}
|
|
}
|
|
|
|
+
|
|
$watch = $multi = false;
|
|
$watch = $multi = false;
|
|
|
|
+
|
|
if ($abort) {
|
|
if ($abort) {
|
|
$commands = $cas = array();
|
|
$commands = $cas = array();
|
|
$abort = false;
|
|
$abort = false;
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
+
|
|
return $expected;
|
|
return $expected;
|
|
|
|
|
|
case 'DISCARD':
|
|
case 'DISCARD':
|
|
if (!$multi) {
|
|
if (!$multi) {
|
|
throw new ServerException("ERR $cmd without MULTI");
|
|
throw new ServerException("ERR $cmd without MULTI");
|
|
}
|
|
}
|
|
|
|
+
|
|
$watch = $multi = false;
|
|
$watch = $multi = false;
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
|
|
|
|
case 'ECHO':
|
|
case 'ECHO':
|
|
@@ -717,9 +726,11 @@ class MultiExecContextTest extends StandardTestCase
|
|
if (strpos($trigger, 'ERR ') === 0) {
|
|
if (strpos($trigger, 'ERR ') === 0) {
|
|
throw new ServerException($trigger);
|
|
throw new ServerException($trigger);
|
|
}
|
|
}
|
|
|
|
+
|
|
if ($trigger === '!!ABORT!!' && $multi) {
|
|
if ($trigger === '!!ABORT!!' && $multi) {
|
|
$abort = true;
|
|
$abort = true;
|
|
}
|
|
}
|
|
|
|
+
|
|
return new ResponseQueued();
|
|
return new ResponseQueued();
|
|
|
|
|
|
case 'UNWATCH':
|
|
case 'UNWATCH':
|