// SET key value [EX seconds] [PX milliseconds] [NX|XX] func SetCmd(s Session, args [][]byte) (redis.Resp, error) { if err := s.Store().Set(s.DB(), args); err != nil && errors2.ErrorNotEqual(err, store.ErrSetAborted) { return toRespError(err) } else if errors2.ErrorEqual(err, store.ErrSetAborted) { return redis.NewBulkBytes(nil), nil } else { return redis.NewString("OK"), nil } }
func (s *Server) handleConn(c net.Conn) { log.Info("new connection", c.RemoteAddr()) s.counter.Add("connections", 1) client := &session{ Conn: c, r: bufio.NewReaderSize(c, DefaultReaderSize), w: bufio.NewWriterSize(c, DefaultWiterSize), CreateAt: time.Now(), backQ: make(chan *PipelineResponse, PipelineResponseNum), closeSignal: &sync.WaitGroup{}, authenticated: false, } client.closeSignal.Add(1) go client.WritingLoop() var err error defer func() { client.closeSignal.Wait() //waiting for writer goroutine if errors2.ErrorNotEqual(err, io.EOF) { log.Warningf("close connection %v, %v", client, errors.ErrorStack(err)) } else { log.Infof("close connection %v", client) } s.counter.Add("connections", -1) }() for { err = s.redisTunnel(client) if err != nil { close(client.backQ) return } client.Ops++ } }