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)
| 36 | // |
| 37 | // Works similar to https://redis.io/commands/sadd |
| 38 | func (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 | // |