GETSET gets the value at the key and atomically sets it to a new value. Works similar to https://redis.io/commands/getset
(key string, value Value)
| 81 | // |
| 82 | // Works similar to https://redis.io/commands/getset |
| 83 | func (c Client) GETSET(key string, value Value) (oldValue ReturnValue, err error) { |
| 84 | builder := newExpresionBuilder() |
| 85 | builder.updateSET(vk, value) |
| 86 | |
| 87 | resp, err := c.ddbClient.UpdateItemRequest(&dynamodb.UpdateItemInput{ |
| 88 | ConditionExpression: builder.conditionExpression(), |
| 89 | ExpressionAttributeNames: builder.expressionAttributeNames(), |
| 90 | ExpressionAttributeValues: builder.expressionAttributeValues(), |
| 91 | UpdateExpression: builder.updateExpression(), |
| 92 | Key: keyDef{ |
| 93 | pk: key, |
| 94 | sk: emptySK, |
| 95 | }.toAV(c), |
| 96 | ReturnValues: dynamodb.ReturnValueAllOld, |
| 97 | TableName: aws.String(c.table), |
| 98 | }).Send(context.TODO()) |
| 99 | |
| 100 | if err != nil || len(resp.Attributes) == 0 { |
| 101 | return |
| 102 | } |
| 103 | |
| 104 | oldValue = parseItem(resp.Attributes, c).val |
| 105 | |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | // MGET fetches the given keys atomically in a transaction. The call is limited to 25 keys and 4MB. |
| 110 | // See https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html |