NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
| TP5中使用Redis | | | --- | --- | ``` <?php namespace app\admin\controller; use think\Db; use think\facade\Env; use think\Request; use think\facade\Validate; use think\facade\Cache; /** * 初始化redis */ class Index extends Controller{ protected static $redis; /** * [_initialize 初始化函数] * @return [type] [description] */ public function _initialize() { if (!(self::$redis instanceof \Redis)) { self::$redis = new \Redis(); self::$redis->connect('127.0.0.1', 6379); } } /** * [redisAction Redis的基本操作] * @return [type] [description] */ public function redisAction() { //从redis中获取一个订单号 $order=self::$redis->lpop("OA_PACKET_ORDER_NO_".date("ymd")); } /** * [getRedis 实例化redis和连接redis] * @return [type] [description] */ protected static function getRedis() { if (!(self::$redis instanceof \Redis)) { self::$redis = new \Redis(); self::$redis->connect('127.0.0.1', 6379); } } } ```