ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
| 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); } } } ```