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

Method ZADD

sorted_sets.go:81–117  ·  view source on GitHub ↗
(key string, membersWithScores map[string]float64, flags Flags)

Source from the content-addressed store, hash-verified

79}
80
81func (c Client) ZADD(key string, membersWithScores map[string]float64, flags Flags) (addedMembers []string, err error) {
82 for member, score := range membersWithScores {
83 builder := newExpresionBuilder()
84 builder.updateSetAV(c.skN, zScore{score}.ToAV())
85
86 if flags.has(IfNotExists) {
87 builder.addConditionNotExists(c.pk)
88 }
89
90 if flags.has(IfAlreadyExists) {
91 builder.addConditionExists(c.pk)
92 }
93
94 resp, err := c.ddbClient.UpdateItemRequest(&dynamodb.UpdateItemInput{
95 ConditionExpression: builder.conditionExpression(),
96 ExpressionAttributeNames: builder.expressionAttributeNames(),
97 ExpressionAttributeValues: builder.expressionAttributeValues(),
98 Key: keyDef{pk: key, sk: member}.toAV(c),
99 ReturnValues: dynamodb.ReturnValueAllOld,
100 TableName: aws.String(c.table),
101 UpdateExpression: builder.updateExpression(),
102 }).Send(context.TODO())
103 if conditionFailureError(err) {
104 continue
105 }
106
107 if err != nil {
108 return addedMembers, err
109 }
110
111 if len(resp.Attributes) == 0 {
112 addedMembers = append(addedMembers, member)
113 }
114 }
115
116 return
117}
118
119func (c Client) ZCARD(key string) (count int64, err error) {
120 return c.HLEN(key)

Callers 7

ZINTERSTOREMethod · 0.95
ZUNIONSTOREMethod · 0.95
TestZBasicFunction · 0.80
TestZPopsFunction · 0.80
TestZRangesFunction · 0.80
TestZCountsFunction · 0.80
TestZAggregationsFunction · 0.80

Calls 13

newExpresionBuilderFunction · 0.85
conditionFailureErrorFunction · 0.85
updateSetAVMethod · 0.80
hasMethod · 0.80
addConditionNotExistsMethod · 0.80
addConditionExistsMethod · 0.80
conditionExpressionMethod · 0.80
updateExpressionMethod · 0.80
ToAVMethod · 0.65
toAVMethod · 0.45

Tested by 5

TestZBasicFunction · 0.64
TestZPopsFunction · 0.64
TestZRangesFunction · 0.64
TestZCountsFunction · 0.64
TestZAggregationsFunction · 0.64