openresty 学习笔记六:使用session库

2023-05-11,,

openresty 学习笔记六:使用session

lua-resty-session 是一个面向 OpenResty 的安全和灵活的 session 库,它实现了 Secure Cookie Protocol。
项目地址:https://github.com/bungle/lua-resty-session

使用方法有很多种,我这里只使用简单的用redis存储session

先要修改redis配置文件vim /usr/local/redis/etc/redis.conf,开启unix socket

unixsocket /tmp/redis.sock
unixsocketperm 777

并在nginx.conf上添加配置

server
{
set $session_storage redis;
set $session_redis_prefix sessions;
set $session_redis_socket unix:///tmp/redis.sock;
set $session_redis_host 127.0.0.1;
set $session_redis_port 6379;
}

使用方法

local session = require "resty.session".open()
session.data.xxx = abc
session:save()

openresty 学习笔记六:使用session库的相关教程结束。

《openresty 学习笔记六:使用session库.doc》

下载本文的Word格式文档,以方便收藏与打印。