func NewSession(c net.Conn) *Session { s := &Session{Sid: sessions.sid.Incr(), CreateUnix: time.Now().Unix()} s.Conn = redis.NewConn(c) s.Conn.ReaderTimeout = time.Minute * 30 s.Conn.WriterTimeout = time.Second * 30 return addToSessions(s) }
func NewSession(c net.Conn) *Session { s := &Session{CreateUnix: time.Now().Unix()} s.Conn = redis.NewConn(c) s.Conn.ReaderTimeout = time.Minute * 30 s.Conn.WriterTimeout = time.Second * 30 log.Infof("session [%p] create: %s", s, s) return s }
func TestBackend(t *testing.T) { l, err := net.Listen("tcp", "127.0.0.1:0") assert.MustNoError(err) defer l.Close() addr := l.Addr().String() reqc := make(chan *Request, 16384) go func() { bc := NewBackendConn(addr) defer bc.Close() defer close(reqc) var resp = redis.NewBulkBytes(make([]byte, 4096)) for i := 0; i < cap(reqc); i++ { r := &Request{ Resp: resp, Wait: &sync.WaitGroup{}, } r.Wait.Add(1) bc.PushBack(r) reqc <- r } }() go func() { c, err := l.Accept() assert.MustNoError(err) defer c.Close() conn := redis.NewConn(c) time.Sleep(time.Millisecond * 300) for i := 0; i < cap(reqc); i++ { _, err := conn.Reader.Decode() assert.MustNoError(err) resp := redis.NewString([]byte(strconv.Itoa(i))) assert.MustNoError(conn.Writer.Encode(resp, true)) } }() var n int for r := range reqc { r.Wait.Wait() assert.Must(string(r.Response.Resp.Value) == strconv.Itoa(n)) n++ } assert.Must(n == cap(reqc)) }