TCP:persist(t)
This command is used to manually add or update entries in the persistence table. It allows you to programmatically define custom session affinity by mapping a specific hash key to a real server. This ensures that subsequent traffic with the same identifier is consistently routed to the same backend resource.
Syntax
TCP:persist(t)
Arguments
| Name | Description |
|---|---|
|
t |
A Lua table containing the following fields:
|
Events
Applicable in the following events:
-
STREAM_REQUEST_DATA
-
STREAM_RESPONSE_DATA
-
STREAM_ PERSISTENCE
Example
In this example, the script captures the client's address, generates a SHA-512 hash, and uses it as a persistence key to pin the session to a specific server pool.
when STREAM_RESPONSE_DATA {
cip = IP:client_addr()
hash_str_cip = sha512_hex(cip)
debug("-----save_tbl-----\n")
t={}
t["operation"] = "save_tbl"
t["hash_value"] = hash_str_cip
t["srv_name"] = "pool1-2"
ret = TCP:persist(t)
if ret then
debug("hash save table success\n");
else
debug("save table failed\n");
end
}
Supported Version
FortiADC version 7.6.7 and later.