本文整理匯總了Golang中github.com/philpearl/tt_goji_middleware/base.Session.Id方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Id方法的具體用法?Golang Session.Id怎麽用?Golang Session.Id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/philpearl/tt_goji_middleware/base.Session
的用法示例。
在下文中一共展示了Session.Id方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ResetTTL
func (sh *SessionHolder) ResetTTL(c web.C, session *base.Session) error {
sessionId := session.Id()
conn := c.Env["redis"].(redigo.Conn)
_, err := conn.Do("EXPIRE", sessionKey(sessionId), sh.Timeout)
return err
}
示例2: Destroy
/*
Destroy deletes a session from redis
*/
func (sh *SessionHolder) Destroy(c web.C, session *base.Session) error {
sessionId := session.Id()
delete(c.Env, "session")
conn := c.Env["redis"].(redigo.Conn)
_, err := conn.Do("DEL", sessionKey(sessionId))
return err
}
示例3: Save
/*
Save a session to postgres
*/
func (sh *SessionHolder) Save(c web.C, session *base.Session) error {
sessionId := session.Id()
// There is a potential race here if the insert fails because the session exists, but it is deleted
// before we can update it.
_, err := sh.db.Exec("INSERT INTO sessions (id, content, expires) VALUES ($1, $2, now() + $3 * interval '1 second')", sessionId, sessionValues(session.Values), sh.Timeout)
if err != nil && isAlreadyExists(err, "sessions") {
_, err = sh.db.Exec("UPDATE sessions SET content=$2, expires=now() + $3 * interval '1 second' WHERE id=$1", sessionId, sessionValues(session.Values), sh.Timeout)
}
return err
}
示例4: RegenerateId
func (sh *SessionHolder) RegenerateId(c web.C, session *base.Session) (string, error) {
sessionId := session.Id()
newSessionId := sh.GenerateSessionId()
conn := c.Env["redis"].(redigo.Conn)
_, err := conn.Do("RENAME", sessionKey(sessionId), sessionKey(newSessionId))
if err == nil {
/* renaming of session key succeeded in backend... update sessionId in our struct */
session.SetId(newSessionId)
} else {
newSessionId = sessionId
}
return newSessionId, err
}