LRem removes elements from a list associated with a key based on the count and value parameters. The count can have the following values: count > 0: Remove count occurrences of the value from the beginning of the list. count < 0: Remove count occurrences of the value from the end of the list. count
(key string, count int, value interface{})
| 281 | // count = 0: Remove all occurrences of the value from the list. |
| 282 | // If the key does not exist, an error is returned. |
| 283 | func (l *ListStructure) LRem(key string, count int, value interface{}) error { |
| 284 | // Get the list |
| 285 | lst, _, err := l.getListFromDB(key, false) |
| 286 | if err != nil { |
| 287 | return err |
| 288 | } |
| 289 | var expirationTime time.Duration |
| 290 | // Process different counts |
| 291 | if count != 0 { |
| 292 | prev, curr := lst.Head, lst.Head |
| 293 | for i := 0; (count > 0 && i < count || count < 0 && lst.Length+i > -count) && curr != nil; { |
| 294 | if l.valueEqual(curr.Value, value) { |
| 295 | if curr == lst.Head { |
| 296 | lst.Head = curr.Next |
| 297 | } else { |
| 298 | prev.Next = curr.Next |
| 299 | } |
| 300 | i++ |
| 301 | lst.Length-- |
| 302 | } else { |
| 303 | prev = curr |
| 304 | } |
| 305 | curr = curr.Next |
| 306 | } |
| 307 | } else { |
| 308 | prev, curr := lst.Head, lst.Head |
| 309 | for curr != nil { |
| 310 | if l.valueEqual(curr.Value, value) { |
| 311 | if curr == lst.Head { |
| 312 | lst.Head = curr.Next |
| 313 | } else { |
| 314 | prev.Next = curr.Next |
| 315 | } |
| 316 | lst.Length-- |
| 317 | } else { |
| 318 | prev = curr |
| 319 | } |
| 320 | curr = curr.Next |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | // Store to db |
| 325 | return l.setListToDB(key, lst, expirationTime) |
| 326 | } |
| 327 | |
| 328 | // LSet sets the value of an element in a list associated with a key based on the index. |
| 329 | // If the index is out of range, an error is returned. |
nothing calls this directly
no test coverage detected