Skip to content

Commit

Permalink
Merge pull request #2 from dwaysinc/0.0.1
Browse files Browse the repository at this point in the history
0.0.1
  • Loading branch information
dwaysinc authored Apr 14, 2022
2 parents 3f29fa6 + ac983e9 commit 34a4ca3
Show file tree
Hide file tree
Showing 10 changed files with 575 additions and 32 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"require": {
"php": ">=8.1",
"amphp/redis": "^1.0.7",
"amphp/amp": "^2.6.2"
"amphp/amp": "^2.6.2",
"amphp/log": "1.1.0"
},
"autoload": {
"psr-4": {
Expand Down
216 changes: 215 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 6 additions & 18 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,47 @@ services:
redis-node-0:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-cluster_data-0:/bitnami/redis/data
- ./runtime/redis-cluster_data-0:/bitnami/redis/data
environment:
- 'REDIS_PASSWORD=bitnami'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

redis-node-1:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-cluster_data-1:/bitnami/redis/data
- ./runtime/redis-cluster_data-1:/bitnami/redis/data
environment:
- 'REDIS_PASSWORD=bitnami'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

redis-node-2:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-cluster_data-2:/bitnami/redis/data
- ./runtime/redis-cluster_data-2:/bitnami/redis/data
environment:
- 'REDIS_PASSWORD=bitnami'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

redis-node-3:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-cluster_data-3:/bitnami/redis/data
- ./runtime/redis-cluster_data-3:/bitnami/redis/data
environment:
- 'REDIS_PASSWORD=bitnami'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

redis-node-4:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-cluster_data-4:/bitnami/redis/data
- ./runtime/redis-cluster_data-4:/bitnami/redis/data
environment:
- 'REDIS_PASSWORD=bitnami'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

redis-node-5:
image: docker.io/bitnami/redis-cluster:6.2
volumes:
- redis-cluster_data-5:/bitnami/redis/data
- ./runtime/redis-cluster_data-5:/bitnami/redis/data
depends_on:
- redis-node-0
- redis-node-1
Expand All @@ -64,16 +64,4 @@ services:

volumes:
php:
driver: local
redis-cluster_data-0:
driver: local
redis-cluster_data-1:
driver: local
redis-cluster_data-2:
driver: local
redis-cluster_data-3:
driver: local
redis-cluster_data-4:
driver: local
redis-cluster_data-5:
driver: local
20 changes: 19 additions & 1 deletion examples/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

require_once __DIR__ . '/../vendor/autoload.php';

use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
use Amp\Redis\Config;
use Amp\Redis\Redis;
use Amp\Redis\RemoteExecutor;
use Monolog\Logger;
use function Amp\ByteStream\getStdout;

Amp\Loop::run(static function () {
$handler = new StreamHandler(getStdout());
$handler->setFormatter(new ConsoleFormatter);

$logger = new Logger('example');
$logger->pushHandler($handler);

$redisCluster = new DwaysInc\RedisCluster\RedisCluster(...[
new Redis(new RemoteExecutor(Config::fromUri('tcp://redis-node-0:6379?password=bitnami',))),
new Redis(new RemoteExecutor(Config::fromUri('tcp://redis-node-1:6379?password=bitnami',))),
Expand All @@ -16,5 +26,13 @@
new Redis(new RemoteExecutor(Config::fromUri('tcp://redis-node-5:6379?password=bitnami',))),
]);

yield $redisCluster->set('a', 12);
$redisCluster->setLogger($logger);

$key = 12345678;

yield $redisCluster->set($key, 12);

$value = yield $redisCluster->get(12345678);

$logger->info(sprintf('Got value by key %s - %s', $key, $value));
});
1 change: 1 addition & 0 deletions runtime/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
Loading

0 comments on commit 34a4ca3

Please sign in to comment.