Redis is the in-memory data store behind countless caches and queues. This is the C function behind the APPEND command, from Redis 7.2, released under the BSD license. It creates the key if it is missing, or checks the type and the size limit before adding to the end of the string.
What to look for
Two quiet exits: the key holds something that is not a string, or the result would be too long.
How much Thunder could read
19 of 20 steps put into words; the other 1 is shown as code.
Read by the current Thunder compiler when this page was built. Hand-checked against the code: accurate, with some wording that is thin or close to the code.
››››
Flow: How does it go? One action or rule as a path: questions with Yes and No, repeats, the Stops, what happens if something goes wrong, and what always happens at the end.
In this file
Append command
From codelines 697–726
You give itc
=Works out: Declares totlen
robj *o, *append;
=Works out: Works out o from lookup key write
Is o null?
Yes
⤓Saves: Stores the result of try object encoding under 2 in the c's argv
→Does: Calls db add
→Does: Calls incr ref count
=Works out: Works out totlen from string object len
No
Check type(c,o,OBJ_STRING)?
Yes
Stops here
No ↓ continue
⌕Finds: Sets append to the 2 entry in the c's argv
Is check string length(c,string object len(o),sdslen(the append's ptr)) C_OK?
No
Stops here
Yes ↓ continue
=Works out: Works out o from db unshare string value
The same reading as Thunder Text, built with this page
Append command
You give it: c
- Declares totlen (line 698)
- `robj *o, *append;` (code, not explained) (line 699)
- Works out o from lookup key write (line 701)
- Ask: Is o null? (line 702)
Yes:
- Stores the result of try object encoding under 2 in the c's argv (line 704)
- Calls db add (line 705)
- Calls incr ref count (line 706)
- Works out totlen from string object len (line 707)
No:
- Ask: Check type(c,o,OBJ_STRING)? (line 710)
Yes:
- Stops here (line 710)
No: continue
- Sets append to the 2 entry in the c's argv (line 714)
- Ask: Is check string length(c,string object len(o),sdslen(the append's ptr)) C_OK? (line 715)
Yes: continue
No:
- Stops here (line 715)
- Works out o from db unshare string value (line 719)
- Works out the o's ptr from sdscatlen (line 720)
- Works out totlen from sdslen (line 721)
- Calls signal modified key (line 723)
- Calls notify keyspace event (line 724)
- Adds one to the server's dirty (line 725)
- Calls add reply long long (line 726)
Copyright (c) 2006-2020, Salvatore Sanfilippo. Licensed under the BSD 3-Clause. The code is shown unmodified; the Thunder reading is ThunderLang's.
Full license text (LICENSE)
Copyright (c) 2006-2020, Salvatore Sanfilippo
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Redis nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.