// SessionRegenerate remove oldsid and use sid to generate new session func (cp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) { cp.b = cp.getBucket() var doc []byte if err := cp.b.Get(oldsid, &doc); err != nil || doc == nil { cp.b.Set(sid, int(cp.maxlifetime), "") } else { err := cp.b.Delete(oldsid) if err != nil { return nil, err } _, _ = cp.b.Add(sid, int(cp.maxlifetime), doc) } err := cp.b.Get(sid, &doc) if err != nil { return nil, err } var kv map[interface{}]interface{} if doc == nil { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(doc) if err != nil { return nil, err } } cs := &SessionStore{b: cp.b, sid: sid, values: kv, maxlifetime: cp.maxlifetime} return cs, nil }
// SessionRead get postgresql session by sid func (mp *Provider) SessionRead(sid string) (session.Store, error) { c := mp.connectInit() row := c.QueryRow("select session_data from session where session_key=$1", sid) var sessiondata []byte err := row.Scan(&sessiondata) if err == sql.ErrNoRows { _, err = c.Exec("insert into session(session_key,session_data,session_expiry) values($1,$2,$3)", sid, "", time.Now().Format(time.RFC3339)) if err != nil { return nil, err } } else if err != nil { return nil, err } var kv map[interface{}]interface{} if len(sessiondata) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(sessiondata) if err != nil { return nil, err } } rs := &SessionStore{c: c, sid: sid, values: kv} return rs, nil }
// SessionRegenerate generate new sid for redis session func (rp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) { c := rp.poollist.Get() defer c.Close() if existed, _ := redis.Int(c.Do("EXISTS", oldsid)); existed == 0 { // oldsid doesn't exists, set the new sid directly // ignore error here, since if it return error // the existed value will be 0 c.Do("SET", sid, "", "EX", rp.maxlifetime) } else { c.Do("RENAME", oldsid, sid) c.Do("EXPIRE", sid, rp.maxlifetime) } kvs, err := redis.String(c.Do("GET", sid)) var kv map[interface{}]interface{} if len(kvs) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob([]byte(kvs)) if err != nil { return nil, err } } rs := &SessionStore{p: rp.poollist, sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil }
// SessionRegenerate generate new sid for ledis session func (lp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) { count, _ := c.Exists([]byte(sid)) if count == 0 { // oldsid doesn't exists, set the new sid directly // ignore error here, since if it return error // the existed value will be 0 c.Set([]byte(sid), []byte("")) c.Expire([]byte(sid), lp.maxlifetime) } else { data, _ := c.Get([]byte(oldsid)) c.Set([]byte(sid), data) c.Expire([]byte(sid), lp.maxlifetime) } kvs, err := c.Get([]byte(sid)) var kv map[interface{}]interface{} if len(kvs) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob([]byte(kvs)) if err != nil { return nil, err } } ls := &SessionStore{sid: sid, values: kv, maxlifetime: lp.maxlifetime} return ls, nil }
// SessionRead read ledis session by sid func (lp *Provider) SessionRead(sid string) (session.Store, error) { kvs, err := c.Get([]byte(sid)) var kv map[interface{}]interface{} if len(kvs) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(kvs) if err != nil { return nil, err } } ls := &SessionStore{sid: sid, values: kv, maxlifetime: lp.maxlifetime} return ls, nil }
// SessionRead read redis session by sid func (rp *Provider) SessionRead(sid string) (session.Store, error) { c := rp.poollist.Get() defer c.Close() kvs, err := redis.String(c.Do("GET", sid)) var kv map[interface{}]interface{} if len(kvs) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob([]byte(kvs)) if err != nil { return nil, err } } rs := &SessionStore{p: rp.poollist, sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil }
// SessionRead read couchbase session by sid func (cp *Provider) SessionRead(sid string) (session.Store, error) { cp.b = cp.getBucket() var doc []byte err := cp.b.Get(sid, &doc) var kv map[interface{}]interface{} if doc == nil { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(doc) if err != nil { return nil, err } } cs := &SessionStore{b: cp.b, sid: sid, values: kv, maxlifetime: cp.maxlifetime} return cs, nil }
// SessionRegenerate generate new sid for mysql session func (mp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) { c := mp.connectInit() row := c.QueryRow("select session_data from "+TableName+" where session_key=?", oldsid) var sessiondata []byte err := row.Scan(&sessiondata) if err == sql.ErrNoRows { c.Exec("insert into "+TableName+"(`session_key`,`session_data`,`session_expiry`) values(?,?,?)", oldsid, "", time.Now().Unix()) } c.Exec("update "+TableName+" set `session_key`=? where session_key=?", sid, oldsid) var kv map[interface{}]interface{} if len(sessiondata) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(sessiondata) if err != nil { return nil, err } } rs := &SessionStore{c: c, sid: sid, values: kv} return rs, nil }
// SessionRead read memcache session by sid func (rp *MemProvider) SessionRead(sid string) (session.Store, error) { if client == nil { if err := rp.connectInit(); err != nil { return nil, err } } item, err := client.Get(sid) if err != nil && err == memcache.ErrCacheMiss { rs := &SessionStore{sid: sid, values: make(map[interface{}]interface{}), maxlifetime: rp.maxlifetime} return rs, nil } var kv map[interface{}]interface{} if len(item.Value) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(item.Value) if err != nil { return nil, err } } rs := &SessionStore{sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil }
// SessionRegenerate generate new sid for memcache session func (rp *MemProvider) SessionRegenerate(oldsid, sid string) (session.Store, error) { if client == nil { if err := rp.connectInit(); err != nil { return nil, err } } var contain []byte if item, err := client.Get(sid); err != nil || len(item.Value) == 0 { // oldsid doesn't exists, set the new sid directly // ignore error here, since if it return error // the existed value will be 0 item.Key = sid item.Value = []byte("") item.Expiration = int32(rp.maxlifetime) client.Set(item) } else { client.Delete(oldsid) item.Key = sid item.Expiration = int32(rp.maxlifetime) client.Set(item) contain = item.Value } var kv map[interface{}]interface{} if len(contain) == 0 { kv = make(map[interface{}]interface{}) } else { var err error kv, err = session.DecodeGob(contain) if err != nil { return nil, err } } rs := &SessionStore{sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil }