1 Star 0 Fork 0

LeeGene / gession

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Gession会话框架

Gitee link address Github link address Go Version Release Version

  1. Gession是一个会话框架。
  2. 可用于HTTP/HTTPS网络连接的会话保持。
  3. 内置对接Redis接口,连接保存Session到Redis。
  4. 操作极其方便,易上手,源码易懂有注释。

安装

$ go get -u github.com/wangluozhe/gession

依赖

Redigo v1.8.5 go.uuid v1.2.0

导入

import(
    "github.com/wangluozhe/gession/session"
)

初始化Session管理器

Session管理器用于管理Session的各种操作,如:New/Get/Del。 Session管理器变量名:session.Ssmgr

Redis方式:

host := "host"				    // Redis地址
port := 6379				    // Redis端口
password := "password"		    // Redis密码
database := 1				    // Redis库
pool := session.NewRedisPool(host, int(port), password, int(database))		// 创建Redis连接池
expire := 1000				    // Session过期时间
session.Init(pool, expire)	    // 初始化Session管理器
Ssmgr := session.Ssmgr		    // 全局可用,可以直接操作session.Ssmgr也可以赋值后在操作,Ssmgr是Session组管理器,用来创建/读取/删除Session

内存方式:

session.Init()                  // 初始化Session管理器
Ssmgr := session.Ssmgr		    // 全局可用,可以直接操作session.Ssmgr也可以赋值后在操作,Ssmgr是Session组管理器,用来创建/读取/删除Session

创建Session

ss := Ssmgr.New()			    // 创建Session

读取Session

ss,err := Ssmgr.Get(sessionId)  // 读取Session,如果内存中没有此Session会从Redis中读取,都没有返回nil
if err != nil{
    fmt.Println(err)
}

删除Session

ss,err := Ssmgr.Del(sessionId)  // 删除Session,内存和Redis中的此Session都会被删除
if err != nil{
    fmt.Println(err)
}

Session操作

Session操作只有四种操作,简单方便,存储的是map类型,有:Set/Get/Del/Save。

设置Session值

ss.Set(key,value)               // 设置Session中的值
// 或
isSuccess := ss.Set(key,value)  // 返回一个是否设置成功的bool值

获取Session值

result := ss.Get(key)           // 获取Session中的值

删除Session值

ss.Del(key)                     // 删除Session中的值
// 或
isSuccess := ss.Del(key)        // 返回一个是否删除成功的bool值

保存Session到Redis中

isSuccess,err := ss.Save()      // 保存此Session到Redis中
if err != nil{
    fmt.Println(err)
}
MIT License Copyright (c) 2021 LeeGene Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Golang语言编写的Session框架,适用于所有Golang的WEB开发框架使用。 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/leegene/gession.git
git@gitee.com:leegene/gession.git
leegene
gession
gession
main

搜索帮助