MCPcopy
hub / github.com/redis/go-redis / slottedKeyedCommands

Method slottedKeyedCommands

osscluster.go:1939–1967  ·  view source on GitHub ↗

slottedKeyedCommands returns a map of slot to commands taking into account only commands that have keys.

(ctx context.Context, cmds []Cmder)

Source from the content-addressed store, hash-verified

1937// slottedKeyedCommands returns a map of slot to commands taking into account
1938// only commands that have keys.
1939func (c *ClusterClient) slottedKeyedCommands(ctx context.Context, cmds []Cmder) map[int][]Cmder {
1940 cmdsSlots := map[int][]Cmder{}
1941
1942 // Peek once outside the loop, one RLock for the whole batch instead of
1943 // two per command (one for the keyless check, one inside cmdSlot).
1944 cachedInfo := c.cmdsInfoCache.Peek()
1945
1946 prefferedRandomSlot := -1
1947 for _, cmd := range cmds {
1948 var info *CommandInfo
1949 if cachedInfo != nil {
1950 info = cachedInfo[cmd.Name()]
1951 }
1952
1953 pos := cmdFirstKeyPosWithInfo(cmd, info)
1954 if pos == 0 {
1955 continue
1956 }
1957
1958 slot := c.cmdSlotWithPos(cmd, pos, prefferedRandomSlot)
1959 if prefferedRandomSlot == -1 {
1960 prefferedRandomSlot = slot
1961 }
1962
1963 cmdsSlots[slot] = append(cmdsSlots[slot], cmd)
1964 }
1965
1966 return cmdsSlots
1967}
1968
1969func (c *ClusterClient) processTxPipelineNode(
1970 ctx context.Context, node *clusterNode, cmds []Cmder, failedCmds *cmdsMap,

Callers 1

processTxPipelineMethod · 0.95

Calls 4

cmdSlotWithPosMethod · 0.95
cmdFirstKeyPosWithInfoFunction · 0.85
NameMethod · 0.65
PeekMethod · 0.45

Tested by

no test coverage detected