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

Method SADD

sets.go:38–55  ·  view source on GitHub ↗

SADD adds the given string members to the set at the given key. Returns that members that were actually added and did not already exist in the set. Cost is O(1) / 1 WCU for each member, whether it already exists or not. Works similar to https://redis.io/commands/sadd

(key string, members ...string)

Source from the content-addressed store, hash-verified

36//
37// Works similar to https://redis.io/commands/sadd
38func (c Client) SADD(key string, members ...string) (addedMembers []string, err error) {
39 for _, member := range members {
40 resp, err := c.ddbClient.PutItemRequest(&dynamodb.PutItemInput{
41 Item: setMember{pk: key, sk: member}.toAV(c),
42 ReturnValues: dynamodb.ReturnValueAllOld,
43 TableName: aws.String(c.table),
44 }).Send(context.TODO())
45 if err != nil {
46 return addedMembers, err
47 }
48
49 if len(resp.Attributes) == 0 {
50 addedMembers = append(addedMembers, member)
51 }
52 }
53
54 return
55}
56
57// SCARD returns the cardinality (the number of elements) in the set at key.
58//

Callers 6

SDIFFSTOREMethod · 0.95
SINTERSTOREMethod · 0.95
SUNIONSTOREMethod · 0.95
TestBasicSetsFunction · 0.80
TestSetOperationsFunction · 0.80
TestSetModifiersFunction · 0.80

Calls 2

toAVMethod · 0.45
StringMethod · 0.45

Tested by 3

TestBasicSetsFunction · 0.64
TestSetOperationsFunction · 0.64
TestSetModifiersFunction · 0.64