redis_append()#
Syntax
redis_append( conn_id, key, value )
Description#
Appends the specified value to the string stored at key. If the key does not exist, it is created as an empty string before appending. If the key exists and is not a string, an error is returned.
This mirrors the Redis APPEND command: https://redis.io/docs/latest/commands/append/
Returns#
Integer — the length of the string after the append operation.
Time complexity#
O(1) (amortized) — cost is proportional to the size of the value appended in practice but treated as constant for the command.
Parameters#
Parameter | Type | Description |
---|---|---|
conn_id | connection | Redis connection identifier/handle used by the MivaScript Redis extension |
key | string | The key whose string value will be appended to |
value | string | Data to append to the current value of the key |
Behavior and Errors#
- If key does not exist, it is created and set to value.
- If key exists and contains a non-string value, the operation fails with a type error.
- Returns the new length of the string after the append.
- Use appropriate connection checks and error handling for network or server errors.
Examples#
Append text and get resulting length
<MvASSIGN NAME="l.conn" VALUE="{ redis_connect('127.0.0.1', 6379) }">
<MvASSIGN NAME="l.len" VALUE="{ redis_append(l.conn, 'greeting', ' world') }">
<MvEVAL EXPR="{ 'New length: ' $ l.len }">
Append to a key and then retrieve full value
<MvASSIGN NAME="l.conn" VALUE="{ redis_connect('127.0.0.1', 6379) }">
<MvASSIGN NAME="l._" VALUE="{ redis_append(l.conn, 'greeting', '!') }">
<MvASSIGN NAME="l.value" VALUE="{ redis_get(l.conn, 'greeting') }">
<MvEVAL EXPR="{ l.value }">