summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorroot2014-11-27 15:55:25 +0100
committerroot2014-11-27 15:55:25 +0100
commit4f923b809b4e38e0639e253f428fb6c4df03ee67 (patch)
tree20d9d9ad9dae0316dad27358b4239b6f18f80e87 /tools
parent311ad398e06cd2eba270ea70ca5a326d03b490f9 (diff)
downloadtools.iamfabulous.de-4f923b809b4e38e0639e253f428fb6c4df03ee67.tar.gz
More structured + better UI
Diffstat (limited to 'tools')
-rw-r--r--tools/class/redis.php73
-rw-r--r--tools/config.php11
2 files changed, 83 insertions, 1 deletions
diff --git a/tools/class/redis.php b/tools/class/redis.php
new file mode 100644
index 0000000..7713487
--- /dev/null
+++ b/tools/class/redis.php
@@ -0,0 +1,73 @@
+<?php
+
+class Database {
+
+ private $db;
+ public $error;
+
+ public function __construct($connect = false, $db = false){
+ $this->db = new Redis();
+
+ if ( ! $connect || ! $db )
+ return;
+
+ $this->connect($connect, $db);
+ }
+
+ public function connect($connect, $db){
+ try {
+ $this->db->connect($connect);
+ } catch (Exception $e){
+ $this->error = $e;
+ return false;
+ }
+
+ try {
+ $this->db->select($db);
+ } catch (Exception $e){
+ $this->error = $e;
+ return false;
+ }
+
+ try {
+ $this->db->ping();
+ } catch (Exception $e){
+ $this->error = $e;
+ return false;
+ }
+
+ return true;
+ }
+
+ public function expire($key, $ttl){
+ try {
+ $this->db->setTimeout($key, $ttl);
+ } catch (Exception $e){
+ $this->error = $e;
+ return false;
+ }
+ }
+
+ public function set($key, $value, $ttl = null){
+ if ( is_null($ttl) )
+ return $this->db->set($key, $value);
+ else
+ return $this->db->set($key, $value, (int)$ttl);
+ }
+
+ public function get($key){
+ return $this->db->get($key);
+ }
+
+ public function exists($key){
+ return $this->db->exists($key);
+ }
+
+ public function __destruct(){
+ try {
+ $this->db->close();
+ } catch (Exception $e){
+ return false;
+ }
+ }
+}
diff --git a/tools/config.php b/tools/config.php
index d4b6071..eb4b329 100644
--- a/tools/config.php
+++ b/tools/config.php
@@ -1,3 +1,12 @@
<?php
-define("__domain_", "http://tools.iamfabulous.de");
+$_scheme = "http://";
+
+if ( isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] != "")
+ $_scheme = "https://";
+
+if ( ! defined("__domain_") )
+ define("__domain_", $_scheme."tools.iamfabulous.de");
+
+if ( ! defined("REDIS_CONNECT") )
+ define("REDIS_CONNECT", "/var/run/redis/redis.sock");