Skip to content

weixinhost/redissession

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

redissession

-- import "github.com/weixinhost/redissession"

Usage

const (
       	DefaultRedisHost = "127.0.0.1:6379"
       	DefaultRedisDB   = 13
       	DefaultPrefix    = "redissession-"
       	DefaultLifeTime  = 3600 * time.Second
)

####type RedisSession

type RedisSession struct {
}

func (*RedisSession) Delete

func (session *RedisSession) Delete(key string) bool

Delete. delete a session key.

func (*RedisSession) Destory

func (session *RedisSession) Destory() bool

Destory Destory all session data

func (*RedisSession) Get

func (session *RedisSession) Get(key string) interface{}

Get. returns nil if data not exists.

func (*RedisSession) GetSessionID

func (session *RedisSession) GetSessionID() string

GetSessionID get session id

func (*RedisSession) Set

func (session *RedisSession) Set(key string, val interface{}) bool

Set set a session data.

func (*RedisSession) SetSessionID

func (session *RedisSession) SetSessionID(sid string) bool

SetSessionID set custom session id

func (*RedisSession) Start

func (session *RedisSession) Start() bool

Start.Call Start before Any thing.

func (*RedisSession) Store

func (session *RedisSession) Store() bool

Store. store session changes to redis.

####type Session

type Session interface {
       	//SetSessionID set custom session id.default is uuid-v4 string.
       	SetSessionID(sid string) bool
       	//get session id
       	GetSessionID() string
       	Start() bool
       	Destory() bool
       	Set(key string, val interface{}) bool
       	Get(key string) interface{}
       	Delete(key string) bool
       	Store() bool
}

func NewSession

func NewSession(engine string, config *SessionConfig) Session

NewSession get a redis session instance.

####type SessionConfig

type SessionConfig struct {
       	RedisHost string        //redis host.default is (127.0.0.1:6379)
       	RedisDB   int           //redis db.default is 13
       	Prefix    string        //redis session key prefix. default is `redissession-`
       	LifeTime  time.Duration //session lifetime.defualt is 1 hour.
        RedisPassword string        //redis Password if needs
}

About

a temp storage wrap engine for redis.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages