// Regenerate regenerates a session store from old session ID to new one. func (p *MemcacheProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err error) { if p.Exist(sid) { return nil, fmt.Errorf("new sid '%s' already exists", sid) } item := NewItem(sid, []byte(""), p.expire) if p.Exist(oldsid) { item, err = p.c.Get(oldsid) if err != nil { return nil, err } else if err = p.c.Delete(oldsid); err != nil { return nil, err } item.Key = sid } if err = p.c.Set(item); 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 } } return NewMemcacheStore(p.c, sid, p.expire, kv), nil }
// Regenerate regenerates a session store from old session ID to new one. func (p *RedisProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err error) { poldsid := p.prefix + oldsid psid := p.prefix + sid if p.Exist(sid) { return nil, fmt.Errorf("new sid '%s' already exists", sid) } else if !p.Exist(oldsid) { // Make a fake old session. if err = p.c.SetEx(poldsid, p.duration, "").Err(); err != nil { return nil, err } } if err = p.c.Rename(poldsid, psid).Err(); err != nil { return nil, err } var kv map[interface{}]interface{} kvs, err := p.c.Get(psid).Result() if err != nil { return nil, err } if len(kvs) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob([]byte(kvs)) if err != nil { return nil, err } } return NewRedisStore(p.c, p.prefix, sid, p.duration, kv), nil }
// Regenerate regenerates a session store from old session ID to new one. func (p *LedisProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err error) { if p.Exist(sid) { return nil, fmt.Errorf("new sid '%s' already exists", sid) } kvs := make([]byte, 0) if p.Exist(oldsid) { if kvs, err = p.c.Get([]byte(oldsid)); err != nil { return nil, err } else if _, err = p.c.Del([]byte(oldsid)); err != nil { return nil, err } } if err = p.c.SetEX([]byte(sid), p.expire, kvs); err != nil { return nil, err } 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 } } return NewLedisStore(p.c, sid, p.expire, kv), nil }
// Regenerate regenerates a session store from old session ID to new one. func (p *CouchbaseProvider) Regenerate(oldsid, sid string) (session.RawStore, error) { p.b = p.getBucket() var doc []byte if err := p.b.Get(oldsid, &doc); err != nil || doc == nil { p.b.Set(sid, int(p.maxlifetime), "") } else { err := p.b.Delete(oldsid) if err != nil { return nil, err } _, _ = p.b.Add(sid, int(p.maxlifetime), doc) } err := p.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: p.b, sid: sid, data: kv, maxlifetime: p.maxlifetime} return cs, nil }
// Read returns raw session store by session ID. func (p *CouchbaseProvider) Read(sid string) (session.RawStore, error) { p.b = p.getBucket() var doc []byte err := p.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: p.b, sid: sid, data: kv, maxlifetime: p.maxlifetime} return cs, nil }
// Read returns raw session store by session ID. func (p *PostgresProvider) Read(sid string) (session.RawStore, error) { var data []byte err := p.c.QueryRow("SELECT data FROM session WHERE key=$1", sid).Scan(&data) if err == sql.ErrNoRows { _, err = p.c.Exec("INSERT INTO session(key,data,expiry) VALUES($1,$2,$3)", sid, "", time.Now().Unix()) } if err != nil { return nil, err } var kv map[interface{}]interface{} if len(data) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(data) if err != nil { return nil, err } } return NewPostgresStore(p.c, sid, kv), nil }
// Read returns raw session store by session ID. func (p *MemcacheProvider) Read(sid string) (session.RawStore, error) { if !p.Exist(sid) { if err := p.c.Set(NewItem(sid, []byte(""), p.expire)); err != nil { return nil, err } } var kv map[interface{}]interface{} item, err := p.c.Get(sid) if err != nil { return nil, err } if len(item.Value) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(item.Value) if err != nil { return nil, err } } return NewMemcacheStore(p.c, sid, p.expire, kv), nil }
// Read returns raw session store by session ID. func (p *LedisProvider) Read(sid string) (session.RawStore, error) { if !p.Exist(sid) { if err := p.c.Set([]byte(sid), []byte("")); err != nil { return nil, err } } var kv map[interface{}]interface{} kvs, err := p.c.Get([]byte(sid)) if err != nil { return nil, err } if len(kvs) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(kvs) if err != nil { return nil, err } } return NewLedisStore(p.c, sid, p.expire, kv), nil }
// Read returns raw session store by session ID. func (p *RedisProvider) Read(sid string) (session.RawStore, error) { psid := p.prefix + sid if !p.Exist(sid) { if err := p.c.Set(psid, "").Err(); err != nil { return nil, err } } var kv map[interface{}]interface{} kvs, err := p.c.Get(psid).Result() if err != nil { return nil, err } if len(kvs) == 0 { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob([]byte(kvs)) if err != nil { return nil, err } } return NewRedisStore(p.c, p.prefix, sid, p.duration, kv), nil }