From c5639ee890215e4e8e0f544821ea8d285ca58eb8 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 13 Sep 2014 22:26:58 +0200 Subject: init --- class/redis.php | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 class/redis.php (limited to 'class/redis.php') 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 @@ +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; $idb->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); + } +} -- cgit v1.2.3