LRem removes the first count occurrences of elements equal to value from the list stored in the bucket at given bucket,key,count. The count argument influences the operation in the following ways: count > 0: Remove elements equal to value moving from head to tail. count < 0: Remove elements equal to
(bucket string, key []byte, count int, value []byte)
| 319 | // count < 0: Remove elements equal to value moving from tail to head. |
| 320 | // count = 0: Remove all elements equal to value. |
| 321 | func (tx *Tx) LRem(bucket string, key []byte, count int, value []byte) error { |
| 322 | var ( |
| 323 | buffer bytes.Buffer |
| 324 | size int |
| 325 | ) |
| 326 | size, err := tx.LSize(bucket, key) |
| 327 | if err != nil { |
| 328 | return err |
| 329 | } |
| 330 | |
| 331 | if count > size || count < -size { |
| 332 | return ErrCount |
| 333 | } |
| 334 | |
| 335 | buffer.Write([]byte(strconv2.IntToStr(count))) |
| 336 | buffer.Write([]byte(SeparatorForListKey)) |
| 337 | buffer.Write(value) |
| 338 | newValue := buffer.Bytes() |
| 339 | |
| 340 | err = tx.push(bucket, key, DataLRemFlag, newValue) |
| 341 | if err != nil { |
| 342 | return err |
| 343 | } |
| 344 | |
| 345 | return nil |
| 346 | } |
| 347 | |
| 348 | // LTrim trims an existing list so that it will contain only the specified range of elements specified. |
| 349 | // the offsets start and stop are zero-based indexes 0 being the first element of the list (the head of the list), |