MCPcopy Create free account
hub / github.com/dbProjectRED/redimo.go / XREADGROUP

Method XREADGROUP

streams.go:689–735  ·  view source on GitHub ↗
(key string, group string, consumer string, option XReadOption, maxCount int64)

Source from the content-addressed store, hash-verified

687}
688
689func (c Client) XREADGROUP(key string, group string, consumer string, option XReadOption, maxCount int64) (items []StreamItem, err error) {
690 if option == XReadPending {
691 return c.xGroupReadPending(key, group, consumer, maxCount)
692 }
693
694 retryCount := 0
695
696 for retryCount < 5 {
697 currentCursor, err := c.xGroupCursorGet(key, group)
698 if err != nil {
699 return items, err
700 }
701
702 items, err := c.XRANGE(key, currentCursor.Next(), XEnd, 1)
703
704 if err != nil || len(items) == 0 {
705 return items, err
706 }
707
708 item := items[0]
709
710 var actions []dynamodb.TransactWriteItem
711 actions = append(actions, c.xGroupCursorPushAction(key, group, item.ID))
712
713 if option == XReadNew {
714 actions = append(actions, PendingItem{
715 ID: item.ID,
716 Consumer: consumer,
717 LastDelivered: time.Now(),
718 }.toPutAction(c.xGroupKey(key, group), c))
719 }
720
721 _, err = c.ddbClient.TransactWriteItemsRequest(&dynamodb.TransactWriteItemsInput{
722 TransactItems: actions,
723 }).Send(context.TODO())
724 if err == nil {
725 return items, nil
726 }
727
728 if !conditionFailureError(err) {
729 return items, err
730 }
731 retryCount++
732 }
733
734 return items, errors.New("too much contention")
735}
736
737// XREVRANGE is similar to XRANGE, but in reverse order. The stream items in descending chronological order. Using the
738// same example as XRANGE, when fetching items in reverse order there are some differences when paginating. The first

Callers 2

Calls 8

xGroupReadPendingMethod · 0.95
xGroupCursorGetMethod · 0.95
XRANGEMethod · 0.95
xGroupKeyMethod · 0.95
conditionFailureErrorFunction · 0.85
NextMethod · 0.80
toPutActionMethod · 0.80

Tested by 2