diff options
| author | root | 2014-09-13 22:26:58 +0200 |
|---|---|---|
| committer | root | 2014-09-13 22:26:58 +0200 |
| commit | c5639ee890215e4e8e0f544821ea8d285ca58eb8 (patch) | |
| tree | 29f685943c61c4d7ec0e376e485686e985b97065 /class | |
| parent | f8c60cae423fc78ed21d17a9217716ccc1e6dab1 (diff) | |
| download | video-dl-c5639ee890215e4e8e0f544821ea8d285ca58eb8.tar.gz | |
init
Diffstat (limited to 'class')
| -rw-r--r-- | class/redis.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/class/redis.php b/class/redis.php new file mode 100644 index 0000000..65c9312 --- /dev/null +++ b/class/redis.php @@ -0,0 +1,64 @@ +<?php +class database { + + public $db; + private $SOCKET; + private $DBNAME; + + public function __construct($DBNAME, $SOCKET) { + $this->db = new Redis(); + $this->DBNAME = $DBNAME; + $this->SOCKET = $SOCKET; + } + + public function open() { + try { + $this->db->connect($this->SOCKET); + } + catch (Exception $e) { + failure($e->getMessage()); + } + if(!$this->db->ping()) + failure("No connection to database established."); + + if(!$this->db->select($this->DBNAME)) + failure("No connection to database established."); + + return true; + } + + public function close() { + $this->db->close(); + } + + public function storeList($KEY, $VALUE) { + for ($i=0; $i<count($VALUE); $i++){ + $this->db->rPush($KEY, $VALUE[$i]); + } + } + + public function getAll($KEY){ + $len = $this->db->lSize($KEY); + $list = array(); + for($i=0;$i<$len;$i++) { + $list[$i] = $this->db->lGet($KEY, $i); + } + + return $list; + } + + public function getItem($KEY, $INDEX){ + return $this->db->lget($KEY, $INDEX); + } + + public function listExists($KEY) { + if($this->db->lLen($KEY) == 0){ + return false; + } + return true; + } + + public function len($KEY){ + return $this->db->lLen($KEY); + } +} |
