session

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: MIT Imports: 9 Imported by: 0

README

session

开始使用

import (
    "github.com/ZR233/session"
    "github.com/go-redis/redis"
    "github.com/ZR233/session/serr"
)

client := redis.NewClient(&redis.Options{
    Addr:     "localhost",
})
profix = "test_project_session"
db := session.NewRedisAdapter(redis.GetRedis(), profix)
sessionManager := session.NewManager(db)

userId := "1"
src := "pc"
expireAt := time.Now().Add(time.Hour*24*5)

//新建session
sess, err := sessionManager.CreateSession(userId, src, expireAt)
if err != nil {
    panic(err)
}

//查找session
sess, err := sessionManager.FindByToken(token)
if err != nil{
    if err == serr.TokenNotFound {
        println(err)
    }else{
        panic(err)
    }
}

Documentation

Overview

@Time : 2019-07-12 16:30 @Author : zr

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedisAdapter

func NewRedisAdapter(options *redis.UniversalOptions, prefix string) adapter.Redis

Types

type Manager

type Manager struct {
	Prefix string
	// contains filtered or unexported fields
}

func NewManager

func NewManager(db adapter.DB) *Manager

func (Manager) CreateSession

func (m Manager) CreateSession(userId string, channel string, expireAt time.Time) (s *model.Session, err error)

func (Manager) Delete

func (m Manager) Delete(s *model.Session) error

func (Manager) DeleteByUser

func (m Manager) DeleteByUser(id string) error

func (Manager) FindByToken

func (m Manager) FindByToken(token string) (s *model.Session, err error)

func (Manager) GetUserAllSessions

func (m Manager) GetUserAllSessions(userId string) (sessions []*model.Session, err error)

func (Manager) Update

func (m Manager) Update(s *model.Session) error

Directories

Path Synopsis
@Time : 2019-07-12 16:42 @Author : zr @Time : 2019-07-12 16:34 @Author : zr
@Time : 2019-07-12 16:42 @Author : zr @Time : 2019-07-12 16:34 @Author : zr
@Time : 2019-07-12 16:39 @Author : zr
@Time : 2019-07-12 16:39 @Author : zr
@Time : 2019-07-12 17:28 @Author : zr
@Time : 2019-07-12 17:28 @Author : zr

Jump to

Keyboard shortcuts

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