session

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2014 License: GPL-3.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	SESSION_STATE_INIT     = "init"
	SESSION_STATE_ACTIVE   = "active"
	SESSION_STATE_INACTIVE = "inactive"

	INSERT_SESSION          = "INSERT INTO `session`(`id`,`type`,`user_id`,`state`,`created`,`updated`)  VALUES (?,?,?,?,?,?) "
	DELETE_SESSION_BYID     = "DELETE FROM `session` WHERE `id`=?"
	DELETE_SESSION_BYUSERID = "DELETE FROM `session` WHERE `user_id`=?"
	UPDATE_SESSION_UPDATED  = "UPDATE `session` SET `updated` = ?  WHERE `id`=? "
	UPDATE_SESSION_STATE    = "UPDATE `session` SET `state` = ?  WHERE `id`=? "
	DELETE_SESSION_PAST     = "DELETE  FROM `session` WHERE  `updated` < ?"
	SET_USERID              = "UPDATE `session` SET  `user_id` = ? WHERE  `id` = ?"
	SELECT_SESSION_BYSTATE  = "SELECT  `id`,`type`,`user_id`,`state`,`created`,`updated` FROM SESSION WHERE `user_id`=?  AND `state`=?"
	SELECT_SESSION_BYUSERID = "SELECT  `id`,`type`,`user_id`,`state`,`created`,`updated` FROM SESSION WHERE `user_id` = ?"
	SELECT_SESSION_BYID     = "SELECT  `id`,`type`,`user_id`,`state`,`created`,`updated` FROM SESSION WHERE `id`=?"
	SELECT_SESSION_BYIDS    = "SELECT  `id`,`type`,`user_id`,`state`,`created`,`updated` FROM SESSION WHERE `id`IN (?)"
	EXIST_SESSION           = "SELECT id FROM session WHERE id = ?"
)

Variables

View Source
var ScanSessionTime = time.NewTicker(168 * time.Hour)

一个星期扫描一次

Functions

func CreatSession

func CreatSession(session *Session) bool

创建会话session记录

func GetSessionsByUserId

func GetSessionsByUserId(userId string) (*[]Session, error)

通过userd查询会话session

func IsExistSession added in v1.2.0

func IsExistSession(sessionId string) bool

func RemoveSessionById

func RemoveSessionById(id string) bool

删除会话session记录

func RemoveSessionByUserId

func RemoveSessionByUserId(usreId string) bool

删除会话session记录

func ScanSession

func ScanSession()

/除过时的会话,当更新时间距当前时间超过24 小时,就将该会话移除

func SetSessionStat

func SetSessionStat(sessionId, state string) bool

更新会话状态

func TickerTaskUpdateSession

func TickerTaskUpdateSession(sessionId string, tickerFlagStop chan bool)

定时更新会话session时间

func UpdateSessionUpdated

func UpdateSessionUpdated(sessionId string, updated time.Time) bool

更新会话session的最新时间

func UpdateSessionUserID

func UpdateSessionUserID(sessionId, userId string) bool

修改会话session记录

Types

type Session

type Session struct {
	Id      string    `json:"id"`
	Type    string    `json:"type"`
	UserId  string    `json:"userId"`
	State   string    `json:"sate"`
	Created time.Time `json:"created"`
	Updated time.Time `json:"updated"`
}

func GetSessions

func GetSessions(uid string, args []string) []*Session

根据 args 参数获取用户 uid 的会话集.

args 参数:

  1. ["all"] 表示获取该用户所有的会话
  2. ["xxx1", "xxx2"] 表示获取该用户 xxx1、xxx2 会话
  3. ["active"] 表示获取该用户的所有激活的会话
  4. [inactive"] 表示获取该用户的所有非激活的会话

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL