先上路由脚本:
#debug_mode=yeslog_level=3
xlog_level=3
stderror_enabled=no
syslog_enabled=yes
syslog_facility=LOG_LOCAL0udp_workers=4socket=udp:127.0.0.1:5060 # CUSTOMIZE ME
socket=tcp:127.0.0.1:5060 # CUSTOMIZE ME#set module path
mpath="/usr/lib/x86_64-linux-gnu/opensips/modules/"#### SIGNALING module
loadmodule "signaling.so"#### StateLess module
loadmodule "sl.so"#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 5)
modparam("tm", "fr_inv_timeout", 30)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)#### Record Route Module
loadmodule "rr.so"
/* do not append from tag to the RR (no need for this script) */
modparam("rr", "append_fromtag", 0)#### MAX ForWarD module
loadmodule "maxfwd.so"#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"#### FIFO Management Interface
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)#### MYSQL module
loadmodule "db_mysql.so"loadmodule "cachedb_sql.so"
modparam("cachedb_sql", "cachedb_url", "sql:1st-mysql://opensips:opensipsrw@localhost/opensips")
modparam("cachedb_sql", "db_table", "cachedb")
modparam("cachedb_sql", "key_column", "keyname")
modparam("cachedb_sql", "value_column", "value")
modparam("cachedb_sql", "counter_column", "counter")
modparam("cachedb_sql", "expires_column", "expires")loadmodule "proto_udp.so"
loadmodule "proto_tcp.so"####### Routing Logic ######### main request routing logic
route{send_reply(404, "Not here");exit;
}
- 启动opensips
- opensips-cli -x mi cache_store sql:1st-mysql key1 1234
"OK"
- opensips-cli -x mi cache_fetch sql:1st-mysql key1
{
"key": "key1",
"value": "1234"
}
- mysql, 执行 from select * from cachedb;
+----+---------+-------+---------+---------+
| id | keyname | value | counter | expires |
+----+---------+-------+---------+---------+
| 1 | key1 | 1234 | 0 | 0 |
+----+---------+-------+---------+---------+
1 row in set (0.000 sec)