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

Method GETSET

strings.go:83–107  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

81//
82// Works similar to https://redis.io/commands/getset
83func (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

Callers 1

TestGETSETFunction · 0.80

Calls 9

newExpresionBuilderFunction · 0.85
parseItemFunction · 0.85
updateSETMethod · 0.80
conditionExpressionMethod · 0.80
updateExpressionMethod · 0.80
toAVMethod · 0.45
StringMethod · 0.45

Tested by 1

TestGETSETFunction · 0.64