LREM removes the first occurrence on the given side of the given element.
(key string, side LSide, element Value)
| 602 | |
| 603 | // LREM removes the first occurrence on the given side of the given element. |
| 604 | func (c Client) LREM(key string, side LSide, element Value) (newLength int64, done bool, err error) { |
| 605 | var actions []dynamodb.TransactWriteItem |
| 606 | |
| 607 | outgoingNode, found, err := c.listNodeAtPivot(key, element, side) |
| 608 | if err != nil || !found { |
| 609 | return newLength, false, err |
| 610 | } |
| 611 | |
| 612 | switch { |
| 613 | case outgoingNode.isHead(): |
| 614 | _, done, err = c.listPop(key, Left) |
| 615 | case outgoingNode.isTail(): |
| 616 | _, done, err = c.listPop(key, Right) |
| 617 | default: |
| 618 | leftKeyNode, found, err := c.listGetByAddress(key, outgoingNode.left) |
| 619 | if !found || err != nil { |
| 620 | return newLength, false, err |
| 621 | } |
| 622 | |
| 623 | rightKeyNode, found, err := c.listGetByAddress(key, outgoingNode.right) |
| 624 | |
| 625 | if !found || err != nil { |
| 626 | return newLength, false, err |
| 627 | } |
| 628 | |
| 629 | actions = append(actions, leftKeyNode.updateSideAction(Right, rightKeyNode.address, c)) |
| 630 | actions = append(actions, rightKeyNode.updateSideAction(Left, leftKeyNode.address, c)) |
| 631 | actions = append(actions, outgoingNode.deleteAction(c)) |
| 632 | actions = append(actions, c.listCountDeltaAction(key, -1)) |
| 633 | } |
| 634 | |
| 635 | if err != nil { |
| 636 | return newLength, done, err |
| 637 | } |
| 638 | |
| 639 | if len(actions) > 0 { |
| 640 | _, err = c.ddbClient.TransactWriteItemsRequest(&dynamodb.TransactWriteItemsInput{ |
| 641 | TransactItems: actions, |
| 642 | }).Send(context.TODO()) |
| 643 | if err != nil { |
| 644 | return newLength, done, err |
| 645 | } |
| 646 | |
| 647 | done = true |
| 648 | } |
| 649 | |
| 650 | newLength, err = c.LLEN(key) |
| 651 | |
| 652 | return newLength, done, err |
| 653 | } |
| 654 | |
| 655 | func (c Client) LSET(key string, index int64, element string) (ok bool, err error) { |
| 656 | node, found, err := c.listNodeAtIndex(key, index) |