xhttpcache 是一个HTTP高速数据缓存服务,也可以做为K-V存储的NOSQL数据库
支持redis协议接口,支持HTTP协议的REST接口;
xhttpcache有哪些功能?提供HTTP数据缓存服务,支持存储二进制数据;
完整的K-V存储实现,支持数据持久化存储(ROCKSDB);
支持数据超时机制,提供毫秒级精度。
现实完整REDIS协议接口,支持redis的SET/GET/DEL/EXIRE/TTL命令;
实现HTTP/HTTPS协议接口,支持通过REST命令访问;
实现HTTPcache相关协议,支持eTage,支持304NotModified,支持对传输内容gzip压缩;
自带WEB后台编辑器,可以直接添加(上传)/修改/删除数据;
xhttpcache图解编译安装编译依赖库:需要先编译安装好:rocksdb,libevhtp, libsnappy,libjemalloc
wget --no-check-certificate https://gitee.com/0xsky/xhttpcache/archive/master.zip unzip master cd xhttpcache-master make使用场景:xhttpcache被设计为HTTP数据加速服务器:通过提供的写接口向xhttpcache写入的数据,可以直接通过浏览器访问.同时也提供了redis的协议接口,可以直接通过redis的client(支持各种语言接口)进行读写,使之也可以当做简单的NOSQL数据库使用;通过REDIS接口建立的K-V数据,可以直接通过HTTP接口在浏览器里访问查看
通过HTTP接口访问:xhttpcache 有两个HTTP服务端口,可以配置文件里配置;httpd_frontend_port为开放访问端口,只支持读请求;httpd_backend_port为后端数据操作端口,支持全部REST读写请求(get/post/put/delete);后端数据接口访问可以设置登陆账号密码;
curl -d "testdata" https://admin:admin123@127.0.0.1:9090/testkey通过POST请求向 xhttpcache 提交建立一条kv格式的数据:testkey -- testdatacurl https://127.0.0.1:8080/testkey通过get请求访问testkey的数据通过前端端口访问,不需要密码验证,当然也可以通过后端接口带上密码访问:curl https://admin:admin123@127.0.0.1:9090/testkey这两种方式通过GET请求访问的数据是完全一样的。curl -I -X DELETE https://admin:admin123@127.0.0.1:9090/testkey通过http协议的delete请求删除testkey通过以下命令可以上传本地文件到 xhttpcachecurl -F file=@/tmp/me.txt https://admin:admin123@127.0.0.1:9090/test.jpg通过redis命令使用示例:以下示例显示了所有的支持的REDIS命令
[xsky@localhost xhttpcache]$ redis-cli -p 7379 127.0.0.1:7379> set test hello OK 127.0.0.1:7379> get test "hello" 127.0.0.1:7379> set test hello ex 1000 OK 127.0.0.1:7379> get test "hello" 127.0.0.1:7379> ttl test (integer) 988 127.0.0.1:7379> EXPIRE test 2000 (integer) 1 127.0.0.1:7379> ttl test (integer) 1998 127.0.0.1:7379> get test "hello" 127.0.0.1:7379>通过redis命令添加图片文件到xhttpcache:
redis-cli -p 7379 -x set getheadimg.jpg <getheadimg.jpg数据批量导入与导出通过以下脚本向xhttpcache里批量导入磁盘文件,以下脚本会将参数指定的目录下的文件都导入到xhttpcache里.
#!/bin/bashredis_cmd="redis-cli -p 7379 -x set "function batch_convert() { for file in `ls $1` do if [ -d $1"/"$file ] then batch_convert $1"/"$file else key=$1"/"$file #echo 33 $redis_cmd ${key#*/} $1"/"$file $redis_cmd ${key#*/} < $1"/"$file fi done}batch_convert $1通过以下shell脚本,可以把xhttpcache里的数据按目录文件的形式导出到磁盘。
#!/bin/sh# # xHttpCache数据备份脚本# By: xSkyusage(){ echo "++++++++++++++++++++++++++++++++++++++++++++++++++++" echo "+ xHttpCache data export shell tools by:xSky " echo "+ usage: " echo "+ $0 data_dir redis_host redis_port " echo "++++++++++++++++++++++++++++++++++++++++++++++++++++" }#判断参数if [ $# -ne 3 ]; then usage exit 0fidata_dir=$1redis_host=$2redis_port=$3echo $data_dir $redis_host $redis_portif [ -d $data_dir ];then #redis-cli -p 6579 scan a z | awk '{print "redis-cli -p 6579 get "$0 " >"$0}'|sh cd $data_dir redis-cli -h $redis_host -p $redis_port scan a z | while read line do echo $line bdir=`expr index $line "/"` file_dir=${line%/*} file_name=$line if [[ $bdir -gt 0 ]];then #echo 1 $bdir $file_dir $file_name mkdir -p $file_dir fi redis-cli -h $redis_host -p $redis_port get $line > $line done cd -else echo [ERROR] the dir $data_dir do not exist exit 0fi
评论