Skip to content

Commit

Permalink
add auth
Browse files Browse the repository at this point in the history
  • Loading branch information
qii404 committed Aug 2, 2017
1 parent 67d57ab commit 9c9b77b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ include 'Autoload.php';

$config = ['host' => '127.0.0.1', 'port' => 6379, 'weight' => 1];

// if need auth
// $config = ['host' => '127.0.0.1', 'port' => 6379, 'weight' => 1, 'auth' => 'qii'];

$redis = new SingleClient(
$config,
RedisFactory::PHPREDIS // this is optional param, default is PHPREDIS driver
Expand Down
6 changes: 4 additions & 2 deletions example/SingleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

include '../src/Autoload.php';

$config = ['host' => '127.0.0.1', 'port' => 6379, 'weight' => 1];
$config = ['host' => '127.0.0.1', 'port' => 6379, 'weight' => 1, 'auth' => 'qii'];

$redis = new SingleClient(
$config,
RedisFactory::PHPREDIS // this is optional param, default is PHPREDIS driver
);

$redis->set('name', 'qii404'); // true
$redis->get('name'); // 'qii404'
$r = $redis->get('name'); // 'qii404'

var_dump($r);

// end of file SingleClient.php
4 changes: 3 additions & 1 deletion example/WithOutSlavesClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
);

$redis->hset('profile', 'name', 'qii44'); // true
$redis->hget('profile', 'name'); // 'qii404'
$r = $redis->hget('profile', 'name'); // 'qii404'

var_dump($r);

// end of file WithoutSlavesClient.php
4 changes: 3 additions & 1 deletion example/WithSlavesClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
);

$redis->zadd('key', 99, 'qii404'); // true; executes in master server, such as port 6379
$redis->zscore('key', 'qii404'); // 99; executes in slave server, such as port 6381
$r = $redis->zscore('key', 'qii404'); // 99; executes in slave server, such as port 6381

var_dump($r);

// end of file WithSlavesClient.php
2 changes: 2 additions & 0 deletions src/Drivers/PhpRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function __construct(array $config)
// todo: define manual Exception
throw new Exception('Cant\'t create connection to redis server, ' . $e->getMessage());
}

$config['auth'] && $this->redis->auth($config['auth']);
}

/**
Expand Down

0 comments on commit 9c9b77b

Please sign in to comment.