Skip to content

Commit 8a90de5

Browse files
committed
Register a second database instance
1 parent 2644574 commit 8a90de5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Clue/Redis/Server/Server.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,26 @@ class Server extends EventEmitter
3232
private $protocol;
3333
private $business;
3434
private $clients;
35-
private $database;
35+
private $databases;
3636

3737
public function __construct(ServerSocket $socket, LoopInterface $loop, ProtocolFactory $protocol = null, Invoker $business = null)
3838
{
3939
if ($protocol === null) {
4040
$protocol = new ProtocolFactory();
4141
}
4242

43-
$this->database = new Storage();
43+
$this->databases = array(
44+
new Storage('0'),
45+
new Storage('1'),
46+
);
47+
$db = reset($this->databases);
4448

4549
if ($business === null) {
4650
$business = new Invoker($protocol->createSerializer());
4751
$business->addCommands(new Business\Connection());
48-
$business->addCommands(new Business\Keys($this->database));
49-
$business->addCommands(new Business\Lists($this->database));
50-
$business->addCommands(new Business\Strings($this->database));
52+
$business->addCommands(new Business\Keys($db));
53+
$business->addCommands(new Business\Lists($db));
54+
$business->addCommands(new Business\Strings($db));
5155
$business->renameCommand('x_echo', 'echo');
5256
}
5357

@@ -70,7 +74,7 @@ public function handleConnection(Connection $connection)
7074
$parser = new RequestParser();
7175
$that = $this;
7276

73-
$client = new Client($connection, $this->business, $this->database);
77+
$client = new Client($connection, $this->business, reset($this->databases));
7478
$this->clients->attach($client);
7579

7680
$connection->on('data', function ($data) use ($parser, $that, $client) {

0 commit comments

Comments
 (0)