db = new Redis(); $this->bypassCache=false; try { $this->db->connect($rconnect); } catch (Exception $e) { return $e->getMessage(); } try { $this->db->ping(); } catch (Exception $e) { return $e->getMessage(); } try { $this->db->select($rdb); } catch (Exception $e) { return $e->getMessage(); } $this->dbnmr = $rdb; $this->dbpagecache = PAGECACHE_DB; $this->db2nd = SECOND_CACHE; } public function check(){ try { return $this->db->ping(); } catch (Exception $e) { return $e->getMessage(); } } public function setKey($key, $value, $ttl = null){ $this->db->set($key, $value, $ttl); } public function getValue($key){ return $this->db->get($key); } public function getToken($data, $append = ""){ $this->token = CACHEPREFIX . $append . md5(strtolower($data)); return $this->token; } public function exists($key){ return $this->db->exists($key); } public function delete($key){ return $this->db->delete($key); } public function del($key){ return $this->db->delete($key); } public function setPageCache($key, $value, $ttl = 3600){ $this->db->select( $this->dbpagecache ); $this->db->set( $key, $value, $ttl ); $this->db->select( $this->dbnmr ); } public function getPageCache($key){ $this->db->select( $this->dbpagecache ); $data = $this->db->get( $key ); $this->db->select( $this->dbnmr ); return $data; } public function existsPageCache($key){ $this->db->select( $this->dbpagecache ); $data = $this->exists( $key ); $this->db->select( $this->dbnmr ); return $data; } public function flushPageCache(){ $this->db->select( $this->dbpagecache ); $this->db->flushDB(); $this->db->select( $this->dbnmr ); } public function flush($token = null){ $this->flushPageCache(); if ( is_null($token) ) return $this->db->flushDB(); else return $this->db->delete($token); } public function flushAll(){ $this->db->flushDB(); $this->flushPageCache(); $this->flush2(); } public function set2($key, $value, $ttl = null){ $this->db->select( $this->db2nd ); $this->db->set($key, $value, $ttl); $this->db->select( $this->dbnmr ); } public function get2($key){ $this->db->select( $this->db2nd ); $data = $this->db->get($key); $this->db->select( $this->dbnmr ); return $data; } public function exists2($key){ $this->db->select( $this->db2nd ); $data = $this->db->exists($key); $this->db->select( $this->dbnmr ); return $data; } public function flush2($token = null){ $this->db->select( $this->db2nd ); if ( is_null($token) ) $data = $this->db->flushDB(); else $data = $this->db->delete($token); $this->db->select( $this->dbnmr ); $this->flushPageCache(); return $data; } }