Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ThinkJS框架中redis的简单使用 #1

@webplus

Description

@webplus

redis可视化工具
redis-windows
redis安装包
node_redis驱动
thinkjs中redis配置

thinkjs设置缓存并修改缓存类型:

export default class extends think.controller.base {
  * indexAction(){
    //设置缓存,缓存类型使用redis
    yield this.cache("name", "value", {
      type: "redis"
    });
  }
}

如何使用redis缓存

//获取缓存
think.cache("name").then(data => {});

//指定缓存类型获取,从 redis 里获取缓存
think.cache("name", undefined, {type: "redis"});

//如果缓存 userList 不存在,则查询数据库,并将值设置到缓存中
think.cache("userList", () => {
  return think.model("user").select();
});

//设置缓存
think.cache("name", "value");

//删除缓存
think.cache("name", null);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions