opensips下redis相关的模块的是cachedb_redis.so,但是默认情况下是不会安装的。
安装
默认情况下,opensips是不会安装cachedb_redis.so。 因为该module依赖另外一个三方库libhiredis.so.
所以前提准备是先安装libhiredis.so。请自行搜索安装方法。
在Opensips里的安装如下,
通过make menuconfig



直接make
make all include_modules="cachedb_redis" prefix="/usr/local/" install
安装后检查
在安装路径下的modules文件夹下检查是否生成了cachedb_redis.so文件

使用
官方API介绍
https://opensips.org/html/docs/modules/1.8.x/cachedb_redis.html
因为opensips的core已经定义了cache接口,所以cachedb_redis.so中的 API也是基于core中的API来实现的。
如下,增删改查
- cache_store
- cache_fetch
- cache_remove
参数配置
参数配置比较少,但是注意一点。 一般redis会有密码,在uri里配置密码的时候,需要在密码前面加上:(因为没有账户,如果这里账户为空)。如果不配置密码,可能会遇到NOAUTH Authentication required错误!

注意:url中的最后一个斜杠是必须的,如果不加会解析失败!!
简单样例
现在redis里创建一个opensips:test = 1的键值,然后在opensips中获取。
cache_fetch("redis:group1","opensips:test",$avp(optest));
xlog("L_INFO", "[TEST] redis test value: $avp(optest) [rm:$rm] [fu:$fu] [ou:$ou] [ru:$ru] [si:$si]\n");
网友评论