Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User_Session_Couchbase_Storage extends User_Session_Storage_Interface
- {
- private $exist=true;
- private static $host,$user,$password,$bucket,$isConnected=false,$connection;
- function __construct($host,$user,$password,$bucket)
- {
- self::setConnection($host,$user,$password,$bucket);
- }
- static function setConnection($host,$user,$password,$bucket)
- {
- self::$host = $host;
- self::$user = $user;
- self::$password = $password;
- self::$bucket = $bucket;
- if(!self::$isConnected) {
- self::$connection = new Couchbase(self::$host, self::$user, self::$password, self::$bucket);
- self::$isConnected = true;
- }
- }
- public function get($id)
- {
- if(!$this->exist) {
- $data = self::$connection->get($id);
- if(self::$connection->getResultCode() == COUCHBASE_KEY_ENOENT){
- $this->exist = false;
- } else {
- $this->exist = true;
- return $data;
- }
- }
- }
- public function set($id,$data,$time)
- {
- if(strlen($data) > 6) {
- $this->get($id);
- if(!$this->exist) {
- self::$connection->add($id,$data,1296000);
- } else {
- self::$connection->replace($id,$data,1296000);
- }
- }
- }
- public function create($id,$data,$time)
- {
- //not used
- }
- public function clean($time)
- {
- //not used
- }
- public function optimize()
- {
- //not used
- }
- public function remove($id)
- {
- self::$connection->delete($id);
- }
- }
Add Comment
Please, Sign In to add comment