Permalink
Browse files

Add simple password authentication.

  • Loading branch information...
1 parent 60b40c2 commit 01a9b4cade35791084dd1c292a075576ef02fd2f gmccue committed Mar 21, 2013
View
@@ -30,6 +30,12 @@ class ARedisConnection extends CApplicationComponent {
*/
public $database=1;
+ /**
+ * The redis server password
+ * @var password
+ */
+ public $password=null;
+
/**
* Sets the redis client to use with this connection
* @param Redis $client the redis client instance
@@ -48,6 +54,12 @@ public function getClient()
if ($this->_client === null) {
$this->_client = new Redis;
$this->_client->connect($this->hostname, $this->port);
+
+ if (isset($this->password)) {
+ if ($this->_client->auth($this->password) === false) {
+ throw new CException('Redis authentication failed!');
+ }
+ }
}
return $this->_client;
}
@@ -52,7 +52,8 @@ public function getConnection()
"class" => "packages.redis.ARedisConnection",
"hostname" => REDIS_HOSTNAME,
"port" => REDIS_PORT,
- "database" => REDIS_DATABASE
+ "database" => REDIS_DATABASE,
+ "password" => REDIS_PASSWORD
));
}
return $this->_connection;
@@ -43,7 +43,8 @@ public function getConnection()
"class" => "packages.redis.ARedisConnection",
"hostname" => REDIS_HOSTNAME,
"port" => REDIS_PORT,
- "database" => REDIS_DATABASE
+ "database" => REDIS_DATABASE,
+ "password" => REDIS_PASSWORD
));
}
return $this->_connection;
@@ -45,7 +45,8 @@ public function getConnection()
"class" => "packages.redis.ARedisConnection",
"hostname" => REDIS_HOSTNAME,
"port" => REDIS_PORT,
- "database" => REDIS_DATABASE
+ "database" => REDIS_DATABASE,
+ "password" => REDIS_PASSWORD
));
}
return $this->_connection;
@@ -50,7 +50,8 @@ public function getConnection()
"class" => "packages.redis.ARedisConnection",
"hostname" => REDIS_HOSTNAME,
"port" => REDIS_PORT,
- "database" => REDIS_DATABASE
+ "database" => REDIS_DATABASE,
+ "password" => REDIS_PASSWORD
));
}
return $this->_connection;
View
@@ -76,7 +76,8 @@ public function getConnection()
"class" => "packages.redis.ARedisConnection",
"hostname" => REDIS_HOSTNAME,
"port" => REDIS_PORT,
- "database" => REDIS_DATABASE
+ "database" => REDIS_DATABASE,
+ "password" => REDIS_PASSWORD
));
}
return $this->_connection;
View
@@ -58,7 +58,8 @@ public function getConnection()
"class" => "packages.redis.ARedisConnection",
"hostname" => REDIS_HOSTNAME,
"port" => REDIS_PORT,
- "database" => REDIS_DATABASE
+ "database" => REDIS_DATABASE,
+ "password" => REDIS_PASSWORD
));
}
return $this->_connection;
@@ -42,7 +42,8 @@ public function getConnection()
"class" => "packages.redis.ARedisConnection",
"hostname" => REDIS_HOSTNAME,
"port" => REDIS_PORT,
- "database" => REDIS_DATABASE
+ "database" => REDIS_DATABASE,
+ "password" => REDIS_PASSWORD
));
}
return $this->_connection;
@@ -71,7 +71,8 @@ public function getConnection()
"class" => "packages.redis.ARedisConnection",
"hostname" => REDIS_HOSTNAME,
"port" => REDIS_PORT,
- "database" => REDIS_DATABASE
+ "database" => REDIS_DATABASE,
+ "password" => REDIS_PASSWORD
));
}
return $this->_connection;
@@ -82,7 +82,8 @@ public function getConnection()
"class" => "packages.redis.ARedisConnection",
"hostname" => REDIS_HOSTNAME,
"port" => REDIS_PORT,
- "database" => REDIS_DATABASE
+ "database" => REDIS_DATABASE,
+ "password" => REDIS_PASSWORD
));
}
return $this->_connection;
View
@@ -157,7 +157,8 @@ public function getConnection()
"class" => "packages.redis.ARedisConnection",
"hostname" => REDIS_HOSTNAME,
"port" => REDIS_PORT,
- "database" => REDIS_DATABASE
+ "database" => REDIS_DATABASE,
+ "password" => REDIS_PASSWORD
));
}
return $this->_connection;
@@ -111,7 +111,8 @@ public function getConnection()
"class" => "packages.redis.ARedisConnection",
"hostname" => REDIS_HOSTNAME,
"port" => REDIS_PORT,
- "database" => REDIS_DATABASE
+ "database" => REDIS_DATABASE,
+ "password" => REDIS_PASSWORD
));
}
return $this->_connection;
View
@@ -5,4 +5,5 @@
Yii::import("packages.redis.*");
define("REDIS_HOSTNAME","localhost");
define("REDIS_PORT", 6379);
-define("REDIS_DATABASE",1);
+define("REDIS_DATABASE",1);
+define("REDIS_PASSWORD", null);

0 comments on commit 01a9b4c

Please sign in to comment.