當前位置: 首頁>>代碼示例>>Golang>>正文


Golang command.Command類代碼示例

本文整理匯總了Golang中carrier/command/command.Command的典型用法代碼示例。如果您正苦於以下問題:Golang Command類的具體用法?Golang Command怎麽用?Golang Command使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Command類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: MSetCommand

func MSetCommand(cmd command.Command, msg protocol.Message) (msgAck protocol.Message) {
	var elements []protocol.Message = msg.GetArraysValue()
	if msg.GetIntegersValue()%2 != 1 {
		return protocol.NewMessageString(protocol.ERR_wrong_number_command, cmd.Name())
	}

	var (
		keyIndex       int64
		hashSlot       uint16
		classification map[uint16]protocol.Message = make(map[uint16]protocol.Message)
		msgSpice       protocol.Message
		ok             bool
	)
	for keyIndex = 1; keyIndex < msg.GetIntegersValue(); keyIndex += 2 {
		hashSlot = crc16.HashSlot(elements[keyIndex].GetBytesValue())
		if msgSpice, ok = classification[hashSlot]; !ok {
			msgSpice = protocol.NewMessage().AppendArraysValue(elements[0])
		}
		classification[hashSlot] = msgSpice.AppendArraysValue(elements[keyIndex]).AppendArraysValue(elements[keyIndex+1])
	}
	// 按slot分命令
	var node nodes.Nodes
	for hashSlot, msgSpice = range classification {
		if node, ok = cluster.GetClusterParameter().GetSlot(hashSlot); !ok {
			logger.Warningf("獲取不到slot節點: %d", hashSlot)
			continue
		}
		forwardMsg(msgSpice, node, cmd.CheckReadonly())
	}
	return protocol.OK
}
開發者ID:huangzhiyong,項目名稱:carrier,代碼行數:31,代碼來源:strings.go

示例2: DelCommand

func DelCommand(cmd command.Command, msg protocol.Message) (msgAck protocol.Message) {
	var (
		elements       []protocol.Message = msg.GetArraysValue()
		element        protocol.Message
		hashSlot       uint16
		classification map[uint16]protocol.Message = make(map[uint16]protocol.Message)
		msgSpice       protocol.Message
		ok             bool
	)
	for _, element = range elements[1:] {
		hashSlot = crc16.HashSlot(element.GetBytesValue())
		if msgSpice, ok = classification[hashSlot]; !ok {
			msgSpice = protocol.NewMessage().AppendArraysValue(elements[0])
		}
		classification[hashSlot] = msgSpice.AppendArraysValue(element)
	}
	// 按slot分命令
	var (
		node        nodes.Nodes
		msgAckSplit protocol.Message
	)
	msgAck = protocol.NewMessage()
	for hashSlot, msgSpice = range classification {
		if node, ok = cluster.GetClusterParameter().GetSlot(hashSlot); !ok {
			logger.Warningf("獲取不到slot節點: %d", hashSlot)
			continue
		}
		msgAckSplit = forwardMsg(msgSpice, node, cmd.CheckReadonly())
		msgAck.AppendIntegersValue(msgAckSplit)
	}
	return
}
開發者ID:huangzhiyong,項目名稱:carrier,代碼行數:32,代碼來源:keys.go

示例3: PingCommand

func PingCommand(cmd command.Command, msg protocol.Message) protocol.Message {
	if msg.GetIntegersValue() > 2 {
		return protocol.NewMessageString(protocol.ERR_wrong_number_command, cmd.Name())
	}
	if msg.GetIntegersValue() == 2 {
		return msg.GetArraysValue()[1]
	}
	return protocol.PONG
}
開發者ID:huangzhiyong,項目名稱:carrier,代碼行數:9,代碼來源:connection.go

示例4: MGetCommand

func MGetCommand(cmd command.Command, msg protocol.Message) (msgAck protocol.Message) {
	var (
		elements       []protocol.Message = msg.GetArraysValue()
		element        protocol.Message
		hashSlot       uint16
		classification map[uint16]protocol.Message = make(map[uint16]protocol.Message)
		msgSpice       protocol.Message
		ok             bool
	)
	for _, element = range elements[1:] {
		hashSlot = crc16.HashSlot(element.GetBytesValue())
		if msgSpice, ok = classification[hashSlot]; !ok {
			msgSpice = protocol.NewMessage().AppendArraysValue(elements[0])
		}
		classification[hashSlot] = msgSpice.AppendArraysValue(element)
	}
	// 按slot分命令
	var (
		node        nodes.Nodes
		msgAckSplit protocol.Message
		msgAckMap   map[protocol.Message]protocol.Message = make(map[protocol.Message]protocol.Message)

		msgKey   int
		msgValue protocol.Message
	)
	for hashSlot, msgSpice = range classification {
		if node, ok = cluster.GetClusterParameter().GetSlot(hashSlot); !ok {
			logger.Warningf("獲取不到slot節點: %d", hashSlot)
			continue
		}
		msgAckSplit = forwardMsg(msgSpice, node, cmd.CheckReadonly())
		if msgAckSplit.GetProtocolType() != protocol.ArraysType {
			logger.Warningf("命令結果預期不符: %v", msgSpice)
			continue
		}
		if msgSpice.GetIntegersValue()-1 != msgAckSplit.GetIntegersValue() {
			logger.Warningf("命令結果預期不符: %v", msgSpice)
			continue
		}
		for msgKey, msgValue = range msgSpice.GetArraysValue()[1:] {
			msgAckMap[msgValue] = msgAckSplit.GetArraysValue()[msgKey]
		}
	}
	// 整合結果
	msgAck = protocol.NewMessage()
	for _, element = range elements[1:] {
		if msgValue, ok = msgAckMap[element]; ok {
			msgAck.AppendArraysValue(msgAckMap[element])
		} else {
			msgAck.AppendArraysValue(protocol.NullBulkString)
		}
	}
	return
}
開發者ID:huangzhiyong,項目名稱:carrier,代碼行數:54,代碼來源:strings.go

示例5: ProcKeyCommand

func ProcKeyCommand(cmd command.Command, msg protocol.Message) (msgAck protocol.Message) {
	var (
		slot uint16 = crc16.HashSlot(msg.GetArraysValue()[1].GetBytesValue()) // 第一個參數是Key
		node nodes.Nodes
		ok   bool
	)
	if node, ok = cluster.GetClusterParameter().GetSlot(slot); !ok {
		logger.Warningf("獲取不到slot節點: %d", slot)
		return protocol.ERR_ClusterSlots
	}
	return forwardMsg(msg, node, cmd.CheckReadonly())
}
開發者ID:huangzhiyong,項目名稱:carrier,代碼行數:12,代碼來源:proc.go

示例6: ForbiddenCommand

func ForbiddenCommand(cmd command.Command, msg protocol.Message) protocol.Message {
	return protocol.NewMessageString(protocol.ERR_forbidden_command, cmd.Name())
}
開發者ID:huangzhiyong,項目名稱:carrier,代碼行數:3,代碼來源:forbidden.go

示例7: init

func init() {
	var cmd command.Command
	for _, cmd = range CommandTable {
		commandSet.AddCommand(cmd.Name(), cmd)
	}
}
開發者ID:huangzhiyong,項目名稱:carrier,代碼行數:6,代碼來源:set.go

示例8: ProcessCommand

func ProcessCommand(msg protocol.Message) protocol.Message {
	var (
		name []byte
		argc int64
		cmd  command.Command
		ok   bool
	)
	switch msg.GetProtocolType() {
	case protocol.ArraysType:
		if argc = msg.GetIntegersValue(); argc > 0 {
			name = msg.GetArraysValue()[0].GetBytesValue()
		}
	}

	if cmd, ok = commandSet.SearchCommand(name); !ok {
		return protocol.NewMessageString(protocol.ERR_unknown_command, name)
	}
	if !cmd.CheckArgc(argc) {
		return protocol.NewMessageString(protocol.ERR_wrong_number_command, cmd.Name())
	}
	if cmd.CheckForbidden() {
		return protocol.NewMessageString(protocol.ERR_forbidden_command, cmd.Name())
	}
	return cmd.Proc(cmd, msg)
}
開發者ID:huangzhiyong,項目名稱:carrier,代碼行數:25,代碼來源:set.go


注:本文中的carrier/command/command.Command類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。