背景:搞一些Nginx的扩展啥的都用那个hiredis进行静态编译后,编译进Nginx,这儿先研究一下这个Redis的C连接认证以及取数据先。
代码@/usr/local/src/hiredis:
编译一下:
gcc redisTest.c /home/test/rpmbuild/BUILD/ngx_http_monitor_module-2.2.0/hiredis/libhiredis.a -I/home/test/rpmbuild/BUILD/ngx_http_monitor_module-2.2.0/
关于头文件之 linux下C include搜索的路径:http://blog.csdn.net/chosen0ne/article/details/7210946
编译静态的resis静态链接库make static,别make 会生成动态连接库,如果只指定 -L路径,会弄成了动态编译,有依赖SO的情况,静态文件大点无所谓了:
cd hiredis
make clean
make static
静态编译出来就是这样的:
ldd a.out
linux-vdso.so.1 => (0x00007ffeec95e000)
libc.so.6 => /lib64/libc.so.6 (0x0000003771400000)
/lib64/ld-linux-x86-64.so.2 (0x0000003771000000)
执行:
./a.out
Connect to redisServer Success
Authentication success
Succeed to execute command[set stest1 value1]
The length of 'stest1' is 6.
Succeed to execute command[strlen stest1]
The value of 'stest1' is value1
Succeed to execute command[get stest1]
Succeed to execute command[get stest2]
参考:http://blog.csdn.net/mniwc/article/details/12851837
代码@/usr/local/src/hiredis:
编译一下:
gcc redisTest.c /home/test/rpmbuild/BUILD/ngx_http_monitor_module-2.2.0/hiredis/libhiredis.a -I/home/test/rpmbuild/BUILD/ngx_http_monitor_module-2.2.0/
关于头文件之 linux下C include搜索的路径:http://blog.csdn.net/chosen0ne/article/details/7210946
编译静态的resis静态链接库make static,别make 会生成动态连接库,如果只指定 -L路径,会弄成了动态编译,有依赖SO的情况,静态文件大点无所谓了:
cd hiredis
make clean
make static
静态编译出来就是这样的:
ldd a.out
linux-vdso.so.1 => (0x00007ffeec95e000)
libc.so.6 => /lib64/libc.so.6 (0x0000003771400000)
/lib64/ld-linux-x86-64.so.2 (0x0000003771000000)
执行:
./a.out
Connect to redisServer Success
Authentication success
Succeed to execute command[set stest1 value1]
The length of 'stest1' is 6.
Succeed to execute command[strlen stest1]
The value of 'stest1' is value1
Succeed to execute command[get stest1]
Succeed to execute command[get stest2]
参考:http://blog.csdn.net/mniwc/article/details/12851837
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/9445/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2017-9-6 10:19
评论列表