static function init() { Autoloader::register(); $serversObj = config("rediscluster"); $servers = $serversObj->all(); $options = ['cluster' => 'redis']; return new Client($servers, $options); }
public function __construct() { \Predis\Autoloader::register(); $this->redis = new \Predis\Client(); $this->wx_auth_name = '__WX_AUTH_'; $this->wx_login_name = '__WX_LOGIN_'; $this->wx_numberid_name = '__WX_NUMBERID_'; parent::__construct(); }
function checkDriver() { try { \Predis\Autoloader::register(); } catch (Exception $e) { return false; } return true; }
public function ajaxPostChat(Request $request) { Predis\Autoloader::register(); try { $redis = new Client(); } catch (Exception $e) { die($e->getMessage()); } $redis->publish('chat-channel', json_encode($request->input('msg'))); return response()->json($request->input('msg')); }
/** * @return bool */ public function checkdriver() { // Check memcache if (!class_exists("\\Predis\\Client")) { $this->required_extension("predis-1.0/autoload"); try { \Predis\Autoloader::register(); } catch (\Exception $e) { } } return true; }
/** * Returns instance of Redis client * @param string $pathToAutoloader * @return Client redis object */ public function getRedis($pathToAutoloader = null) { if ($this->redis instanceof Client) { } else { if (null === $pathToAutoloader) { require "{$this->redisAutoloaderFile}"; } else { require "{$pathToAutoloader}"; } Autoloader::register(); $this->redis = new Client(); } return $this->redis; }
public function __construct() { \Predis\Autoloader::register(); $this->redis = new \Predis\Client(); $this->wx_auth_name = '__WX_AUTH_'; $this->wx_login_name = '__WX_LOGIN_'; $this->wx_numberid_name = '__WX_NUMBERID_'; parent::__construct(); if (!isWeiXinBrowser()) { $this->assign('tips', '请在微信浏览器中打开'); $this->display('WeiXin:result'); exit; } }
/** * 点赞一条feed */ public function praise() { $feedid = intval(I('post.feedid', '')); \Predis\Autoloader::register(); $redis = new \Predis\Client(); if ($redis->zscore('feed:' . $feedid . ':praise', ACPopedom::getID())) { $res = $redis->zrem('feed:' . $feedid . ':praise', ACPopedom::getID()); $rs = $redis->hincrby('feed:' . $feedid, 'praise', -1); $this->ajaxReturn($res && $rs ? array('status' => true) : array('status' => false, 'message' => '由于服务器君罢工,取消点赞失败失败啦..')); } else { $rs = $redis->zadd('feed:' . $feedid . ':praise', time(), ACPopedom::getID()); $result = $redis->hincrby('feed:' . $feedid, 'praise', 1); $this->ajaxReturn($result && $rs ? array('status' => true, 'message' => '点赞成功了,么么哒') : array('status' => false, 'message' => '由于服务器君罢工,点赞失败失败啦..')); } }
public function index() { \Predis\Autoloader::register(); $redis = new \Predis\Client(); $feedList = M('Feed')->alias('f')->field('f.feedid,f.posttime,f.show,f.content,f.picpath,f.appid,u.avator,u.nickname')->join(array('__USERS__ AS u ON f.userid = u.userid '))->where('f.userid = ' . ACPopedom::getID())->select(); foreach ($feedList as $key => $value) { $feedList[$key]['posttime'] = beforeTime($value['posttime']); if ($value['picpath']) { $feedList[$key]['picpath'] = explode('#$', $value['picpath']); $feedList[$key]['pic-col'] = count($feedList[$key]['picpath']) > 4 ? 3 : 12 / count($feedList[$key]['picpath']); } //取出点赞数 $praise = $redis->hget('feed:' . $value['feedid'], 'praise'); $feedList[$key]['praise'] = $praise ? $praise : 0; } //var_dump($feedList); $this->assign('feedlist', $feedList); $this->assign('userinfo', ACPopedom::getUserInfo()); $this->display(); }
public function QRcode() { \Predis\Autoloader::register(); $redis = new \Predis\Client(); //生成二维码 $numberid = M('randnumber')->add(array('openid' => '')); $token = base64_encode(authcode($numberid, "ENCODE", SESSION_AUTH)); //设置标志有效时间 $redis->setex('__WX_NUMBERID_' . $numberid, 300, 'true'); $rs = json_decode(Http::CurlRequst("http://api.wwei.cn/wwei", array("data" => $token, 'apikey' => 20150828111302), "GET"), true); $this->assign('erweima', $rs['data']['qr_filepath']); $this->assign('token', $token); $this->display(); }
<?php namespace Zule\Tools; require 'Predis/Autoloader.php'; \Predis\Autoloader::register(); class Predis { private static $adapters = array(); private function __construct() { } static function instance($named = 'default') { if (!isset($self->adapters[$named])) { // todo configure predis client. // right now I'm just trying to make it work :D self::$adapters[$named] = new \Predis\Client(); } return self::$adapters[$named]; } }
/** * 清除缓存,按需重载 * @param string $cachename * @return boolean */ protected function removeCache($cachename) { //TODO: remove cache implementation \Predis\Autoloader::register(); $redis = new \Predis\Client(); if ($redis->del($cachename)) { return true; } return false; }
/** *Saves the value in redis-server using Predis class object * */ private function saveUsingPredis() { require __DIR__ . "/../vendor/predis/predis/autoload.php"; \Predis\Autoloader::register(); $redis = new \Predis\Client(); if ($redis->get('counter') == NULL) { $redis->set('counter', 0); } else { $redis->incr('counter'); } $redis->set($redis->get('counter'), $this->value); }
private static function registCommonService($di, $config) { $di->setShared('config', $config); $di->setShared('profiler', function () { return new \Phalcon\Db\Profiler(); }); $di->setShared('modelsMetadata', function () use($di, $config) { if ('file' == $config->metaData->saveType) { $savePath = $config->metaData->savePath; if (!file_exists($savePath)) { mkdir($savePath, 0744, true); } $metaData = new \Phalcon\Mvc\Model\Metadata\Files(array('metaDataDir' => $savePath)); return $metaData; } }); $di->setShared('db_myPhalcon_w', function () use($di, $config) { $profiler = $di->getProfiler(); $eventsManager = new \Phalcon\Events\Manager(); $eventsManager->attach('db', function ($event, $connection) use($profiler) { if ($event->getType() == 'beforeQuery') { $profiler->startProfile($connection->getSQLStatement(), $connection->getSqlVariables(), $connection->getSQLBindTypes()); } if ($event->getType() == 'afterQuery') { $profiler->stopProfile(); $profile = $profiler->getLastProfile(); LoggerUtil::info(sprintf('SQL %s , cost time : %s', $profile->getSQLStatement(), $profile->getTotalElapsedSeconds())); } }); $db = new DbAdapter(array('host' => $config->mysql->myPhalcon_w->host, 'username' => $config->mysql->myPhalcon_w->username, 'password' => $config->mysql->myPhalcon_w->password, 'dbname' => $config->mysql->myPhalcon_w->dbname, 'port' => $config->mysql->myPhalcon_w->port)); $db->setEventsManager($eventsManager); return $db; }); $di->setShared('db_myPhalcon_r', function () use($di, $config) { $profiler = $di->getProfiler(); $eventsManager = new \Phalcon\Events\Manager(); $eventsManager->attach('db', function ($event, $connection) use($profiler) { if ($event->getType() == 'beforeQuery') { $profiler->startProfile($connection->getSQLStatement(), $connection->getSqlVariables(), $connection->getSQLBindTypes()); } if ($event->getType() == 'afterQuery') { $profiler->stopProfile(); $profile = $profiler->getLastProfile(); LoggerUtil::info(sprintf('SQL: %s , COST TIME: %s', $profile->getSQLStatement(), $profile->getTotalElapsedSeconds())); } }); $db = new DbAdapter(array('host' => $config->mysql->myPhalcon_r->host, 'username' => $config->mysql->myPhalcon_r->username, 'password' => $config->mysql->myPhalcon_r->password, 'dbname' => $config->mysql->myPhalcon_r->dbname, 'port' => $config->mysql->myPhalcon_r->port)); $db->setEventsManager($eventsManager); return $db; }); $di->setShared('redisCache', function () use($di, $config) { require VENDOR_PATH . '/predis/Autoloader.php'; \Predis\Autoloader::register(); $host = $config->redisCache->host; $port = $config->redisCache->port; return new \Predis\Client("tcp://{$host}:{$port}"); }); $di->setShared('curl', function () use($di, $config) { require VENDOR_PATH . '/Curl/Autoloader.php'; \Curl\Autoloader::register(); return new \Curl\Curl(); }); $di->setShared('image', function () use($di, $config) { require VENDOR_PATH . '/Image/Autoloader.php'; \Image\Autoloader::register(); return new \Image\Image(\Image\Image::IMAGE_IMAGICK); }); }
protected function newConnection() { Predis\Autoloader::register(); $connection = new Predis\Client(['scheme' => 'tcp', 'host' => '192.168.33.10', 'port' => '6379']); return $connection; }