示例#1
0
func (s *Session) handleMultiKeyCmd(cmd *resp.Command, numKeys int) {
	var subCmd *resp.Command
	var err error
	mc := NewMultiKeyCmd(cmd, numKeys)
	// multi sub cmd share the same seq number
	seq := s.getNextReqSeq()
	readOnly := mc.CmdType() == MGET
	for i := 0; i < numKeys; i++ {
		switch mc.CmdType() {
		case MGET:
			subCmd, err = resp.NewCommand("GET", cmd.Value(i+1))
		case MSET:
			subCmd, err = resp.NewCommand("SET", cmd.Value(2*i+1), cmd.Value((2*i + 2)))
		case DEL:
			subCmd, err = resp.NewCommand("DEL", cmd.Value(i+1))
		}
		if err != nil {
			panic(err)
		}
		key := subCmd.Value(1)
		slot := Key2Slot(key)
		plReq := &PipelineRequest{
			cmd:       subCmd,
			readOnly:  readOnly,
			slot:      slot,
			seq:       seq,
			subSeq:    i,
			backQ:     s.backQ,
			parentCmd: mc,
			wg:        s.reqWg,
		}
		s.reqWg.Add(1)
		s.dispatcher.Schedule(plReq)
	}
}
示例#2
0
func init() {
	cmd, _ := resp.NewCommand("CLUSTER", "SLOTS")
	REDIS_CMD_CLUSTER_SLOTS = cmd.Format()
	cmd, _ = resp.NewCommand("CLUSTER", "NODES")
	REDIS_CMD_CLUSTER_NODES = cmd.Format()
	cmd, _ = resp.NewCommand("READONLY")
	REDIS_CMD_READ_ONLY = cmd.Format()
}