MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / cmdSETRANGE

Function cmdSETRANGE

strings.go:129–153  ·  view source on GitHub ↗

cmdSETRANGE overwrites part of the string stored at key, starting at the specified offset, for the entire length of the value. If the offset is larger than the current length of the string, the string is padded with zero-bytes to make offset fit. Non-existing keys are treated as empty strings.

(m uhaha.Machine, args []string)

Source from the content-addressed store, hash-verified

127// cmdSETRANGE overwrites part of the string stored at key, starting at the specified offset,
128// for the entire length of the value. If the offset is larger than the current length of the string,
129// the string is padded with zero-bytes to make offset fit. Non-existing keys are treated as empty strings.
130func cmdSETRANGE(m uhaha.Machine, args []string) (interface{}, error) {
131 // Check the number of arguments
132 if len(args) != 4 {
133 return nil, uhaha.ErrWrongNumArgs
134 }
135
136 // Parse the key and offset
137 key := []byte(args[1])
138 offset, err := strconv.Atoi(args[2])
139 if err != nil {
140 return nil, err
141 }
142
143 // Parse the value to be set
144 value := []byte(args[3])
145
146 // Perform the SetRange operation
147 n, err := ldb.SetRange(key, offset, value)
148 if err != nil {
149 return nil, err
150 }
151
152 // Return the length of the string after the operation
153 return redcon.SimpleInt(n), nil
154}
155
156// cmdINCRBY increments the number stored at key by delta. If the key does not exist,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected