// read redis session by sid func (rp *MemProvider) SessionRead(sid string) (session.SessionStore, error) { conn, err := rp.connectInit() if err != nil { return nil, err } kvs, err := conn.Get(sid) if err != nil { return nil, err } var contain []byte if len(kvs) > 0 { contain = kvs[0].Value } var kv map[interface{}]interface{} if len(contain) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(contain) if err != nil { return nil, err } } rs := &MemcacheSessionStore{c: conn, sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil }
func (cp *CouchbaseProvider) SessionRegenerate(oldsid, sid string) (session.SessionStore, 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 := &CouchbaseSessionStore{b: cp.b, sid: sid, values: kv, maxlifetime: cp.maxlifetime} return cs, nil }
// generate new sid for redis session func (rp *RedisProvider) SessionRegenerate(oldsid, sid string) (session.SessionStore, 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 := &RedisSessionStore{p: rp.poollist, sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil }
// generate new sid for redis session func (rp *MemProvider) SessionRegenerate(oldsid, sid string) (session.SessionStore, error) { conn, err := rp.connectInit() if err != nil { return nil, err } var contain []byte if kvs, err := conn.Get(sid); err != nil || len(kvs) == 0 { // oldsid doesn't exists, set the new sid directly // ignore error here, since if it return error // the existed value will be 0 conn.Set(sid, 0, uint64(rp.maxlifetime), []byte("")) } else { conn.Delete(oldsid) conn.Set(sid, 0, uint64(rp.maxlifetime), kvs[0].Value) contain = kvs[0].Value } var kv map[interface{}]interface{} if len(contain) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(contain) if err != nil { return nil, err } } rs := &MemcacheSessionStore{c: conn, sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil }
// get postgresql session by sid func (mp *PostgresqlProvider) SessionRead(sid string) (session.SessionStore, 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 := &PostgresqlSessionStore{c: c, sid: sid, values: kv} 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 }
func (p *SsdbProvider) SessionRegenerate(oldsid, sid string) (session.Store, error) { //conn.Do("setx", key, v, ttl) if p.client == nil { if err := p.connectInit(); err != nil { return nil, err } } value, err := p.client.Get(oldsid) if err != nil { return nil, err } var kv map[interface{}]interface{} if value == nil || len(value.(string)) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob([]byte(value.(string))) if err != nil { return nil, err } _, err = p.client.Del(oldsid) if err != nil { return nil, err } } _, e := p.client.Do("setx", sid, value, p.maxLifetime) if e != nil { return nil, e } rs := &SessionStore{sid: sid, values: kv, maxLifetime: p.maxLifetime, client: p.client} return rs, 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 }
// read redis session by sid func (rp *RedisProvider) SessionRead(sid string) (session.SessionStore, 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 := &RedisSessionStore{p: rp.poollist, sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil }
// read couchbase session by sid func (cp *CouchbaseProvider) SessionRead(sid string) (session.SessionStore, 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 := &CouchbaseSessionStore{b: cp.b, sid: sid, values: kv, maxlifetime: cp.maxlifetime} return cs, nil }
// generate new sid for mysql session func (mp *MysqlProvider) SessionRegenerate(oldsid, sid string) (session.SessionStore, error) { c := mp.connectInit() row := c.QueryRow("select session_data from session where session_key=?", oldsid) var sessiondata []byte err := row.Scan(&sessiondata) if err == sql.ErrNoRows { c.Exec("insert into session(`session_key`,`session_data`,`session_expiry`) values(?,?,?)", oldsid, "", time.Now().Unix()) } c.Exec("update session 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 := &MysqlSessionStore{c: c, sid: sid, values: kv} return rs, nil }
func (p *SsdbProvider) SessionRead(sid string) (session.Store, error) { if p.client == nil { if err := p.connectInit(); err != nil { return nil, err } } var kv map[interface{}]interface{} value, err := p.client.Get(sid) if err != nil { return nil, err } if value == nil || len(value.(string)) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob([]byte(value.(string))) if err != nil { return nil, err } } rs := &SessionStore{sid: sid, values: kv, maxLifetime: p.maxLifetime, client: p.client} return rs, nil }
// generate new sid for memcache session func (rp *MemProvider) SessionRegenerate(oldsid, sid string) (session.SessionStore, 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.Value = item.Value 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 := &MemcacheSessionStore{sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil }
// read memcache session by sid func (rp *MemProvider) SessionRead(sid string) (session.SessionStore, error) { if client == nil { if err := rp.connectInit(); err != nil { return nil, err } } item, err := client.Get(sid) if err != nil { return nil, err } 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 := &MemcacheSessionStore{sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil }