跳到主要内容

cache 操作 Redis

setSession() 用于数据保存到 Redis。

luwak.cache("get", key: string): string;
luwak.cache("set", key: string, value: any, expire?: number): void;
luwak.cache("del", key: string): void;
luwak.cache("exists", key: string): number; // 1 存在,0 不存在
luwak.cache("expire", key: string, expire: number): void;

何时使用

  • 临时保存短信验证码

代码演示

脚本代码

var key = "prefix:sms:123456789";
var value = 99887;
var expire = 300;
var expire2 = 900;

// 保存手机验证码,300秒有效, 省略最后一个参数表示永久有效
luwak.cache("set", key, value, expire);

// 更新有效期为900秒
luwak.cache("expire", key, expire2);

// 读取验证码
luwak.cache("get", key);

// 删除验证码
luwak.cache("del", key);

// 是否存在
luwak.cache("exists", key);