From 437ee0efa6b75ddcf9b8c7027d610ef1f0f84d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B5=D1=80=D0=B8=D0=B8=CC=86=20=D0=A1?= =?UTF-8?q?=D1=82=D0=B0=D0=B4=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 27 Nov 2018 15:32:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=87=D0=B0=D1=81=D1=82=D0=B8=D1=87=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B0?= =?UTF-8?q?=20redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Components/Redis.php | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Components/Redis.php diff --git a/Components/Redis.php b/Components/Redis.php new file mode 100644 index 0000000..d75f6d3 --- /dev/null +++ b/Components/Redis.php @@ -0,0 +1,56 @@ +app = $app; + + $redis_server_ip = $this->app->config('redis_server_ip'); + $redis_server_port = $this->app->config('redis_server_port'); + $redis_server_timeout = ($this->app->config('redis_server_timeout')!==null ? $this->app->config('redis_server_timeout') : 1); + $redis_server_password = $this->app->config('redis_server_password'); + + $this->redis = new Redis(); + $this->redis->connect($redis_server_ip, $redis_server_port, $redis_server_timeout); + if (isset($redis_server_password)) $this->redis->auth($redis_server_password); + } + + public function __destruct () { + $this->redis->close(); + } + + function set($key, $value, $expiration = 3600/*1 час*/) { + $ret = $this->redis->setEx($key, $expiration, $value); + if (!$ret) return array ('result'=>false); + else return array('result'=>true ); + } + + function get($key) { + $ret = $this->redis->get($key); + if ($ret === false) return array ('result'=>false); + else $ret = array ('result'=>true, 'value'=>$ret); + return $ret; + } + + function delete($key) { + $ret = $this->redis->delete($key); + if ($ret === false) return array ('result'=>false); + else return array ('result'=>true); + } + + function append($key, $value) { + $ret = $this->redis->append($key, $value); + if ($ret == 0) return array ('result'=>false); + else return array('result'=> true); + } + + function exists($key) { + $ret = $this->redis->exists($key); + if ($ret == 0) return array ('result'=>false); + else return array('result'=> true); + } +} + +?>