使用ThinkPHP3.2框架怎么对Redis进行操作

使用ThinkPHP3.2框架怎么对Redis进行操作

这篇文章给大家介绍使用ThinkPHP3.2框架怎么对Redis进行操作,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
  public function index() {
   // 配置 redis 缓存
   $set = array(
   'type' =>'redis' ,
   'host'=>'127.0.0.1' ,
   'port'=>6379,
   );
   // 实例化
   $redis=S($set);
   // 存储数据
   $redis->name="hello world again";
   $redis->id=1;
  }
}

之后我们到 redis-cli.exe 中查看以下存储的结果:

使用ThinkPHP3.2框架怎么对Redis进行操作

接下来换种方式存储:

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
  public function index() {
   // 配置 redis 缓存
   $set = array(
   'type' =>'redis' ,
   'host'=>'127.0.0.1' ,
   'port'=>6379,
   );
   // 设置要存储的数据
   $message = array(
   'name' =>'yang' ,
   'id'=>1
    );
   // 缓存
   S('message',$message,$set);
  }
}

再来查看缓存结果:

使用ThinkPHP3.2框架怎么对Redis进行操作

关于使用ThinkPHP3.2框架怎么对Redis进行操作就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。