This commit is contained in:
wanganni 2025-07-31 20:12:13 +08:00
parent 8146ce3a7b
commit da15267213
569 changed files with 163845 additions and 3168 deletions

BIN
jar/zzzz/111111i.zip Normal file

Binary file not shown.

BIN
jar/zzzz/222.zip Normal file

Binary file not shown.

BIN
jar/zzzz/XBPQ.jar Normal file

Binary file not shown.

BIN
jar/zzzz/classes.dex Normal file

Binary file not shown.

BIN
jar/zzzz/classes.dex.bak Normal file

Binary file not shown.

BIN
jar/zzzz/classes_smali.zip Normal file

Binary file not shown.

BIN
jar/zzzz/smali.zip Normal file

Binary file not shown.

BIN
jar/zzzz/xbpq1.jar Normal file

Binary file not shown.

BIN
jar/zzzz/xbpq1.jar.bak Normal file

Binary file not shown.

BIN
jar/zzzz/xbpq2.jar Normal file

Binary file not shown.

BIN
jar/zzzz/xbpq原版.jar Normal file

Binary file not shown.

BIN
jar/zzzz/xyq202503.jar.bak Normal file

Binary file not shown.

View file

@ -7,7 +7,7 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://18je.life/label/hot/by/time/nid/1/page/1/sid/1/",
"首页推荐链接": "https://18mf.life/label/hot/by/time/nid/1/page/1/sid/1/",
"首页列表数组规则": ".main&&.main_list",
"首页片单列表数组规则": "li",
"首页片单是否Jsoup写法": "1",
@ -15,7 +15,7 @@
"首页片单链接": "a&&href",
"首页片单图片": "img&&data-original",
"首页片单副标题": "'📆'+span&&Text",
"首页片单链接加前缀": "https://18je.life",
"首页片单链接加前缀": "https://18mf.life",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//{cateId}id
@ -25,7 +25,7 @@
//{lang}
//{catePg}
//{year}
"分类链接": "https://18je.life/show/{cateId}/by/{by}/nid/1/page/{catePg}/sid/1/",
"分类链接": "https://18mf.life/show/{cateId}/by/{by}/nid/1/page/{catePg}/sid/1/",
"分类名称": "国产&日韩&欧美&伦理&动漫&",
"分类名称替换词": "1&2&3&4&16&",
"分类截取模式": "1",
@ -35,10 +35,10 @@
"分类片单链接": "a&&href",
"分类片单图片": ".vodlist_img&&img&&data-original",
"分类片单副标题": "'📆'+span&&Text",
"分类片单链接加前缀": "https://18je.life",
"分类片单链接加前缀": "https://18mf.life",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "https://18je.life/index.php/ajax/suggest?mid=1&wd={wd}",
"搜索链接": "https://18mf.life/index.php/ajax/suggest?mid=1&wd={wd}",
"POST请求数据": "",
"搜索截取模式": "0",
"搜索列表数组规则": "list",
@ -47,7 +47,7 @@
"搜索片单标题": "name",
"搜索片单链接": "id",
"搜索片单副标题": "",
"搜索片单链接加前缀": "https://18je.life/v/",
"搜索片单链接加前缀": "https://18mf.life/v/",
"搜索片单链接加后缀": "/",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -9,7 +9,7 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://sziobc2970n4gv9.i88.ind7888.iumi1i35.5xbaidu.com",
"首页推荐链接": "https://5xsq.com",
"首页列表数组规则": ".desktop-thumbs",
"首页片单列表数组规则": ".thumb",
"首页片单是否Jsoup写法": "1",
@ -17,11 +17,11 @@
"首页片单链接": "a&&href",
"首页片单图片": "source&&srcset",
"首页片单副标题": "'⏱️'+.duration,1&&Text+'📆'+.item-date&&Text",
"首页片单链接加前缀": "https://sziobc2970n4gv9.i88.ind7888.iumi1i35.5xbaidu.com",
"首页片单链接加前缀": "https://5xsq.com",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://hscangku.com/vodtype/{cateId}-{catePg}/",
"分类链接": "https://sziobc2970n4gv9.i88.ind7888.iumi1i35.5xbaidu.com/{cateId}?o={by}&page={catePg}",
"分类链接": "https://5xsq.com/{cateId}?o={by}&page={catePg}",
"分类名称": "最新视频&精选视频&未经审查&审查视频&分类",
"分类名称替换词": "videos&recommendation&uncensored&censored&videos/homemade-selfie",
"分类截取模式": "1",
@ -32,10 +32,10 @@
"分类片单图片": "source&&srcset",
"分类片单副标题": "'⏱️'+.duration,1&&Text+'📆'+.item-date&&Text",
"分类片单链接加前缀": "https://sziobc2970n4gv9.i88.ind7888.iumi1i35.5xbaidu.com",
"分类片单链接加前缀": "https://5xsq.com",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$PC_UA",
"搜索链接": "https://sziobc2970n4gv9.i88.ind7888.iumi1i35.5xbaidu.com/search/videos/{wd}",
"搜索链接": "https://5xsq.com/search/videos/{wd}",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": ".desktop-thumbs&&.thumb",
@ -44,7 +44,7 @@
"搜索片单标题": ".name&&Text",
"搜索片单链接": "a&&href",
"搜索片单副标题": "'⏱️'+.duration,1&&Text+'📆'+.item-date&&Text",
"搜索片单链接加前缀": "https://sziobc2970n4gv9.i88.ind7888.iumi1i35.5xbaidu.com",
"搜索片单链接加前缀": "https://5xsq.com",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -8,7 +8,7 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "0",
"首页推荐链接": "https://www.91hdec.cc",
"首页推荐链接": "https://www.91707.cc",
"首页列表数组规则": ".page-main",
"首页片单列表数组规则": "article",
"首页片单是否Jsoup写法": "1",
@ -16,11 +16,11 @@
"首页片单链接": "a&&href",
"首页片单图片": "img&&src",
"首页片单副标题": "'⏱️'+.video-length&&Text+'分'",
"首页片单链接加前缀": "https://www.91hdec.cc",
"首页片单链接加前缀": "https://www.91707.cc",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://hscangku.com/vodshow/{cateId}-{catePg}/",
"分类链接": "https://www.91hdec.cc{cateId}page/{catePg}/?orderby={by}",
"分类链接": "https://www.91707.cc{cateId}page/{catePg}/?orderby={by}",
"分类名称": "热播&全部&国产精选&国产探花&日本无码&日本有码&国产传媒&国产主播&国产系列&中文字幕&巨乳专区&淫乱多人&制服诱惑&学生专区&欧美精选&国产乱伦&国产自拍&萝莉专区&韩国主播&户外露出&美穴专区&动漫&国产短视频&ktv系列&女同&极品&男同&福利姬",
"分类名称替换词": "/rebo/&/video/&/categories/国产精选/&/categories/国产探花/&/categories/日本无码/&/categories/日本有码/&/categories/国产传媒/&/categories/国产主播/&/categories/国产系列/&/categories/中文字幕/&/categories/巨乳专区/&/categories/淫乱多人/&/categories/制服诱惑/&/categories/学生专区/&/categories/欧美精选/&/categories/国产乱伦/&/categories/国产自拍/&/categories/萝莉专区/&/categories/韩国主播/&/categories/户外露出/&/categories/美穴专区/&/categories/动漫/&/categories/国产短视频/&/categories/ktv系列/&/categories/女同/&/categories/极品/&/categories/男同/&/categories/福利姬/",
"分类截取模式": "1",
@ -31,10 +31,10 @@
"分类片单图片": "img&&data-src",
"分类片单副标题": "'⏱️'+.video-length&&Text+'分'",
"分类片单链接加前缀": "https://www.91hdec.cc",
"分类片单链接加前缀": "https://www.91707.cc",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "https://www.91hdec.cc/?s={wd}&search=&content_type=any&orderby=post_like&content_type=video",
"搜索链接": "https://www.91707.cc/?s={wd}&search=&content_type=any&orderby=post_like&content_type=video",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": ".page-main&&article",
@ -43,7 +43,7 @@
"搜索片单标题": "h2&&Text",
"搜索片单链接": "a&&href",
"搜索片单副标题": "'⏱️'+.video-length&&Text+'分'",
"搜索片单链接加前缀": "https://www.91hdec.cc",
"搜索片单链接加前缀": "https://www.91707.cc",
"搜索片单链接加后缀": "",
"链接是否直接播放": "0",
"直接播放链接加前缀": "",
@ -63,7 +63,7 @@
"选集标题": "a&&Text",
"选集链接": "a&&href",
"是否反转选集序列": "0",
"选集链接加前缀": "https://www.91hdec.cc",
"选集链接加前缀": "https://www.91707.cc",
"选集链接加后缀": "",
"筛选数据":{

View file

@ -20,42 +20,42 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "0",
"首页推荐链接": "https://ywy.jsav2.com/video",
"首页列表数组规则": "#videoListPage",
"首页片单列表数组规则": ".colVideoList",
"首页推荐链接": "https://jiuse.io/video",
"首页列表数组规则": "#rd5",
"首页片单列表数组规则": "article",
"首页片单是否Jsoup写法": "1",
"首页片单标题": ".title&&Text",
"首页片单标题": "h4&&a&&Text",
"首页片单链接": "a&&href",
"首页片单图片": ".img&&style",
"首页片单副标题": "'⏱️'+.layer&&Text",
"首页片单链接加前缀": "https://ywy.jsav2.com",
"首页片单图片": "img&&src",
"首页片单副标题": "'⏱️'+.duration&&Text+' 📆'+time&&Text",
"首页片单链接加前缀": "https://jiuse.io",
"首页片单链接加后缀": "",
"分类起始页码": "1",
"分类链接": "https://ywy.jsav2.com/video/category/{cateId}/{catePg}",
"分类链接": "https://jiuse.io/video/category/{cateId}/{catePg}",
//https://iook1.cc/vodtype/1-2.html
//https://iook1.cc/label/new/page/1.html
"分类名称": "最近更新&高清视频&最近加精&当前最热&最近得分&非付费&91原创&10分钟以上&20分钟以上&本月讨论&本月收藏&收藏最多&本月最热&上月最热",
"分类名称替换词": "latest&hd&recent-favorite&hot-list&recent-rating&nonpaid&ori&long-list&longer-list&month-discuss&top-favorite&most-favorite&top-list&top-last",
"分类截取模式": "1",
"分类列表数组规则": "#videoListPage&&.colVideoList",
"分类列表数组规则": "#rd5&&article",
"分类片单是否Jsoup写法": "1",
"分类片单标题": ".title&&Text",
"分类片单标题": "h4&&a&&Text",
"分类片单链接": "a&&href",
"分类片单图片": ".img&&style",
"分类片单副标题": "'⏱️'+.layer&&Text",
"分类片单链接加前缀": "https://ywy.jsav2.com",
"分类片单图片": "img&&src",
"分类片单副标题": "'⏱️'+.duration&&Text+' 📆'+time&&Text",
"分类片单链接加前缀": "https://jiuse.io",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "https://ywy.jsav2.com/search?keywords={wd}",
"搜索链接": "https://jiuse.io/search?keywords={wd}",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": "#main&&.colVideoList",
"搜索列表数组规则": "#rd5&&article",
"搜索片单是否Jsoup写法": "1",
"搜索片单图片": ".img&&style",
"搜索片单标题": ".title&&Text",
"搜索片单图片": "img&&src",
"搜索片单标题": "h4&&a&&Text",
"搜索片单链接": "a&&href",
"搜索片单副标题": "'⏱️'+.layer&&Text",
"搜索片单链接加前缀": "https://ywy.jsav2.com",
"搜索片单副标题": "'⏱️'+.duration&&Text+' 📆'+time&&Text",
"搜索片单链接加前缀": "https://jiuse.io",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -26,6 +26,8 @@
// body&&.stui-vodlist:has(h4)body&&.stui-vodlisth4:contains:not:matches[:11111=>222]
"首页片单列表数组规则": "li",
//jsouphtml1jsoup()0
// div[vclass^=list-grid]&&[vclass^=v-item]
"首页片单是否Jsoup写法":"1",
//
//

View file

@ -133,6 +133,6 @@
"分析MacPlayer": "0",
"是否开启手动嗅探": "1",
"手动嗅探视频链接关键词": ".m3u8#.mp4",
"手动嗅探视频链接关键词": ".m3u8#.mp4/index.m3u8",
"手动嗅探视频链接过滤词": "edge-hls#baidu.com"
}

View file

@ -7,7 +7,7 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://www.cdnbus.art",
"首页推荐链接": "https://www.javbus.com",
"首页列表数组规则": "#waterfall",
"首页片单列表数组规则": ".item",
"首页片单是否Jsoup写法": "1",
@ -19,7 +19,7 @@
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://hscangku.com/vodtype/{cateId}-{catePg}/",
"分类链接": "https://www.cdnbus.art/{cateId}/page/{catePg}",
"分类链接": "https://www.javbus.com/{cateId}/page/{catePg}",
"分类名称": "无码",
"分类名称替换词": "uncensored",
"分类截取模式": "1",

View file

@ -18,8 +18,8 @@
"分类起始页码": "1",
//"分类链接": "https://hscangku.com/vodtype/{cateId}-{catePg}/",
"分类链接": "https://www.javffm.com/drama/page/{catePg}/?orderby={by}&tvtype={cateId}",
"分类名称": "全部&自拍&无码&欧美&动画&国产&伦理&中文字幕",
"分类名称替换词": "&6&7&porn-2&5&chinese-av-porn&porn&chinese-subtitles",
"分类名称": "全部&无码&亚洲无码&国产&传媒出品&中文字幕",
"分类名称替换词": "&7&asian-uncensored&chinese-av-porn&8&chinese-subtitles",
"分类截取模式": "1",
"分类列表数组规则": "#archive-content&&article",
"分类片单是否Jsoup写法": "1",

80
tv/XYQHiker/krx18.json Normal file
View file

@ -0,0 +1,80 @@
{
"规则名": "krx18-XYQHiker",
"规则作者": "飞鱼",
"请求头参数": "电脑",
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "0",
"首页推荐链接": "https://krx18.com",
"首页列表数组规则": ".videos",
"首页片单列表数组规则": "li",
"首页片单是否Jsoup写法": "1",
"首页片单标题": "a&&title",
"首页片单链接": "a&&href",
"首页片单图片": "img&&src",
"首页片单副标题": "'⏱️'+.video-overlay&&Text+'👍'+.video-rating&&Text",
"首页片单链接加前缀": "",
"首页片单链接加后缀": "",
"分类起始页码": "1",
"分类链接": "https://krx18.com/{cateId}/page/{catePg}/",
"分类名称": "全部&英文字幕&韩国&澳大利亚&比利时&加拿大&中国&丹麦&法国&德国&印度尼西亚&印度&意大利&日本&荷兰&菲律宾&波兰&俄罗斯&新加坡&西班牙&瑞士&台湾&泰国&英国&美国",
"分类名称替换词": "movies&genre/eng-sub&genre/korea&genre/australia&genre/belgium&genre/canada&genre/china&genre/denmark&genre/france&genre/germany&genre/indonesia&genre/india&genre/italy&genre/japan&genre/netherlands&genre/philippines&genre/poland&genre/russia&genre/singapore&genre/spain&genre/switzerland&genre/taiwan&genre/thailand&genre/uk&genre/usa",
"分类截取模式": "1",
"分类列表数组规则": ".module&&article",
"分类片单是否Jsoup写法": "1",
"分类片单标题": ".title&&Text",
"分类片单链接": "a&&href",
"分类片单图片": "img&&data-src||src",
"分类片单副标题": "'📆'+.data&&span&&Text+'👍'+.metadata&&span,1&&Text",
"分类片单链接加前缀": "",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "https://krx18.com/?s={wd}",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": ".module&&article",
"搜索片单是否Jsoup写法": "1",
"搜索片单图片": "img&&src",
"搜索片单标题": ".title&&Text",
"搜索片单链接": "a&&href",
"搜索片单副标题": "'🗓️'+.year&&Text+'👍'+.rating&&Text",
"搜索片单链接加前缀": "",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",
"直接播放链接加后缀": "",
"直接播放直链视频请求头": "",
"分析MacPlayer": "0",
"是否开启手动嗅探": "1",
"手动嗅探视频链接关键词": "m3u8#.m3u8",
"手动嗅探视频链接过滤词": "baidu.com#playhubconnect.com#afcdn.net#.mp4",
"筛选数据":{
"asian/":[
{"key":"cateId","name":"分类","value":[
{"n":"全部","v":""},
{"n":"亚洲","v":"asian/"},
{"n":"91制片厂","v":"7/"},
{"n":"天美传媒","v":"8/"},
{"n":"蜜桃影像","v":"9/"},
{"n":"星空传媒","v":"10/"},
{"n":"皇家华人","v":"11/"},
{"n":"精东影业","v":"12/"},
{"n":"乐播传媒","v":"13/"},
{"n":"成人头条","v":"14/"},
{"n":"兔子先生","v":"15/"},
{"n":"杏吧原创","v":"16/"}
]
},
{"key":"by","name":"排序","value":[
{"n":"更新时间","v":"recent/"},
{"n":"播放次数","v":"popular/"},
{"n":"点赞","v":"rated/"},
{"n":"视频时间","v":"popular/"}]}]}
}

View file

@ -1,14 +1,14 @@
{
//
// https://missav789.com/
//https://missav789.com/
// https://missav.live/
//https://missav.live/
"规则名": "missAV.com-XYQHiker",
"规则作者": "飞鱼",
"请求头参数": "手机",
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://missav789.com/dm428/cn/new",
"首页推荐链接": "https://missav.live/dm428/cn/new",
"首页列表数组规则": ".gap-5",
"首页片单列表数组规则": ".thumbnail",
"首页片单是否Jsoup写法": "1",
@ -20,7 +20,7 @@
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://hscangku.com/vodshow/{cateId}-{catePg}/",
"分类链接": "https://missav789.com/{cateId}?sort={by}&page={catePg}",
"分类链接": "https://missav.live/{cateId}?sort={by}&page={catePg}",
"分类名称": "中文字幕&日本AV&素人&无码影片&国产AV",
"分类名称替换词": "dm264/cn/chinese-subtitle&dm428/cn/new&dm23/cn/siro&dm548/cn/uncensored-leak&dm30/cn/madou",
"分类截取模式": "1",
@ -34,7 +34,7 @@
"分类片单链接加前缀": "",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$PC_UA",
"搜索链接": "https://missav789.com/cn/search/{wd}",
"搜索链接": "https://missav.live/cn/search/{wd}",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": ".gap-5&&.thumbnail",

View file

@ -50,10 +50,10 @@
"直接播放直链视频请求头": "",
"详情是否Jsoup写法":"0",
"类型详情": "<p>類型:&&</p>",
"年代详情": "<p>更新:&&</p>",
"地区详情": "",
"年代详情": "added\">&&</li>",
"地区详情": "views\"><span>&&</li>",
"演员详情": "",
"简介详情": "",
"简介详情": "inlineFree\">&&</span>",
"线路列表数组规则": "#mobileContainer",
"线路标题": "'pornhub高清'",
"播放列表数组规则": "#mobileContainer",

View file

@ -8,7 +8,7 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://www.ptt.sex/zh-hans/?sort=id",
"首页推荐链接": "https://www.pornbest.co/zh-hans/?sort=id",
"首页列表数组规则": "#videos",
"首页片单列表数组规则": ".col-lg-3",
"首页片单是否Jsoup写法": "1",
@ -16,10 +16,10 @@
"首页片单链接": ".card-body&&a&&href",
"首页片单图片": "img&&src",
"首页片单副标题": "更新+span&&Text",
"首页片单链接加前缀": "https://www.ptt.sex",
"首页片单链接加前缀": "https://www.pornbest.co",
"首页片单链接加后缀": "",
"分类起始页码": "1",
"分类链接": "https://www.ptt.sex/zh-hans{cateId}?{by}&page={catePg}",
"分类链接": "https://www.pornbest.co/zh-hans{cateId}?{by}&page={catePg}",
//https://w1218.91p46.com/v.php?category=top&viewtype=basic&page=3
//https://w1218.91p46.com/v.php?next=watch&page=2
//https://w1218.91p46.com/v.php?category=hot&viewtype=basic&page=2
@ -32,14 +32,14 @@
"分类片单链接": ".card-body&&a&&href",
"分类片单图片": "img&&src",
"分类片单副标题": "span&&Text",
"分类片单链接加前缀": "https://www.ptt.sex",
"分类片单链接加前缀": "https://www.pornbest.co",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "https://www.ptt.sex/q/{wd}?category_id=&page={catePg}",
"搜索链接": "https://www.pornbest.co/q/{wd}?category_id=&page={catePg}",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": "#videos&&.col-lg-3",
@ -48,7 +48,7 @@
"搜索片单标题": ".card-body&&a&&Text",
"搜索片单链接": ".card-body&&a&&href",
"搜索片单副标题": "span&&Text",
"搜索片单链接加前缀": "https://www.ptt.sex",
"搜索片单链接加前缀": "https://www.pornbest.co",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -171,5 +171,5 @@
"分析MacPlayer": "0",
"是否开启手动嗅探": "1",
"手动嗅探视频链接关键词": ".m3u8#.mp4",
"手动嗅探视频链接过滤词": "baidu.com"
"手动嗅探视频链接过滤词": "baidu.com#m3u8.jpg"
}

View file

@ -1,5 +1,5 @@
{
//https://rjav.tv
//https://thisav.biz
"规则名": "rjav-XYQHiker",
"规则作者": "飞鱼",
"请求头参数":"手机",
@ -7,7 +7,7 @@
"图片是否需要代理":"0",
"是否开启获取首页数据":"1",
//
"首页推荐链接": "https://rjav.tv/zh/",
"首页推荐链接": "https://thisav.biz/zh/",
//
"首页列表数组规则": ".tab-bd",
//
@ -24,12 +24,12 @@
//
"首页片单副标题":"' ⏱️'+.ico-right&&Text",
//
"首页片单链接加前缀": "https://rjav.tv",
"首页片单链接加前缀": "https://thisav.biz",
//
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://www.l0l.tv/index.php/vod/show/id/{cateId}/page/{catePg}.html",
"分类链接": "https://rjav.tv/zh/videotype/{cateId}-{catePg}.html",
"分类链接": "https://thisav.biz/zh/videotype/{cateId}-{catePg}.html",
"分类名称": "FC2-PPV&日本無碼&馬賽克破壞&國產&日本有碼&MGS動画&中文字幕&動畫&歐美成人&Korean BJ Dance&寫真",
"分类名称替换词": "FC2-PPV&JAV_Uncensored&Mosaic_Removed&Asian_Amateur&JAV_Censored&MGS&JAV+CHN.SUBs&Anime&Western_Porn&Korean_BJ_Dance&Adult_IDOL",
//"筛选数据":{},
@ -40,11 +40,11 @@
"分类片单链接": "a&&href",//
"分类片单图片": "img&&src",
"分类片单副标题":"' ⏱️'+.ico-right&&Text",
"分类片单链接加前缀": "https://rjav.tv",
"分类片单链接加前缀": "https://thisav.biz",
"分类片单链接加后缀": "",
"搜索请求头参数":"User-Agent$MOBILE_UA",
"搜索链接": "https://rjav.tv/zh/vod/search.html?wd={wd}",
"搜索链接": "https://thisav.biz/zh/vod/search.html?wd={wd}",
"POST请求数据":"0",
"搜索截取模式": "1",
"搜索列表数组规则": ".row-space7&&li",
@ -53,7 +53,7 @@
"搜索片单标题": "a&&title",
"搜索片单链接": "a&&href",
"搜索片单副标题":"' ⏱️'+.ico-right&&Text",
"搜索片单链接加前缀": "https://rjav.tv",
"搜索片单链接加前缀": "https://thisav.biz",
"搜索片单链接加后缀": "",
//--------
"链接是否直接播放": "1",

View file

@ -12,7 +12,7 @@
"首页列表数组规则": ".video-list",
"首页片单列表数组规则": ".video-item",
"首页片单是否Jsoup写法": "1",
"首页片单标题": "a&&title",
"首页片单标题": "p&&a&&title",
"首页片单链接": "a&&href",
"首页片单图片": "img&&data-src",
"首页片单副标题": "'⏱️'+.l&&Text+'💿'+.h&&Text",
@ -26,7 +26,7 @@
"分类截取模式": "1",
"分类列表数组规则": ".video-list&&.video-item",
"分类片单是否Jsoup写法": "1",
"分类片单标题": "a&&title",
"分类片单标题": "p&&a&&title",
"分类片单链接": "a&&href",
"分类片单图片": "img&&data-src",
"分类片单副标题": "'⏱️'+.l&&Text+'💿'+.h&&Text",
@ -40,7 +40,7 @@
"搜索列表数组规则": ".video-list&&.video-item",
"搜索片单是否Jsoup写法": "1",
"搜索片单图片": "img&&data-src",
"搜索片单标题": "a&&title",
"搜索片单标题": "p&&a&&title",
"搜索片单链接": "a&&href",
"搜索片单副标题": "'⏱️'+.l&&Text+'💿'+.h&&Text",
"搜索片单链接加前缀": "https://spankbang.com",
@ -2247,5 +2247,5 @@
"分析MacPlayer": "0",
"是否开启手动嗅探": "1",
"手动嗅探视频链接关键词": ".m3u8#.mp4",
"手动嗅探视频链接过滤词": "baidu.com"
"手动嗅探视频链接过滤词": "baidu.com#ptgncdn.com#sacdnssedge.com#tsyndicate.com#vcmdiawe.com"
}

View file

@ -21,11 +21,13 @@
"首页片单链接加前缀": "",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://hscangku.com/vodshow/{cateId}-{catePg}/",
//https://go.stripchatgirls.com
//https://go.mnaspm.com
//go.superchat.shop
"分类链接": "https://go.superchat.shop/api/models?tag={cateId}&forceClient=1&stripcashR=0&limit=200&usePreroll&webp=1&type=popular&timezone=Asia/Shanghai",
//go.rmhfrtnd.com
//https://go.xliirdr.com
//https://go.stripchat.review
"分类链接": "https://go.xliirdr.com/api/models?tag={cateId}&forceClient=1&stripcashR=0&limit=200&usePreroll&webp=1&type=popular&timezone=Asia/Shanghai",
"分类名称": "女主播&情侣&男主播&推荐&免费性爱&群交直播&女同&VR&变性人&新主播",
"分类名称替换词": "girls/chinese&couples/chinese&men/popular&girls/recommended&girls/popular&couples/group-sex&couples/lesbians&girls/vr&trans/popular&girls/new",
"分类截取模式": "0",
@ -36,7 +38,7 @@
"分类片单图片": "snapshotUrl",
"分类片单副标题": "id+'https://edge-hls.doppiocdn.net/hls/'+id+'/master/'+id+'_480p.m3u8'",
"分类片单链接加前缀": "https://zh.superchat.shop/",
"分类片单链接加前缀": "https://zh.stripchat.global/",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$PC_UA",
"搜索链接": "https://zh.stripchat.com/index.php/ajax/suggest?mid=1&wd={wd}",
@ -48,7 +50,7 @@
"搜索片单标题": "name",
"搜索片单链接": "id",
"搜索片单副标题": "",
"搜索片单链接加前缀": "https://zh.stripchat.com/vodplay/",
"搜索片单链接加前缀": "https://zh.stripchat.global/vodplay/",
"搜索片单链接加后缀": "-1-1.html",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -4,14 +4,14 @@
//https://rapidtai.com
//https://taisinba.com
//https://taimadou.com
//https://taitaichoo.com
//https://rapidtai.com
"规则名": "taiav",
"规则作者": "飞鱼",
"请求头参数": "手机",
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://taitaichoo.com/cn/hots",
"首页推荐链接": "https://rapidtai.com/cn/hots",
"首页列表数组规则": ".videos-lists",
"首页片单列表数组规则": ".uk-card",
"首页片单是否Jsoup写法": "1",
@ -19,10 +19,10 @@
"首页片单链接": "a&&href",
"首页片单图片": "img&&src",
"首页片单副标题": ".time&&Text",
"首页片单链接加前缀": "https://taitaichoo.com",
"首页片单链接加前缀": "https://rapidtai.com",
"首页片单链接加后缀": "",
"分类起始页码": "1",
"分类链接": "https://taitaichoo.com/cn/{cateId}?page={catePg}",
"分类链接": "https://rapidtai.com/cn/{cateId}?page={catePg}",
"分类名称": "最新&随机推荐&国产AV&网红主播&无码&有码&身材⋮&着装⋮&剧情⋮&交合⋮&玩法⋮&角色⋮&地点⋮&杂项⋮&女优⋮&更多≡",
"分类名称替换词": "news&random&category/国产AV&category/网红主播&category/无码&category/有码&tag/巨乳&tag/黑絲&tag/誘惑&tag/中出&tag/痴女&tag/主播&tag/汽車&tag/麻豆传媒映画&tag/探花&tag/Korean",
"分类截取模式": "1",
@ -32,10 +32,10 @@
"分类片单链接": "a&&href",
"分类片单图片": "img&&src",
"分类片单副标题": ".time&&Text",
"分类片单链接加前缀": "https://taitaichoo.com",
"分类片单链接加前缀": "https://rapidtai.com",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "https://taitaichoo.com/search?q={wd}",
"搜索链接": "https://rapidtai.com/search?q={wd}",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": ".videos-lists&&.uk-card",
@ -44,7 +44,7 @@
"搜索片单标题": ".uk-margin-remove&&Text",
"搜索片单链接": "a&&href",
"搜索片单副标题": ".time&&Text",
"搜索片单链接加前缀": "https://taitaichoo.com",
"搜索片单链接加前缀": "https://rapidtai.com",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -6,7 +6,7 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://www.ujizz3cn.com/categories/643/young?hl=zh",
"首页推荐链接": "https://www.ujizz4cn.com/categories/643/young?hl=zh",
"首页列表数组规则": "#video_block",
"首页片单列表数组规则": ".th-itm",
"首页片单是否Jsoup写法": "1",
@ -14,11 +14,11 @@
"首页片单链接": "a&&href",
"首页片单图片": "img&&data-src",
"首页片单副标题": "'⏱️'+.time&&Text",
"首页片单链接加前缀": "https://www.ujizz3cn.com",
"首页片单链接加前缀": "https://www.ujizz4cn.com",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://hscangku.com/vodtype/{cateId}-{catePg}/",
"分类链接": "https://www.ujizz3cn.com/{cateId}?hl=zh{by}&p={catePg}",
"分类链接": "https://www.ujizz4cn.com/{cateId}?hl=zh{by}&p={catePg}",
//https://www.ujizzcn.com/videos?hl=zh&s=n&p=2
//https://www.ujizzcn.com/videos?hl=zh&p=2
"分类名称": "日本成人片&亚洲女&体内射精&爸爸&中国妞&年轻&日本妞&妈妈&处女&可爱&业余&大学&青少年&不是女儿&乱伦&爸爸和女儿&美女&俄罗斯大美女&大乳房&女朋友&丝袜&18-19&完美身材&娇小&女学生&台湾妞",
@ -30,10 +30,10 @@
"分类片单链接": "a&&href",
"分类片单图片": "img&&data-src",
"分类片单副标题": "'⏱️'+.time&&Text",
"分类片单链接加前缀": "https://www.ujizz3cn.com",
"分类片单链接加前缀": "https://www.ujizz4cn.com",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "https://www.ujizz3cn.com/search?search={wd}&hl=zh",
"搜索链接": "https://www.ujizz4cn.com/search?search={wd}&hl=zh",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": ".th&&.th-itm",
@ -42,10 +42,10 @@
"搜索片单标题": "p&&Text",
"搜索片单链接": "a&&href",
"搜索片单副标题": "'⏱️'+.time&&Text",
"搜索片单链接加前缀": "https://www.ujizz3cn.com",
"搜索片单链接加前缀": "https://www.ujizz4cn.com",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",
"直接播放链接加前缀": "https://www.ujizz3cn.com",
"直接播放链接加前缀": "https://www.ujizz4cn.com",
"直接播放链接加后缀": "",
"直接播放直链视频请求头": "",

View file

@ -8,18 +8,18 @@
//https://zh.xhamster19.com/
"规则名": "xHamster-XYQHiker",
"规则作者": "飞鱼",
"请求头参数": "手机",
"请求头参数": "电脑",
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://zh.xhamster1.desi",
"首页列表数组规则": "article",
"首页片单列表数组规则": "li:has(img)",
"首页列表数组规则": ".thumb-list",
"首页片单列表数组规则": ".thumb-list__item",
"首页片单是否Jsoup写法": "1",
"首页片单标题": "img&&alt",
"首页片单链接": "a&&href",
"首页片单图片": "img,1&&src",
"首页片单副标题": "'⏱️️'+time&&Text+'▶️'+.video-thumb-views&&Text",
"首页片单副标题": "'⏱️️'+.thumb-image-container__duration&&Text+'▶️'+.video-thumb-views&&Text!views",
"首页片单链接加前缀": "",
"首页片单链接加后缀": "",
"分类起始页码": "1",
@ -28,25 +28,25 @@
"分类名称": "最新&最佳&流行分类&生产&芝士&恋物癖&性取向&年龄&种族&身体&头发&人数&性爱玩具&衣服&角色扮演&场所",
"分类名称替换词": "newest&best/weekly&categories/chinese&categories/3d&categories/69&categories/ballbusting&categories/bisexual&categories/18-year-old&categories/asian&categories/saggy-tits&categories/colored-hair&categories/threesome&categories/fucking-machine&categories/thong&categories/bunny&categories/village",
"分类截取模式": "1",
"分类列表数组规则": ".video_block&&li:has(img)",
"分类列表数组规则": ".thumb-list&&.thumb-list__item",
"分类片单是否Jsoup写法": "1",
"分类片单标题": "img&&alt",
"分类片单链接": "a&&href",
"分类片单图片": "img,1&&src",
"分类片单副标题": "'⏱️️'+time&&Text+'▶️'+.video-thumb-views&&Text",
"分类片单副标题": "'⏱️️'+.thumb-image-container__duration&&Text+'▶️'+.video-thumb-views&&Text!views",
"分类片单链接加前缀": "",
"分类片单链接加后缀": "",
"搜索请求头参数": "手机",
"搜索请求头参数": "电脑",
"搜索链接": "https://zh.xhamster1.desi/search/{wd}",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": ".video_block&&li:has(img)",
"搜索列表数组规则": ".thumb-list&&.thumb-list__item",
"搜索片单是否Jsoup写法": "1",
"搜索片单图片": "img,1&&src",
"搜索片单标题": "img&&alt",
"搜索片单链接": "a&&href",
"搜索片单副标题": "'⏱️️'+time&&Text+'▶️'+.video-thumb-views&&Text",
"搜索片单副标题": "'⏱️️'+.thumb-image-container__duration&&Text+'▶️'+.video-thumb-views&&Text!views",
"搜索片单链接加前缀": "",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",

View file

@ -13,14 +13,14 @@
"分类": "女主播&情侣&男主播&推荐&免费性爱&群交直播&女同&VR&变性人&新主播",
"分类值": "girls/chinese&couples/chinese&men/popular&girls/recommended&girls/popular&couples/group-sex&couples/lesbians&girls/vr&trans/popular&girls/new",
"分类url": "https://go.superchat.shop/api/models?tag={cateId}&forceClient=1&stripcashR=0&limit=200&usePreroll&webp=1&type=popular&timezone=Asia/Shanghai",
"分类url": "https://go.stripchat.review/api/models?tag={cateId}&forceClient=1&stripcashR=0&limit=200&usePreroll&webp=1&type=popular&timezone=Asia/Shanghai",
"二次截取": "",
"数组": "models",
"图片": "snapshotUrl",
"标题": "username",
"副标题": "",
"链接前缀": "https://zh.superchat.shop/",
"链接前缀": "https://zh.stripchat.com/",
"链接后缀": "",
"链接": "username",

View file

@ -13,14 +13,14 @@
"分类": "女主播&情侣&男主播&推荐&免费性爱&群交直播&女同&VR&变性人&新主播",
"分类值": "girls/chinese&couples/chinese&men/popular&girls/recommended&girls/popular&couples/group-sex&couples/lesbians&girls/vr&trans/popular&girls/new",
"分类url": "https://go.superchat.shop/api/models?tag={cateId}&forceClient=1&stripcashR=0&limit=200&usePreroll&webp=1&type=popular&timezone=Asia/Shanghai",
"分类url": "https://go.stripchat.review/api/models?tag={cateId}&forceClient=1&stripcashR=0&limit=200&usePreroll&webp=1&type=popular&timezone=Asia/Shanghai",
"二次截取": "",
"数组": "models",
"图片": "snapshotUrl",
"标题": "username",
"副标题": "[]",
"链接前缀": "https://zh.superchat.shop/",
"副标题": "",
"链接前缀": "https://zh.stripchat.review/",
"链接后缀": "",
"链接": "username",

View file

@ -0,0 +1,301 @@
# -*- coding: utf-8 -*-
# by @嗷呜
import sys
from urllib.parse import urlparse
sys.path.append("..")
import re
import hashlib
import hmac
import random
import string
from Crypto.Util.Padding import unpad
from concurrent.futures import ThreadPoolExecutor
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5, AES
from base64 import b64encode, b64decode
import json
import time
from base.spider import Spider
class Spider(Spider):
def init(self, extend=""):
self.device = self.device_id()
self.host = self.gethost()
pass
def getName(self):
pass
def isVideoFormat(self, url):
pass
def manualVideoCheck(self):
pass
def action(self, action):
pass
def destroy(self):
pass
def homeContent(self, filter):
result = {}
filters = {}
classes = []
bba = self.url()
data = self.fetch(f"{self.host}/api/v1/app/config?pack={bba[0]}&signature={bba[1]}", headers=self.header()).text
data1 = self.aes(data)
dy = {"class": "类型", "area": "地区", "lang": "语言", "year": "年份", "letter": "字母", "by": "排序",
"sort": "排序"}
data1['data']['movie_screen']['sort'].pop(0)
for item in data1['data']['movie_screen']['sort']:
item['n'] = item.pop('name')
item['v'] = item.pop('value')
for item in data1['data']['movie_screen']['filter']:
has_non_empty_field = False
classes.append({"type_name": item["name"], "type_id": str(item["id"])})
for key in dy:
if key in item and item[key]:
has_non_empty_field = True
break
if has_non_empty_field:
filters[str(item["id"])] = []
filters[str(item["id"])].append(
{"key": 'sort', "name": '排序', "value": data1['data']['movie_screen']['sort']})
for dkey in item:
if dkey in dy and item[dkey]:
item[dkey].pop(0)
value_array = [
{"n": value.strip(), "v": value.strip()}
for value in item[dkey]
if value.strip() != ""
]
filters[str(item["id"])].append(
{"key": dkey, "name": dy[dkey], "value": value_array}
)
result["class"] = classes
result["filters"] = filters
return result
def homeVideoContent(self):
bba = self.url()
url = f'{self.host}/api/v1/movie/index_recommend?pack={bba[0]}&signature={bba[1]}'
data = self.fetch(url, headers=self.header()).json()
videos = []
for item in data['data']:
if len(item['list']) > 0:
for it in item['list']:
try:
videos.append(self.voides(it))
except Exception as e:
continue
result = {"list": videos}
return result
def categoryContent(self, tid, pg, filter, extend):
body = {"type_id": tid, "sort": extend.get("sort", "by_default"), "class": extend.get("class", "类型"),
"area": extend.get("area", "地区"), "year": extend.get("year", "年份"), "page": str(pg),
"pageSize": "21"}
result = {}
list = []
bba = self.url(body)
url = f"{self.host}/api/v1/movie/screen/list?pack={bba[0]}&signature={bba[1]}"
data = self.fetch(url, headers=self.header()).json()['data']['list']
for item in data:
list.append(self.voides(item))
result["list"] = list
result["page"] = pg
result["pagecount"] = 9999
result["limit"] = 90
result["total"] = 999999
return result
def detailContent(self, ids):
body = {"id": ids[0]}
bba = self.url(body)
url = f'{self.host}/api/v1/movie/detail?pack={bba[0]}&signature={bba[1]}'
data = self.fetch(url, headers=self.header()).json()['data']
video = {'vod_name': data.get('name'), 'type_name': data.get('type_name'), 'vod_year': data.get('year'),
'vod_area': data.get('area'), 'vod_remarks': data.get('dynami'), 'vod_content': data.get('content')}
play = []
names = []
tasks = []
for itt in data["play_from"]:
name = itt["name"]
a = []
if len(itt["list"]) > 0:
names.append(name)
play.append(self.playeach(itt['list']))
else:
tasks.append({"movie_id": ids[0], "from_code": itt["code"]})
names.append(name)
if tasks:
with ThreadPoolExecutor(max_workers=len(tasks)) as executor:
results = executor.map(self.playlist, tasks)
for result in results:
if result:
play.append(result)
else:
play.append("")
video["vod_play_from"] = "$$$".join(names)
video["vod_play_url"] = "$$$".join(play)
result = {"list": [video]}
return result
def searchContent(self, key, quick, pg=1):
body = {"keyword": key, "sort": "", "type_id": "0", "page": str(pg), "pageSize": "10",
"res_type": "by_movie_name"}
bba = self.url(body)
url = f"{self.host}/api/v1/movie/search?pack={bba[0]}&signature={bba[1]}"
data = self.fetch(url, headers=self.header()).json()['data'].get('list')
videos = []
for it in data:
try:
videos.append(self.voides(it))
except Exception as e:
continue
result = {"list": videos, "page": pg}
return result
def playerContent(self, flag, id, vipFlags):
url = id
if not re.search(r"\.m3u8|\.mp4", url):
try:
data = json.loads(b64decode(id.encode('utf-8')).decode('utf-8'))
bba = self.url(data)
data2 = self.fetch(f"{self.host}/api/v1/movie_addr/parse_url?pack={bba[0]}&signature={bba[1]}",
headers=self.header()).json()['data']
url = data2.get('play_url') or data2.get('download_url')
except Exception as e:
pass
if re.search(r'\.jpg|\.png|\.jpeg', url):
url = self.Mproxy(url)
result = {}
result["parse"] = 0
result["url"] = url
result["header"] = {'user-agent': 'okhttp/4.9.2'}
return result
def localProxy(self, param):
return self.Mlocal(param)
def Mproxy(self, url):
return self.getProxyUrl() + "&url=" + b64encode(url.encode('utf-8')).decode('utf-8') + "&type=m3u8"
def Mlocal(self, param,header=None):
url = self.d64(param["url"])
ydata = self.fetch(url, headers=header, allow_redirects=False)
data = ydata.content.decode('utf-8')
if ydata.headers.get('Location'):
url = ydata.headers['Location']
data = self.fetch(url, headers=header).content.decode('utf-8')
parsed_url = urlparse(url)
durl = parsed_url.scheme + "://" + parsed_url.netloc
lines = data.strip().split('\n')
for index, string in enumerate(lines):
if '#EXT' not in string and 'http' not in string:
last_slash_index = string.rfind('/')
lpath = string[:last_slash_index + 1]
lines[index] = durl + ('' if lpath.startswith('/') else '/') + lpath
data = '\n'.join(lines)
return [200, "application/vnd.apple.mpegur", data]
def device_id(self):
characters = string.ascii_lowercase + string.digits
random_string = ''.join(random.choices(characters, k=32))
return random_string
def gethost(self):
try:
url = 'https://dns.alidns.com/dns-query'
headers = {
'User-Agent': 'okhttp/4.9.2',
'Accept': 'application/dns-message'
}
params = {
'dns': 'AAABAAABAAAAAAAACWJmbTExYXM5ZgdmdXFpeXVuAmNuAAAcAAE'
}
response = self.fetch(url, headers=headers, params=params)
host=self.parse_dns_name(response.content, 12)
return f"https://{host}"
except:
return "https://bfm11as9f.fuqiyun.cn"
def parse_dns_name(self, data, offset):
parts = []
while True:
length = data[offset]
if length == 0:
break
offset += 1
parts.append(data[offset:offset + length].decode('utf-8'))
offset += length
return '.'.join(parts)
def header(self):
headers = {
'User-Agent': 'Android',
'Accept': 'application/prs.55App.v2+json',
'timestamp': str(int(time.time())),
'x-client-setting': '{"pure-mode":0}',
'x-client-uuid': '{"device_id":' + self.device + '}, "type":1,"brand":"Redmi", "model":"M2012K10C", "system_version":30, "sdk_version":"3.1.0.7"}',
'x-client-version': '3096 '
}
return headers
def url(self, id=None):
if not id:
id = {}
id["timestamp"] = str(int(time.time()))
public_key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA02F/kPg5A2NX4qZ5JSns+bjhVMCC6JbTiTKpbgNgiXU+Kkorg6Dj76gS68gB8llhbUKCXjIdygnHPrxVHWfzmzisq9P9awmXBkCk74Skglx2LKHa/mNz9ivg6YzQ5pQFUEWS0DfomGBXVtqvBlOXMCRxp69oWaMsnfjnBV+0J7vHbXzUIkqBLdXSNfM9Ag5qdRDrJC3CqB65EJ3ARWVzZTTcXSdMW9i3qzEZPawPNPe5yPYbMZIoXLcrqvEZnRK1oak67/ihf7iwPJqdc+68ZYEmmdqwunOvRdjq89fQMVelmqcRD9RYe08v+xDxG9Co9z7hcXGTsUquMxkh29uNawIDAQAB'
encrypted_text = json.dumps(id)
public_key = RSA.import_key(b64decode(public_key))
cipher = PKCS1_v1_5.new(public_key)
encrypted_message = cipher.encrypt(encrypted_text.encode('utf-8'))
encrypted_message_base64 = b64encode(encrypted_message).decode('utf-8')
result = encrypted_message_base64.replace('+', '-').replace('/', '_').replace('=', '')
key = '635a580fcb5dc6e60caa39c31a7bde48'
sign = hmac.new(key.encode(), result.encode(), hashlib.md5).hexdigest()
return result, sign
def playlist(self, body):
try:
bba = self.url(body)
url = f'{self.host}/api/v1/movie_addr/list?pack={bba[0]}&signature={bba[1]}'
data = self.fetch(url, headers=self.header()).json()['data']
return self.playeach(data)
except Exception:
return []
def playeach(self, data):
play_urls = []
for it in data:
if re.search(r"mp4|m3u8", it["play_url"]):
play_urls.append(f"{it['episode_name']}${it['play_url']}")
else:
vd={"from_code": it['from_code'], "play_url": it['play_url'], "episode_id": it['episode_id'], "type": "play"}
play_urls.append(
f"{it['episode_name']}${b64encode(json.dumps(vd).encode('utf-8')).decode('utf-8')}"
)
return '#'.join(play_urls)
def voides(self, item):
if item['name'] or item['title']:
voide = {
"vod_id": item.get('id') or item.get('click'),
'vod_name': item.get('name') or item.get('title'),
'vod_pic': item.get('cover') or item.get('image'),
'vod_year': item.get('year') or item.get('label'),
'vod_remarks': item.get('dynamic') or item.get('sub_title')
}
return voide
def aes(self, text):
text = text.replace('-', '+').replace('_', '/') + '=='
key = b"e6d5de5fcc51f53d"
iv = b"2f13eef7dfc6c613"
cipher = AES.new(key, AES.MODE_CBC, iv)
pt = unpad(cipher.decrypt(b64decode(text)), AES.block_size).decode("utf-8")
return json.loads(pt)

View file

@ -10,7 +10,7 @@
"图片是否需要代理":"0",
"是否开启获取首页数据": "1",
//
"首页推荐链接": "https://www.grofos.xyz:6699",
"首页推荐链接": "https://www.reoxooe.com:2096",
//
"首页列表数组规则": ".recommended",
//
@ -27,12 +27,12 @@
//
"首页片单副标题":".right-list&&Text||p&&Text+.views&&Text",
//
"首页片单链接加前缀": "https://www.grofos.xyz:6699",
"首页片单链接加前缀": "https://www.reoxooe.com:2096",
//
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://www.l0l.tv/index.php/vod/show/id/{cateId}/page/{catePg}.html",
"分类链接": "https://www.grofos.xyz:6699/category/2.html?category_id={cateId}&page={catePg}",
"分类链接": "https://www.reoxooe.com:2096/category/2.html?category_id={cateId}&page={catePg}",
"分类名称": "国产&原创&传媒&日韩&欧美&动漫&AI换脸&主播&AV解说&同性",
"分类名称替换词": "1&40&2&3&4&5&6&7&8&10",
//"筛选数据":{},
@ -43,10 +43,10 @@
"分类片单链接": "a&&href",
"分类片单图片": "img&&data-src",
"分类片单副标题":".pre-time&&Text+'👁️'+.pre-eye&&Text",
"分类片单链接加前缀":"https://www.grofos.xyz:6699",
"分类片单链接加前缀":"https://www.reoxooe.com:2096",
"分类片单链接加后缀": "",
"搜索请求头参数":"User-Agent$PC_UA",
"搜索链接": "https://www.grofos.xyz:6699/search/1.html?keyword={wd}",
"搜索链接": "https://www.reoxooe.com:2096/search/1.html?keyword={wd}",
"POST请求数据":"0",
"搜索截取模式": "1",
"搜索列表数组规则": ".recommended&&.col-md-2",

View file

@ -24,7 +24,7 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "0",
"首页推荐链接": "https://anga.wiacgbl.com",
"首页推荐链接": "https://hjgut.b2vcgbl.cc",
"首页列表数组规则": ".main",
"首页片单列表数组规则": "a:has(:contains(浏览))",
"首页片单是否Jsoup写法": "1",
@ -32,11 +32,11 @@
"首页片单链接": "a&&href",
"首页片单图片": "img&&src",
"首页片单副标题": "",
"首页片单链接加前缀": "https://anga.wiacgbl.com",
"首页片单链接加前缀": "https://hjgut.b2vcgbl.cc",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://rouv98.xyz/vodtype/{cateId}-{catePg}/",
"分类链接": "https://anga.wiacgbl.com/{cateId}?page={catePg}/",
"分类链接": "https://hjgut.b2vcgbl.cc/{cateId}?page={catePg}/",
"分类名称": "首页&今日吃瓜&最热头条&网红爆料&反差爆料&聚焦时事&国产精品&校园瓜闻&吃瓜搞笑&独家出品&电影天堂&海角论坛&领导秘事&暗网猎奇&成人短剧&成人小课堂&动漫之家",
"分类名称替换词": "&category/1&category/2&category/3&category/4&category/5&category/6&category/7&category/8&category/54643&category/9&category/18321&category/10&category/19301&category/34638&category/54627&category/54628",
"分类截取模式": "1",
@ -46,10 +46,10 @@
"分类片单链接": "a&href",
"分类片单图片": "img&&src",
"分类片单副标题": "",
"分类片单链接加前缀": "https://anga.wiacgbl.com",
"分类片单链接加前缀": "https://hjgut.b2vcgbl.cc",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "https://anga.wiacgbl.com/search/{wd}/",
"搜索链接": "https://hjgut.b2vcgbl.cc/search/{wd}/",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": ".main&&a:has(:contains(浏览))",
@ -58,7 +58,7 @@
"搜索片单标题": "img&&alt",
"搜索片单链接": "a&&href",
"搜索片单副标题": "",
"搜索片单链接加前缀": "https://anga.wiacgbl.com",
"搜索片单链接加前缀": "https://hjgut.b2vcgbl.cc",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -34,7 +34,7 @@
//"分类链接": "https://www.l0l.tv/index.php/vod/show/id/{cateId}/page/{catePg}.html",
"分类链接": "https://www.2025gu.com/{cateId}/time-{catePg}.html",
"分类名称": "全部视频&国产视频&日韩视频&欧美视频&动漫视频&制服人妻&自拍自慰&群交颜射&写真伦理",
"分类名称替换词": "sortlist/2138&sortlist/2139&sortlist/2140&sortlist/2141&sortlist/2142&sortlist/2143&sortlist/2144&sortlist/2145&sortlist/2146",
"分类名称替换词": "sortlist&sortlist/5342&sortlist/5343&sortlist/5344&sortlist/5345&sortlist/5346&sortlist/5347&sortlist/5348&sortlist/5349",
//"筛选数据":{},
"分类截取模式": "1",
"分类列表数组规则": ".stui-vodlist.clearfix&&li",

View file

@ -8,19 +8,19 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://b7iy37iy.six-jokerlu.buzz/index.php/vodtype/",
"首页推荐链接": "https://12noiq413c.jokerlu-wind.buzz/index.php/vodtype/",
"首页列表数组规则": ".recommended",
"首页片单列表数组规则": ".col-md-2",
"首页片单是否Jsoup写法": "1",
"首页片单标题": ".title&&Text",
"首页片单链接": "a&&href",
"首页片单图片": "img&&src",
"首页片单图片": "img&&data-src",
"首页片单副标题": "'📅'+.time&&Text",
"首页片单链接加前缀": "https://b7iy37iy.six-jokerlu.buzz",
"首页片单链接加前缀": "https://12noiq413c.jokerlu-wind.buzz",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://hscangku.com/vodtype/{cateId}-{catePg}/",
"分类链接": "https://b7iy37iy.six-jokerlu.buzz/index.php/vodtype/{cateId}-{catePg}.html",
"分类链接": "https://12noiq413c.jokerlu-wind.buzz/index.php/vodtype/{cateId}-{catePg}.html",
"分类名称": "全部视频&HongKongDoll&国产传媒&国产视频&日本视频&泰国视频&欧美视频&动画视频&中文字幕&VR&韩国视频",
"分类名称替换词": "0&133&115&1&2&84&5&49&9&3&4",
"分类截取模式": "1",
@ -28,12 +28,12 @@
"分类片单是否Jsoup写法": "1",
"分类片单标题": ".title&&Text",
"分类片单链接": "a&&href",
"分类片单图片": ".resent-grid-img&&img&&src",
"分类片单图片": ".resent-grid-img&&img&&data-src",
"分类片单副标题": "'📅'+.time&&p&&Text+'🔥'+.views&&Text",
"分类片单链接加前缀": "https://b7iy37iy.six-jokerlu.buzz",
"分类片单链接加前缀": "https://12noiq413c.jokerlu-wind.buzz",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$PC_UA",
"搜索链接": "https://b7iy37iy.six-jokerlu.buzz/index.php/ajax/suggest?mid=1&wd={wd}",
"搜索链接": "https://12noiq413c.jokerlu-wind.buzz/index.php/ajax/suggest?mid=1&wd={wd}",
"POST请求数据": "",
"搜索截取模式": "0",
"搜索列表数组规则": "list",
@ -42,7 +42,7 @@
"搜索片单标题": "name",
"搜索片单链接": "id",
"搜索片单副标题": "",
"搜索片单链接加前缀": "https://b7iy37iy.six-jokerlu.buzz/index.php/vodplay/",
"搜索片单链接加前缀": "https://12noiq413c.jokerlu-wind.buzz/index.php/vodplay/",
"搜索片单链接加后缀": "-1-1.html",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -6,18 +6,18 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://cn.xszav2.com",
"首页推荐链接": "https://cn.xszav3.com",
"首页列表数组规则": "body",
"首页片单列表数组规则": ".thumbnail",
"首页片单是否Jsoup写法": "1",
"首页片单标题": ".text-sm&&Text",
"首页片单链接": "a&&href",
"首页片单图片": "img&&data-src",
"首页片单图片": "img&&src",
"首页片单副标题": ".text-xs&&Text",
"首页片单链接加前缀": "",
"首页片单链接加前缀": "https://cn.xszav3.com",
"首页片单链接加后缀": "",
"分类起始页码": "1",
"分类链接": "https://cn.xszav2.com/videos/{cateId}?page={catePg}",
"分类链接": "https://cn.xszav3.com/videos/{cateId}?page={catePg}",
//https://iook1.cc/vodtype/1-2.html
//https://iook1.cc/label/new/page/1.html
//"分类链接":"https://iookk.cc/vodshow/{cateId}--{by}------{catePg}---.html"
@ -28,21 +28,21 @@
"分类片单是否Jsoup写法": "1",
"分类片单标题": ".text-sm&&Text",
"分类片单链接": "a&&href",
"分类片单图片": "img&&data-src",
"分类片单图片": "img&&src",
"分类片单副标题": ".text-xs&&Text",
"分类片单链接加前缀": "",
"分类片单链接加前缀": "https://cn.xszav3.com",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "https://cn.xszav2.com/search/videos/{wd}",
"搜索链接": "https://cn.xszav3.com/search/videos/{wd}",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": "body&&.content-row&&.col-xl-3",
"搜索片单是否Jsoup写法": "1",
"搜索片单图片": "img&&data-src",
"搜索片单图片": "img&&src",
"搜索片单标题": ".content-info&&Text",
"搜索片单链接": "a&&href",
"搜索片单副标题": ".duration&&Text",
"搜索片单链接加前缀": "https://cn.xszav2.com",
"搜索片单链接加前缀": "https://cn.xszav3.com",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -35,11 +35,11 @@
"分类名称替换词": "series-63824a975d8ae&series-6206216719462&series-6030196781d85&series-617d3e7acdcc8&series-60192e83c9e05&series-61c4d9b653b6d",
//"筛选数据":{},
"分类截取模式": "1",
"分类列表数组规则": ".videos&&.item",
"分类列表数组规则": ".video-list&&.item",
"分类片单是否Jsoup写法":"1",
"分类片单标题": ".text&&a&&Text",
"分类片单链接": ".text&&a&&href",
"分类片单图片": ".preview-container&&data-poster",
"分类片单标题": ".title&&a&&Text",
"分类片单链接": "a&&href",
"分类片单图片": ".img&&style",
"分类片单副标题":"'⏱️'+.duration&&Text+.series&&Text",
"分类片单链接加前缀": "https://xchina.co",
"分类片单链接加后缀": "",

View file

@ -2,14 +2,14 @@
//
// https://m.uaa.com/
//https://m.uaa.com/
//https://m.uaa004.com
//https://www.uaa202410.com
"规则名": "有爱爱uaa-XYQHiker",
"规则作者": "飞鱼",
"请求头参数": "手机",
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "0",
"首页推荐链接": "https://m.uaa004.com",
"首页推荐链接": "https://www.uaa202410.com",
"首页列表数组规则": ".list-videos",
"首页片单列表数组规则": ".item",
"首页片单是否Jsoup写法": "1",
@ -20,7 +20,7 @@
"首页片单链接加前缀": "",
"首页片单链接加后缀": "",
"分类起始页码": "1",
"分类链接": "https://m.uaa004.com/api/video/app/video/search?actress=&category={class}&orderType={by}&origin={cateId}&page={catePg}&size=24&theme=",
"分类链接": "https://www.uaa202410.com/api/video/app/video/search?actress=&category={class}&orderType={by}&origin={cateId}&page={catePg}&size=24&theme=",
"分类名称": "全部&国产视频&日本AV&H动漫",
"分类名称替换词": "&1&2&3",
"分类截取模式": "0",
@ -34,7 +34,7 @@
"分类片单链接加前缀": "",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$PC_UA",
"搜索链接": "https://m.uaa004.com/api/video/app/video/search?actress=&keyword={wd}&orderType=0&page=1&searchType=1&size=24&theme=",
"搜索链接": "https://www.uaa202410.com/api/video/app/video/search?actress=&keyword={wd}&orderType=0&page=1&searchType=1&size=24&theme=",
"POST请求数据": "",
"搜索截取模式": "0",
"搜索列表数组规则": "model.data",
@ -63,7 +63,7 @@
"选集标题": "a&&Text",
"选集链接": "a&&href",
"是否反转选集序列": "0",
"选集链接加前缀": "https://m.uaa004.com",
"选集链接加前缀": "https://www.uaa202410.com",
"选集链接加后缀": "",
"筛选数据":{

View file

@ -1,12 +1,12 @@
{
//https://likeav.fun/
//https://www.haomov.com/
"规则名": "爱上AV",
"规则作者": "飞鱼",
"请求头参数": "PC_UA",
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://likeav.fun",
"首页推荐链接": "https://www.haomov.com",
"首页列表数组规则": "#list_videos_most_recent_videos_items",
"首页片单列表数组规则": ".item",
"首页片单是否Jsoup写法": "1",
@ -14,12 +14,12 @@
"首页片单链接": "a&&href",
"首页片单图片": ".img&&img&&data-original",
"首页片单副标题": "'⏱️'+.is-hd&&Text+'🌟'+.added&&Text",
"首页片单链接加前缀": "https://likeav.fun",
"首页片单链接加前缀": "https://www.haomov.com",
"首页片单链接加后缀": "",
"分类起始页码": "1",
"分类链接": "https://likeav.fun/{cateId}{catePg}.html",
//https://likeav.fun/vodtype/1-2.html
//https://likeav.fun/label/new/page/1.html
"分类链接": "https://www.haomov.com/{cateId}{catePg}.html",
//https://www.haomov.com/vodtype/1-2.html
//https://www.haomov.com/label/new/page/1.html
//"分类链接":"https://iookk.cc/vodshow/{cateId}--{by}------{catePg}---.html"
"分类名称": "最新&精品推荐&日韩精品&国产视频&激情动漫&伦理&欧美视频",
"分类名称替换词": "label/new/page/&vodtype/1-&vodtype/2-&vodtype/20-&vodtype/4-&vodtype/27-&vodtype/25-",
@ -30,10 +30,10 @@
"分类片单链接": "a&&href",
"分类片单图片": ".img&&img&&data-original",
"分类片单副标题": "'⏱️'+.is-hd&&Text+'🌟'+.added&&Text",
"分类片单链接加前缀": "https://likeav.fun",
"分类片单链接加前缀": "https://www.haomov.com",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "https://likeav.fun/vod/search.html?wd={wd}",
"搜索链接": "https://www.haomov.com/vod/search.html?wd={wd}",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": "#list_videos_videos_list_search_result_items&&.item",
@ -42,7 +42,7 @@
"搜索片单标题": ".title&&Text",
"搜索片单链接": "a&&href",
"搜索片单副标题": "'⏱️'+.is-hd&&Text+.added&&Text",
"搜索片单链接加前缀": "https://likeav.fun",
"搜索片单链接加前缀": "https://www.haomov.com",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -24,11 +24,11 @@
"分类名称": "最新&热门&传媒学院&标签&演员",
"分类名称替换词": "latest&hot/yesterday&麻豆传媒映画&tag/乱伦&star/孟若羽",
"分类截取模式": "1",
"分类列表数组规则": ".row:has(ins)&&.video-item",
"分类列表数组规则": "div[class*=container-fluid]&&.video-item",
"分类片单是否Jsoup写法": "1",
"分类片单标题": ".video-info&&Text",
"分类片单链接": "a&&href",
"分类片单图片": "img&&data-src",
"分类片单图片": "img&&data-src||src",
"分类片单副标题": "'⏱️'+.duration&&Text+'📅'+.date&&Text",
"分类片单链接加前缀": "",

View file

@ -28,15 +28,15 @@
"首页片单链接加前缀": "",
"首页片单链接加后缀": "",
"分类起始页码": "1",
"分类链接": "http://api.vipmisss.com:81/mf/jsonDancelife.txt",
"分类链接": "http://api.hclyz.com:81/mf/json.txt",
"分类名称": "直播大全",
"分类名称替换词": "jsonweishizhibo",
"分类截取模式": "0",
"分类列表数组规则": "zhubo",
"分类列表数组规则": "pingtai",
"分类片单是否Jsoup写法": "1",
"分类片单标题": "title",
"分类片单链接": "address",
"分类片单图片": "img",
"分类片单图片": "xinimg",
"分类片单副标题": "Number",
"分类片单链接加前缀": "",
@ -53,7 +53,7 @@
"搜索片单副标题": "",
"搜索片单链接加前缀": "",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",
"链接是否直接播放": "0",
"直接播放链接加前缀": "",
"直接播放链接加后缀": "",
"直接播放直链视频请求头": "",
@ -66,10 +66,10 @@
"线路列表数组规则": "",
"线路标题": "",
"播放列表数组规则": "",
"选集列表数组规则": "",
"选集标题链接是否Jsoup写法":"0",
"选集标题": "",
"选集链接": "",
"选集列表数组规则": "zhubo",
"选集标题链接是否Jsoup写法":"1",
"选集标题": "title",
"选集链接": "address",
"是否反转选集序列": "0",
"选集链接加前缀": "",
"选集链接加后缀": "",

View file

@ -8,14 +8,14 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://www.ht33p.vip:9527",
"首页列表数组规则": ".pinkred-v-list",
"首页片单列表数组规则": ".pinkred-v-item",
"首页推荐链接": "https://www.htkt140.vip:9527",
"首页列表数组规则": "div[vclass^=list-grid]",
"首页片单列表数组规则": "[vclass^=v-item]",
"首页片单是否Jsoup写法": "1",
"首页片单标题": ".pinkred-v-title&&Text",
"首页片单链接": "a&&href",
"首页片单图片": ".pinkred-v-preview&&data-original",
"首页片单副标题": "'👁️'+.pinkred-v-hits&&Text+'⏱'+.pinkred-v-duration&&Text",
"首页片单标题": "[vclass^=v-title]&&Text",
"首页片单链接": "a&&data-href",
"首页片单图片": "img&&data-original",
"首页片单副标题": "'👁️'+[vclass*=v-hits]&&Text+' ⏱'+[vclass*=v-duration]&&Text",
"首页片单链接加前缀": "",
"首页片单链接加后缀": "",
"分类起始页码": "1",
@ -27,29 +27,29 @@
//{lang}
//{catePg}
//{year}
"分类链接": "https://www.ht33p.vip:9527/type/{cateId}/{area}-{class}-{by}-{catePg}",
"分类链接": "https://www.htkt140.vip:9527/type/{cateId}/{area}-{class}-{by}-{catePg}",
"分类名称": "国产&传媒&日韩&解说&动漫&欧美&三级片&ai换脸&同性&短视频&女优",
"分类名称替换词": "guochan&chuanmei&rihan&zongyi&dongman&oumei&sanjipian&AIhuanlian&tongxing&duanshipin&nvyou",
"分类截取模式": "1",
"分类列表数组规则": ".pinkred-v-list&&.pinkred-v-item",
"分类列表数组规则": "div[vclass^=list-grid]&&[vclass^=v-item]",
"分类片单是否Jsoup写法": "1",
"分类片单标题": ".pinkred-v-title&&Text",
"分类片单链接": "a&&href",
"分类片单图片": ".pinkred-v-preview&&data-original",
"分类片单副标题": "'👁️'+.pinkred-v-hits&&Text+'⏱'+.pinkred-v-duration&&Text",
"分类片单链接加前缀": "https://www.ht33p.vip:9527",
"分类片单标题": "[vclass^=v-title]&&Text",
"分类片单链接": "a&&data-href",
"分类片单图片": "img&&data-original",
"分类片单副标题": "'👁️'+[vclass*=v-hits]&&Text+' ⏱'+[vclass*=v-duration]&&Text",
"分类片单链接加前缀": "https://www.htkt140.vip:9527",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$MOBILE",
"搜索链接": "https://www.ht33p.vip:9527/search/{wd}/",
"搜索链接": "https://www.htkt140.vip:9527/search/{wd}/",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": ".pinkred-v-list&&.pinkred-v-item",
"搜索列表数组规则": "div[vclass^=list-grid]&&[vclass^=v-item]",
"搜索片单是否Jsoup写法": "1",
"搜索片单图片": ".pinkred-v-preview&&data-original",
"搜索片单标题": ".pinkred-v-title&&Text",
"搜索片单链接": "a&&href",
"搜索片单副标题": "'👁️'+.pinkred-v-hits&&Text+'⏱'+.pinkred-v-duration&&Text",
"搜索片单链接加前缀": "",
"搜索片单图片": "img&&data-original",
"搜索片单标题": "[vclass^=v-title]&&Text",
"搜索片单链接": "a&&data-href",
"搜索片单副标题": "'👁️'+[vclass*=v-hits]&&Text+' ⏱'+[vclass*=v-duration]&&Text",
"搜索片单链接加前缀": "https://www.htkt140.vip:9527",
"搜索片单链接加后缀": "",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -1,14 +1,14 @@
{
//apple24.cc
// https://www.appleav9.buzz/
//https://www.appleav9.buzz/
// https://www.apple12.xyz/
//https://www.apple12.xyz/
"规则名": "苹果AV-XYQHiker",
"规则作者": "飞鱼",
"请求头参数": "手机",
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://www.appleav9.buzz/vod/search/by/time.html",
"首页推荐链接": "https://www.apple12.xyz/vod/search/by/time.html",
"首页列表数组规则": ".list-videos",
"首页片单列表数组规则": ".item",
"首页片单是否Jsoup写法": "1",
@ -16,11 +16,11 @@
"首页片单链接": "a&&href",
"首页片单图片": "img&&data-original",
"首页片单副标题": "'📅'+.added&&Text+'👁️'+.views&&Text",
"首页片单链接加前缀": "https://www.appleav9.buzz",
"首页片单链接加前缀": "https://www.apple12.xyz",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://hscangku.com/vodshow/{cateId}-{catePg}/",
"分类链接": "https://www.appleav9.buzz{cateId}--{by}------{catePg}---.html",
"分类链接": "https://www.apple12.xyz{cateId}--{by}------{catePg}---.html",
"分类名称": "国产视频&日韩视频&精品推荐&网爆泄密&3D动漫&欧美字幕&伦理三级&重口猎奇",
"分类名称替换词": "/vodshow/1&/vodshow/2&/vodshow/21&/vodshow/3&/vodshow/4&/vodshow/5&/vodshow/20&/vodshow/22",
"分类截取模式": "1",
@ -31,10 +31,10 @@
"分类片单图片": "img&&data-original",
"分类片单副标题": "'📅'+.added&&Text+'👁️'+.views&&Text",
"分类片单链接加前缀": "https://www.appleav9.buzz",
"分类片单链接加前缀": "https://www.apple12.xyz",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$PC_UA",
"搜索链接": "https://www.appleav9.buzz/index.php/ajax/suggest?mid=1&wd={wd}",
"搜索链接": "https://www.apple12.xyz/index.php/ajax/suggest?mid=1&wd={wd}",
"POST请求数据": "",
"搜索截取模式": "0",
"搜索列表数组规则": "list",
@ -43,7 +43,7 @@
"搜索片单标题": "name",
"搜索片单链接": "id",
"搜索片单副标题": "",
"搜索片单链接加前缀": "https://www.appleav9.buzz/vodplay/",
"搜索片单链接加前缀": "https://www.apple12.xyz/vodplay/",
"搜索片单链接加后缀": "-1-1.html",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",
@ -63,7 +63,7 @@
"选集标题": "a&&Text",
"选集链接": "a&&href",
"是否反转选集序列": "0",
"选集链接加前缀": "https://www.appleav9.buzz",
"选集链接加前缀": "https://www.apple12.xyz",
"选集链接加后缀": "",
"筛选数据":{

View file

@ -1,5 +1,5 @@
{
// https://shise.me/
// https://shise.me/
"规则名": "视色-XYQHiker",
"规则作者": "飞鱼",
@ -15,34 +15,34 @@
"首页片单链接": "a&&href",
"首页片单图片": ".video-cover&&style",
"首页片单副标题": ".duration&&Text+' '+.tags&&.tag&&Text",
"首页片单链接加前缀": "https://shise.me/",
"首页片单链接加前缀": "https://shise.me",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://hscangku.com/vodtype/{cateId}-{catePg}/",
"分类链接": "https://shise.me/series.html?id={cateId}&page={catePg}",
"分类链接": "https://shise.me/videos/{catePg}/{catePg}.html",
"分类名称": "中文AV&日本AV&模特私拍&业余拍摄&其他影片",
"分类名称替换词": "63824a975d8ae&6206216719462&6030196781d85&617d3e7acdcc8&60192e83c9e05",
"分类名称替换词": "series-63824a975d8ae&6206216719462&6030196781d85&617d3e7acdcc8&60192e83c9e05",
"分类截取模式": "1",
"分类列表数组规则": ".videos&&.video",
"分类列表数组规则": "div[class^=list video-list]&&[class*=item video]",
"分类片单是否Jsoup写法": "1",
"分类片单标题": ".title&&Text",
"分类片单链接": "a&&href",
"分类片单图片": ".video-cover&&style",
"分类片单副标题": ".duration&&Text+' '+.tags&&.tag&&Text",
"分类片单图片": ".img&&style!background-image:url('!');",
"分类片单副标题": "",
"分类片单链接加前缀": "https://shise.me/",
"分类片单链接加前缀": "https://shise.me",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$PC_UA",
"搜索链接": "https://shise.me/search.html?k={wd}",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": ".videos&&.video",
"搜索列表数组规则": "div[class^=list video-list]&&[class*=item video]",
"搜索片单是否Jsoup写法": "1",
"搜索片单图片": ".video-cover&&style",
"搜索片单图片": ".img&&style!background-image:url('!');",
"搜索片单标题": ".title&&Text",
"搜索片单链接": "a&&href",
"搜索片单副标题": ".duration&&Text+' '+.tags&&.tag&&Text",
"搜索片单链接加前缀": "https://shise.me/",
"搜索片单链接加前缀": "https://shise.me",
"搜索片单链接加后缀": "",
"链接是否直接播放": "0",
"直接播放链接加前缀": "",

View file

@ -8,28 +8,30 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "https://www.javrate.com",
"首页列表数组规则": ".body-container:has(img)",
"首页片单列表数组规则": ".col-xl-2",
"首页推荐链接": "https://www.javrate.com/movie/new",
"首页列表数组规则": "section[class*=container-fluid]",
"首页片单列表数组规则": ".mgn-item",
"首页片单是否Jsoup写法": "1",
"首页片单标题": ".movie-box-title&&Text",
"首页片单标题": "h3&&Text",
"首页片单链接": "a&&href",
"首页片单图片": "img&&src",
"首页片单副标题": "'📅'+.justify-content-between&&label,1&&Text+label,1&&Text+'⭐'+.justify-content-between&&label,0&&Text",
"首页片单副标题": "'📅'+label[class=mgn-date]&&Text+' '+.mgn-badge-type&&Text",
"首页片单链接加前缀": "https://www.javrate.com",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://hscangku.com/vodshow/{cateId}-{catePg}/",
"分类链接": "https://www.javrate.com{cateId}?page={catePg}",
//https://www.javrate.com/menu/censored/5-2-4
//https://www.javrate.com/menu/uncensored/5-2-3
"分类链接": "https://www.javrate.com{cateId}?page=2{catePg}",
"分类名称": "最新更新&無碼A片&日本A片&國產AV&最多人看&最佳A片&类型&剧情&职业&关系&衣着&特征&主题&角色状态&做爱玩法&习惯癖好&颜值身材&场景地点",
"分类名称替换词": "/movie/new&/menu/uncensored&/menu/censored&/menu/chinese&/movie/hot&/movie/top&/keywords/movie/劇情&/keywords/movie/出軌&/keywords/movie/女學生&/keywords/movie/姐姐・妹妹&/keywords/movie/黑絲&/keywords/movie/美少女&/keywords/movie/淫亂&/keywords/movie/絕頂高潮&/keywords/movie/中出&/keywords/movie/胸控・戀乳癖&/keywords/movie/美乳&/keywords/movie/酒店",
"分类名称替换词": "/movie/new&/menu/uncensored&/menu/censored&/menu/chinese&/best&/movie/top&/keywords/movie/劇情&/keywords/movie/出軌&/keywords/movie/女學生&/keywords/movie/姐姐・妹妹&/keywords/movie/黑絲&/keywords/movie/美少女&/keywords/movie/淫亂&/keywords/movie/絕頂高潮&/keywords/movie/中出&/keywords/movie/胸控・戀乳癖&/keywords/movie/美乳&/keywords/movie/酒店",
"分类截取模式": "1",
"分类列表数组规则": "section:has(img)&&.col-md-4",
"分类列表数组规则": "section[class*=container-fluid]&&.mgn-item",
"分类片单是否Jsoup写法": "1",
"分类片单标题": ".movie-box-title&&Text",
"分类片单标题": "h3&&Text",
"分类片单链接": "a&&href",
"分类片单图片": "img&&src",
"分类片单副标题": "'📅'+.justify-content-between&&label,1&&Text+label,1&&Text+'⭐'+.justify-content-between&&label,0&&Text",
"分类片单副标题": "'📅'+label[class=mgn-date]&&Text+' '+.mgn-badge-type&&Text",
"分类片单链接加前缀": "https://www.javrate.com",
"分类片单链接加后缀": "",

View file

@ -1,10 +1,10 @@
{
//
// https://madou.club/
// https://madou.club/
//https://madou.club/
"规则名": "麻豆社-XYQHiker",
"规则作者": "飞鱼",
"请求头参数": "手机",
"请求头参数": "电脑",
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
@ -193,6 +193,6 @@
"分析MacPlayer": "0",
"是否开启手动嗅探": "1",
"手动嗅探视频链接关键词": ".m3u8#dash.madou.club",
"手动嗅探视频链接关键词": ".m3u8",
"手动嗅探视频链接过滤词": "baidu.com#.mp4"
}

View file

@ -5,32 +5,32 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "1",
"首页推荐链接": "http://6499ck.cc",
"首页推荐链接": "https://huangsecangku.net",
"首页列表数组规则": ".stui-vodlist.clearfix",
"首页片单列表数组规则": "li:not(:contains(注册即送)):not(:contains(澳门威尼斯人官网)):not(:contains(24小时在线匹配首次免费)):not(:contains(正宗莞式服务一条龙)):not(:contains(博业体育)):not(:contains(少女直播破处.高潮抽搐)):not(:contains(PG娱乐城)):not(:contains(多人操B-自慰调教-高清无码直播)):not(:contains(春药商城.迷奸表妹)):not(:contains(澳门新葡京注册))",
"首页片单列表数组规则": "li:not(:contains(注册即送)):not(:contains(澳门威尼斯人官网)):not(:contains(24小时在线匹配首次免费)):not(:contains(正宗莞式服务一条龙)):not(:contains(博业体育)):not(:contains(少女直播破处.高潮抽搐)):not(:contains(PG娱乐城)):not(:contains(多人操B-自慰调教-高清无码直播)):not(:contains(春药商城.迷奸表妹)):not(:contains(澳门新葡京注册)):not(:contains(迷奸少妇最佳方案请咨询))",
"首页片单是否Jsoup写法": "1",
"首页片单标题": ".title&&Text",
"首页片单链接": "a&&href",
"首页片单图片": "a&&data-original",
"首页片单副标题": ".pic-text.text-right&&Text+'\n👁'+.pull-right,1&&Text",
"首页片单链接加前缀": "http://6499ck.cc",
"首页片单链接加前缀": "https://huangsecangku.net",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://rouv98.xyz/vodtype/{cateId}-{catePg}/",
"分类链接": "http://6499ck.cc/vodtype/{cateId}-{catePg}.html",
"分类链接": "https://huangsecangku.net/vodtype/{cateId}-{catePg}.html",
"分类名称": "无码中文字幕&有码中文字幕&日本无码&日本有码&国产视频&欧美高清&动漫剧情",
"分类名称替换词": "8&9&10&7&15&21&22",
"分类截取模式": "1",
"分类列表数组规则": ".stui-vodlist.clearfix&&li:not(:contains(注册即送)):not(:contains(24小时在线匹配首次免费)):not(:contains(正宗莞式服务一条龙)):not(:contains(少女直播破处.高潮抽搐)):not(:contains(澳门威尼斯人官网)):not(:contains(博业体育)):not(:contains(PG娱乐城)):not(:contains(多人操B-自慰调教-高清无码直播)):not(:contains(春药商城.迷奸表妹)):not(:contains(澳门新葡京注册))",
"分类列表数组规则": ".stui-vodlist.clearfix&&li:not(:contains(注册即送)):not(:contains(24小时在线匹配首次免费)):not(:contains(正宗莞式服务一条龙)):not(:contains(少女直播破处.高潮抽搐)):not(:contains(澳门威尼斯人官网)):not(:contains(博业体育)):not(:contains(PG娱乐城)):not(:contains(多人操B-自慰调教-高清无码直播)):not(:contains(春药商城.迷奸表妹)):not(:contains(澳门新葡京注册)):not(:contains(迷奸少妇最佳方案请咨询))",
"分类片单是否Jsoup写法": "1",
"分类片单标题": ".title&&Text",
"分类片单链接": "a&&href",
"分类片单图片": "a&&data-original",
"分类片单副标题": ".pic-text.text-right&&Text+'\n👁'+.pull-right,1&&Text",
"分类片单链接加前缀": "http://6499ck.cc",
"分类片单链接加前缀": "https://huangsecangku.net",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "http://6499ck.cc/index.php/ajax/suggest?mid=1&wd={wd}",
"搜索链接": "https://huangsecangku.net/index.php/ajax/suggest?mid=1&wd={wd}",
"POST请求数据": "",
"搜索截取模式": "0",
"搜索列表数组规则": "list",
@ -39,7 +39,7 @@
"搜索片单标题": "name",
"搜索片单链接": "id",
"搜索片单副标题": "",
"搜索片单链接加前缀": "http://6499ck.cc/vodplay/",
"搜索片单链接加前缀": "https://huangsecangku.net/vodplay/",
"搜索片单链接加后缀": "-1-1.html",
"链接是否直接播放": "1",
"直接播放链接加前缀": "",

View file

@ -30,7 +30,7 @@
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://www.l0l.tv/index.php/vod/show/id/{cateId}/page/{catePg}.html",
"分类链接": "https://hlcg01.vip/front/api/v1/posts/listByChannel?pageNo={catePg}&pageSize=20&total=0&channelId={cateId}",
"分类链接": "https://hgcl1.com/front/api/v1/posts/listByChannel?pageNo={catePg}&pageSize=20&total=0&channelId={cateId}",
"分类名称": "全部&最新&热门&最多点赞&推荐&热门大瓜&网红明星&反差女友&学生校园&社会事件&奇趣百科&福利看片",
"分类名称替换词": "&order=newest&order=hottest&order=favors&order=featured&1&2&7&16&17&6&3",
//"筛选数据":{},
@ -44,7 +44,7 @@
"分类片单链接加前缀":"",
"分类片单链接加后缀": "",
"搜索请求头参数":"User-Agent$手机",
"搜索链接": "https://hlcg01.vip/front/api/v1/search?pageNo=1&pageSize=50&kw={wd}",
"搜索链接": "https://hgcl1.com/front/api/v1/search?pageNo=1&pageSize=50&kw={wd}",
"POST请求数据":"0",
"搜索截取模式": "0",
"搜索列表数组规则": "data.content",

View file

@ -1,10 +1,12 @@
{
//
//https://heiliaobk.com/
//https://github.com/hlbkw
//https://heiliaocg.com/
// https://kgfr.nsqgbzx.cc
//https://hlbk7.com/
//https://heiliaocg.com
//https://gbzx01.com
//线https://e5uhlbk.com/
//heiliaobaike@gmail.com ()
@ -15,7 +17,7 @@
"网页编码格式": "UTF-8",
"图片是否需要代理": "0",
"是否开启获取首页数据": "0",
"首页推荐链接": "https://kgyo.07ehlbk.com",
"首页推荐链接": "https://jyfru.1fchlbk.com",
"首页列表数组规则": ".stui-vodlist.clearfix",
"首页片单列表数组规则": "li:not(:contains(全国约炮)):not(:contains(注册即送)):not(:contains(澳门威尼斯人官网)):not(:contains(24小时在线匹配首次免费)):not(:contains(正宗莞式服务一条龙)):not(:contains(少女直播破处.高潮抽搐)):not(:contains(17吃瓜同城约炮)):not(:contains(17吃瓜春药商城)):not(:contains(威尼斯信誉)):not(:contains(开云体育)):not(:contains(新葡京体育))",
"首页片单是否Jsoup写法": "1",
@ -23,46 +25,46 @@
"首页片单链接": "a&&href",
"首页片单图片": "a&&data-original",
"首页片单副标题": ".pic-text.text-right&&Text",
"首页片单链接加前缀": "https://kgyo.07ehlbk.com",
"首页片单链接加前缀": "https://jyfru.1fchlbk.com",
"首页片单链接加后缀": "",
"分类起始页码": "1",
//"分类链接": "https://rouv98.xyz/vodtype/{cateId}-{catePg}/",
"分类链接": "https://kgyo.07ehlbk.com{cateId}{catePg}/",
"分类名称": "首页&今日黑料&头条黑料&网红黑料&反差母狗&实时追踪&深夜福利&校园黑料&搞笑趣闻&黑料天堂&政坛黑料&海角论坛&重口猎奇&成人短剧",
"分类名称替换词": "/page/&/category/jrhl/&/category/tthl/&/category/whhl/&/category/fcmg/&/category/sszz/&/category/syfl/&/category/xyhl/&/category/gxqw/&/category/hltt/&/category/zthl/&/category/hjlt/&/category/zklq/&/category/CRDJ/",
"分类链接": "https://jyfru.1fchlbk.com{cateId}?page={catePg}",
"分类名称": "首页&今日爆瓜&校园热瓜&抖阴网红&反差母狗&妙龄少女&淫妻绿奴&合集臻选&瓜爆头条&重口猎奇&海角精品&政坛风云&成人短剧&性爱讲堂&搞笑趣闻&深夜影院&禁漫天堂",
"分类名称替换词": "/&/category/1&/category/7&/category/3&/category/4&/category/18322&/category/2&/category/9&/category/5&/category/12&/category/11&/category/10&/category/13&/category/15&/category/8&/category/16&/category/17",
"分类截取模式": "1",
"分类列表数组规则": ".row&&article:has(h2):not(:contains(全国约炮)):not(:contains(福利推荐)):not(:contains(黑料百科分享天天免费领现金)):not(:contains(17吃瓜春药商城)):not(:contains(威尼斯信誉)):not(:contains(开云体育)):not(:contains(新葡京体育))",
"分类片单是否Jsoup写法": "0",
"分类片单标题": "title\">\n&&\n",
"分类片单链接": "href=\"&&\">",
"分类片单图片": "loadBannerDirect('&&'",
"分类列表数组规则": ".main&&a:has(.item_item-subtitle__y5ZST):not(:matches(黑料百科火热招聘)):not(:matches(热点黑料一口气看完)):not(:matches(万千选择只为您心动 黑料百科与瓜友们共创心仪专栏))",
"分类片单是否Jsoup写法": "1",
"分类片单标题": "img&&alt",
"分类片单链接": "a&&href",
"分类片单图片": "img&&src",
//"分类片单副标题": "+08:00\">\n&&\n",
"分类片单副标题": "content=\"&&+08:00\">",
"分类片单链接加前缀": "",
"分类片单副标题": "p,2&&Text",
"分类片单链接加前缀": "https://jyfru.1fchlbk.com",
"分类片单链接加后缀": "",
"搜索请求头参数": "User-Agent$手机",
"搜索链接": "https://kgyo.07ehlbk.com/search/{wd}/",
"搜索链接": "https://jyfru.1fchlbk.com/search/{wd}",
"POST请求数据": "",
"搜索截取模式": "1",
"搜索列表数组规则": ".row:has(article)&&article",
"搜索片单是否Jsoup写法": "0",
"搜索片单图片": "loadBannerDirect('&&'",
"搜索片单标题": "title\">\n&&\n",
"搜索片单链接": "href=\"&&\">",
"搜索片单副标题": "+08:00\">\n&&\n",
"搜索片单链接加前缀": "",
"搜索列表数组规则": ".main&&a",
"搜索片单是否Jsoup写法": "1",
"搜索片单图片": "img&&src",
"搜索片单标题": "img&&alt",
"搜索片单链接": "a&&href",
"搜索片单副标题": "p,2&&Text",
"搜索片单链接加前缀": "https://jyfru.1fchlbk.com",
"搜索片单链接加后缀": "",
"链接是否直接播放": "0",
"直接播放链接加前缀": "",
"直接播放链接加后缀": "",
"直接播放直链视频请求头": "",
//-------
"详情是否Jsoup写法":"1",
"类型详情": ".post-content&&p:contains(#)&&Text",
"详情是否Jsoup写法":"0",
"类型详情": "tags\":[&&],",
"年代详情": "",
"地区详情": "",
"演员详情": "",
"简介详情": ".post-content&&p:contains()&&Text",
"简介详情": "content\":\"&&\",\"share",
"线路列表数组规则": "",
"线路标题": "",
"播放列表数组规则": ".post-content",

View file

@ -0,0 +1,10 @@
echo "用户:"$(whoami)
if pgrep -x "sshd" >/dev/null
then
echo "sshd运行中..."
else
sshd
echo "自动启动sshd"
fi
debian

View file

@ -0,0 +1,103 @@
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
# . /etc/bash_completion
#fi
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"

View file

@ -0,0 +1,106 @@
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
# . /etc/bash_completion
#fi
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
source hipyenv/bin/activate
cd /hipyenv/redis-3.0.6/src && ./redis-server redis.conf
cd /hipyenv/hipy-server/app/ && python3 main.py

View file

@ -0,0 +1,27 @@
ECHO_SQL=false
AUTO_ADD_PERM_LABEL=true
PORT=7129
RELOAD=false
LOGIN_WITH_CAPTCHA=false
PROJECT_NAME=hipy-嗨派
WEB_DOMAIN=https://hipy-ui.vercel.app
SECRET_KEY=DFGG45645674GHFGHFH
SQLALCHEMY_ENGINE=mysql+pymysql
SQL_HOST=127.0.0.1
SQL_PORT=3306
SQL_USERNAME=root
SQL_PASSWORD=123456
SQL_DATABASE=hipy
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=3
SMTP_HOST=smtp.qq.com
SMTP_USER=john_doe_1996@foxmail.com
SMTP_PASSWORD=ndkhgrgoimyvbhei
EMAIL_FROM_EMAIL=john_doe_1996@foxmail.com
IP_AGENTS=[""]

View file

@ -0,0 +1,88 @@
#!/bin/bash
echo '手机zerotermux——chroot一键搭建HIPY项目————在线搭建'
echo '本脚本测试环境为X86-ubuntu22.04.6LTS其他linux环境根据自己环境修改'
sleep 3
echo '准备安装环境'
echo $(date +%Y-%m-%d\ %H:%M:%S)
rm -rf /hipyenv
rm -rf root/.pyenv
mkdir /hipyenv
echo '拷贝redis项目'
cp -Raf redis-3.0.6 /hipyenv
sleep 3
echo '克隆hipy-server'
echo $(date +%Y-%m-%d\ %H:%M:%S)
cd /hipyenv && git clone https://github.com/hjdhnx/hipy-server.git
echo $(date +%Y-%m-%d\ %H:%M:%S)
echo '拷贝hipy-server数据库环境'
cp -Raf /sd/pywork/hipy-server_build/.env /hipyenv/hipy-server/app/configs
echo '拷贝python3.8.12环境'
cp -Raf /sd/pywork/hipy-server_build/.bashrc2 ~/.bashrc
echo '开始安装虚拟python3.8.12开发环境'
echo '安装依赖项:'
echo $(date +%Y-%m-%d\ %H:%M:%S)
cd /
sudo apt update && sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev git openssl
echo $(date +%Y-%m-%d\ %H:%M:%S)
echo '安装pyenv'
rm -rf root/.pyenv
curl https://pyenv.run | bash
echo 'pyenv安装成功'
echo $(date +%Y-%m-%d\ %H:%M:%S)
sleep 10
echo '在shell配置文件中添加pyenv初始化'
sleep 10
source ~/.bashrc
echo '开始安装Python 3.8.12'
echo '请开梯子大约需要6-8分钟'
echo $(date +%Y-%m-%d\ %H:%M:%S)
pyenv install 3.8.12
echo 'Python 3.8.12安装成功'
echo $(date +%Y-%m-%d\ %H:%M:%S)
echo '设置Python 3.8.12作为全局默认版本:'
pyenv global 3.8.12
echo '验证Python版本'
python --version
echo 'python版本3.8.12成功'
sleep 5
source ~/.bashrc
python3 --version
echo 'python3版本3.8.12成功'
echo 'python3.8.12安装完成'
echo $(date +%Y-%m-%d\ %H:%M:%S)
sleep 5
cp -Raf /sd/pywork/hipy-server_build/.bashrc3 ~/.bashrc
echo '使用venv模块来创建和管理虚拟环境。'
echo $(date +%Y-%m-%d\ %H:%M:%S)
python -m venv hipyenv && source hipyenv/bin/activate
echo 'venv安装成功'
sleep 5
echo '部署hipy-server'
echo $(date +%Y-%m-%d\ %H:%M:%S)
cd /hipyenv/hipy-server/app
echo '安装hipy-server依赖'
apt-get update && apt-get install -y python3-psycopg2 gcc python3-dev g++ default-jdk supervisor libpq-dev
echo $(date +%Y-%m-%d\ %H:%M:%S)
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && pip install --upgrade pip && pip install --upgrade setuptools && pip install --no-cache-dir -r requirements.txt
echo $(date +%Y-%m-%d\ %H:%M:%S)
pip install click pydantic virtualenv setuptools
echo $(date +%Y-%m-%d\ %H:%M:%S)
#pip install --extra-index-url https://nightly.pythonmonkey.io/ --pre pythonmonkey --no-dependencies
sleep 5
echo '安装redis'
echo $(date +%Y-%m-%d\ %H:%M:%S)
cd /hipyenv/redis-3.0.6/src
chmod +x redis-server
echo 'redis安装成功'
echo '启动redis'
./redis-rever redis.conf
echo 'redis启动成功'
echo $(date +%Y-%m-%d\ %H:%M:%S)
echo '运行脚本初始化数据库数据'
cd /hipyenv/hipy-server/app
python3 initial_data.py
exit
sleep 5
exit
sleep 5
cp -Raf ~/storage/downloads/pywork/hipy-server_build/.bashrc .

View file

@ -0,0 +1,28 @@
.*.swp
*.o
*.log
dump.rdb
redis-benchmark
redis-check-aof
redis-check-dump
redis-cli
redis-sentinel
redis-server
doc-tools
release
misc/*
src/release.h
appendonly.aof
SHORT_TERM_TODO
release.h
src/transfer.sh
src/configs
redis.ds
src/redis.conf
src/nodes.conf
deps/lua/src/lua
deps/lua/src/luac
deps/lua/src/liblua.a
.make-*
.prerequisites
*.dSYM

View file

@ -0,0 +1,752 @@
Redis 3.0 release notes
=======================
--------------------------------------------------------------------------------
Upgrade urgency levels:
LOW: No need to upgrade unless there are new features you want to use.
MODERATE: Program an upgrade of the server, but it's not urgent.
HIGH: There is a critical bug that may affect a subset of users. Upgrade!
CRITICAL: There is a critical bug affecting MOST USERS. Upgrade ASAP.
--------------------------------------------------------------------------------
--[ Redis 3.0.6 ] Release date: 18 Dec 2015
Upgrade urgency: MODERATE. We fixed a crash that happens very rarely, so
updating does not hurt, but most users are unlikely to
experience this condition because it requires some odd
timing. However if you are a Redis Cluster user, upgrading
is strongly adviced since this release includes very
important improvements to Redis Cluster.
* [FIX] lua_struct.c/getnum security issue fixed. (Luca Bruno discovered it,
patched by Sun He and Chris Lamb)
* [FIX] Redis Cluster replica migration fixed. See issue #2924 for details.
(Salvatore Sanfilippo)
* [FIX] Fix a race condition in processCommand() because of interactions
with freeMemoryIfNeeded(). Details in issue #2948 and especially
in the commit message d999f5a. (Race found analytically by
Oran Agra, patch by Salvatore Sanfilippo)
* [NEW] Backported from the upcoming Redis 3.2:
MIGRATE now supports an extended multiple-keys pipelined mode, which
is an order of magnitude faster. Redis Cluster now uses this mode
in order to perform reshardings and rebalancings. (Salvatore Sanfilippo)
* [NEW] Backported from the upcoming Redis 3.2:
Redis Cluster has now support for rebalancing via the redis-trib
rebalance command. Demo here:
https://asciinema.org/a/0tw2e5740kouda0yhkqrm5790
Official documentation will be available ASAP. (Salvatore Sanfilippo)
* [NEW] Redis Cluster redis-trib.rb new "info" subcommand.
* [NEW] Redis Cluster tests improved. (Salvatore Sanfilippo)
* [NEW] Log offending memory access address on SIGSEGV/SIGBUS (Salvatore
Sanfilippo)
--[ Redis 3.0.5 ] Release date: 15 Oct 2015
Upgrade urgency: MODERATE, the most important thing is a fix in the replication
code that may make the slave hanging forever if the master
remains with an open socket even if it is no longer able to
reply.
* [FIX] MOVE now moves the TTL as well. A bug lasting forever... finally
fixed thanks to Andy Grunwald that reported it.
(reported by Andy Grunwald, fixed by Salvatore Sanfilippo)
* [FIX] Fix a false positive in HSTRLEN test.
* [FIX] Fix a bug in redis-cli --pipe mode that was not able to read back
replies from the server incrementally. Now a mass import will use
a lot less memory, and you can use --pipe to do incremental streaming.
(reported by Twitter user @fsaintjacques, fixed by Salvatore
Sanfilippo)
* [FIX] Slave detection of master timeout. (fixed by Kevin McGehee, refactoring
and regression test by Salvatore Sanfilippo)
* [NEW] Cluster: redis-trib fix can fix an additional case for opens lots.
(Salvatore Sanfilippo)
* [NEW] Cluster: redis-trib import support for --copy and --replace options
(David Thomson)
--[ Redis 3.0.4 ] Release date: 8 Sep 2015
Upgrade urgency: HIGH for Redis and Sentinel. However note that in order to
fix certain replication bugs, the replication internals were
modified in a very heavy way. So while this release is
conceptually saner, it may contain regressions. For this
reason, before the release, QA activities were performed by
me (antirez) and Redis Labs and no evident bug was found.
* [FIX] A number of bugs related to replication PSYNC and the (yet experimental)
diskless replication feature were fixed. The bugs could lead to
inconsistency between masters and slaves. (Salvatore Sanfilippo, Oran
Agra fixed the issue found by Yuval Inbar)
* [FIX] A replication bug in the context of PSYNC partial resynchonization was
found and fixed. This bug happens even when diskless replication is off
in the case different slaves connect at different times while the master
is creating an RDB file, and later a partial resynchronization is
attempted by a slave that connected not as the first one. (Salvatore
Sanfilippo, Oran Agra)
* [FIX] Chained replication and PSYNC interactions leading to potential stale
chained slaves data set, see issue #2694. (Salvatore Sanfilippo fixed
an issue reported by "GeorgeBJ" user at Github)
* [FIX] redis-cli --scan iteration fixed when returned cursor overflows
32 bit signed integer. (Ofir Luzon, Yuval Inbar)
* [FIX] Sentinel: fixed a bug during the master switch process, where for a
failed conditional check, the new configuration is rewritten, during
a small window of time, in a corrupted way where the master is
also reported to be one of the slaves. This bug is rare to trigger
but apparently it happens in the wild, and the effect is to see
a replication loop where the master will try to replicate with itself.
A detailed explanation of the bug and its effects can be found in
the commit message here: https://github.com/antirez/redis/commit/c20218eb5770b2cafb12bc7092313b8358fedc0a.
The bug was found by Jan-Erik Rediger using a static analyzer and
fixed by Salvatore Sanfilippo.
* [FIX] Sentinel lack of arity checks for certain commands.
(Rogerio Goncalves, Salvatore Sanfilippo)
* [NEW] Replication internals rewritten in order to be more resistant to bugs.
The replication handshake in the slave side was rewritten as a non
blocking state machine. (Salvatore Sanfilippo, Oran Agra)
* [NEW] New "replication capabilities" feature introduced in order to signal
from the master to the slave what are the features supported, so that
the master can choose the kind of replication to start (diskless or
not) when master and slave are of different versions. (Oran Agra,
Salvatore Sanfilippo)
* [NEW] Log clients details when SLAVEOF command is received. (Salvatore
Sanfilippo with inputs from Nick Craver and Marc Gravell).
--[ Redis 3.0.3 ] Release date: 17 Jul 2015
Upgrade urgency: LOW for Redis and Sentinel.
* [FIX] Fix blocking operations timeout precision when HZ is at its default
value (not increased) and there are thousands of clients connected
at the same time. This bug affected Sidekiq users that experienced
a very long delay for BLPOP and similar commands to return for
timeout. Check commit b029ff1 for more info. (Salvatore Sanfilippo)
* [FIX] MIGRATE "creating socket: Invalid argument" error fix. Check
issues #2609 and #2612 for more info. (Salvatore Sanfilippo)
* [FIX] Be able to connect to the master even when the slave is bound to
just the loopback interface and has no valid public address in the
network the master is reacahble. (Salvatore Sanfilippo)
* [FIX] ZADD with options encoding promotion fixed. (linfangrong)
* [FIX] Reset aof_delayed_fsync on CONFIG RESETSTATS. (Tom Kiemes)
* [FIX] PFCOUNT key parsing in cluster fixed. (MOON_CLJ)
* [FIX] Fix Solaris compilation of Redis 3.0. (Jan-Erik Rediger)
* [NEW] Variadic EXISTS command. Now the command accepts multiple arguments
and returns the total count of existing keys.
--[ Redis 3.0.2 ] Release date: 4 Jun 2015
Upgrade urgency: HIGH for Redis because of a security issue.
LOW for Sentinel.
* [FIX] Critical security issue fix by Ben Murphy: http://t.co/LpGTyZmfS7
* [FIX] SMOVE reply fixed when src and dst keys are the same. (Glenn Nethercutt)
* [FIX] Lua cmsgpack lib updated to support str8 type. (Sebastian Waisbrot)
* [NEW] ZADD support for options: NX, XX, CH. See new doc at redis.io.
(Salvatore Sanfilippo)
* [NEW] Senitnel: CKQUORUM and FLUSHCONFIG commands back ported.
(Salvatore Sanfilippo and Bill Anderson)
--[ Redis 3.0.1 ] Release date: 5 May 2015
Upgrade urgency: LOW for Redis and Cluster, MODERATE for Sentinel.
* [FIX] Sentinel memory leak due to hiredis fixed. (Salvatore Sanfilippo)
* [FIX] Sentinel memory leak on duplicated instance. (Charsyam)
* [FIX] Redis crash on Lua reaching output buffer limits. (Yossi Gottlieb)
* [FIX] Sentinel flushes config on +slave events. (Bill Anderson)
--[ Redis 3.0.0 ] Release date: 1 Apr 2015
>> What's new in Redis 3.0 compared to Redis 2.8?
* Redis Cluster: a distributed implementation of a subset of Redis.
* New "embedded string" object encoding resulting in less cache
misses. Big speed gain under certain work loads.
* AOF child -> parent final data transmission to minimize latency due
to "last write" during AOF rewrites.
* Much improved LRU approximation algorithm for keys eviction.
* WAIT command to block waiting for a write to be transmitted to
the specified number of slaves.
* MIGRATE connection caching. Much faster keys migraitons.
* MIGRATE new options COPY and REPLACE.
* CLIENT PAUSE command: stop processing client requests for a
specified amount of time.
* BITCOUNT performance improvements.
* CONFIG SET accepts memory values in different units (for example
you can use "CONFIG SET maxmemory 1gb").
* Redis log format slightly changed reporting in each line the role of the
instance (master/slave) or if it's a saving child log.
* INCR performance improvements.
>> Refactoring changes (no new features nor bug fixes)
* Blocking operations full refactoring (blocked.c)
* Client output buffer memory tracking refactored.
Changes between RC6 and 3.0.0 stable:
>> General changes
* Fixes to diskless replication. (Oran Agra)
* Test for BLPOP replication on role change. (Salvatore Sanfilippo)
* prepareClientToWrite() error handling improvements. (Salvatore Sanfilippo)
* Remove dict.c no longer used function. (Salvatore Sanfilippo)
>> Cluster changes
None
>> Sentinel changes
None
--[ Redis 3.0.0 RC6 (version 2.9.106) ] Release date: 24 mar 2015
Upgrade urgency: HIGH because of bugs related to Redis Custer and replication.
This is the 6th release candidate of Redis 3.0.0. This release fixes important
issues discovered during stress testing, and implements safest behavior
for blocking operations during clients reshardings, and a new much needed
functionality of Redis Cluster manual failovers.
In order to fix certain bugs quite a bit of refactoring was needed which
is usually non advisabble in a Release Candidate, but needed in order to
end with a clean fix.
>> General changes
* [FIX] Redis (non clustered & clustered) replication bug involving blocking
operations: see issue #2473. (Salvatore Sanfilippo)
>> Cluster changes
* [FIX] clientsArePaused() fix crashing the old master during manual failover.
(Salvatore Sanfilippo)
* [FIX] Lua scripts replication in Redis Cluster was totally broken.
(Salvatore Sanfilippo)
* [FIX] Redirect clients blocked into list operations when the hash slot
they are blocked into is migrated to another instance or the cluster
state turns into "fail". (Salvatore Sanfilippo)
* [NEW] TAKEOVER option for CLUSTER FAILOVER implemented. It is now possible
to fix a cluster manually in the minority side of the partition, for
example in order to allow for multi DC setups & recovery.
(Salvatore Sanfilippo)
>> Sentinel changes
No changes in Sentinel.
--[ Redis 3.0.0 RC5 (version 2.9.105) ] Release date: 20 mar 2015
Upgrade urgency: Moderate for Redis Cluster users, low otherwise.
This is the 5th release candidate of Redis 3.0.0, released in order to fix
a moderate bug in Redis Cluster. This RC does not shift in the future the
Redis 3.0.0 final release which is scheduled in a few days (we are in the
process of finishing the documentation for Redis Cluster).
>> General changes
* [FIX] Fix LATENCY command crash. (Salvatore Sanfilippo, thx to Ingmar)
* [FIX] Config: missing activerehashing option support in CONFIG SET added.
(Salvatore Sanfilippo, thx to Bill Anderson)
* [FIX] Fix for backtrace generation issue. (Mariano Pérez Rodríguez, Matt Stancliff, Salvatore Sanfilippo)
* [NEW] Redis-cli --latency-dist backported from unstable.
(Salvatore Sanfilippo)
>> Cluster changes
* [FIX] Avoid redundant SELECT in MIGRATE. (Tommy Wang, Salvatore Sanfilippo)
* [FIX] More robust slave check in CLUSTER REPLICATE. (Salvatore Sanfilippo)
* [FIX] Fixed possible Redis Cluster node crash due to wrong separation of
concerns between getNodeByQuery() and Cluster global state update
fnuction. (Salvatore Sanfilippo, thx to Ingmar)
* [NEW] Add command CLUSTER MYID to easily featch instance ID. (Michel Martens)
>> Sentinel changes
* [NEW] Support for CLIENT command added. It was missing in the command table.
(Leandro López)
--[ Redis 3.0.0 RC4 (version 2.9.104) ] Release date: 13 feb 2015
Upgrade urgency: High for Redis if you use LRU eviction, low otherwise.
This is the 4th release candidate of Redis 3.0.0, it fixes problems with
LRU eviction that are not present in older release (2.8.x is not affected)
and adds new tools to inspect latency and load-test LRU.
>> General changes
* [FIX] redis-cli CSV output NIL spurious newline removed. (Matt Collier)
* [FIX] Memory efficiency test in unit test is now much faster: it affacted
the total "make test" execution time in a bad way. (Salvatore
Sanfilippo)
* [FIX] Fixes and improvements to dict.c and LRU eviction. Redis 3.0.0 new
LRU eviction had bugs creating high latency spikes when LRU was
happening during the keys dictionary rehashing. This bug is not
present into 2.8, was 3.0 specific. As a side effect of this issue
dict.c is now improved, and LRU algorithm is more precise (better
approximates true LRU). This was a joint effort, see issue
#2306 for details. (Oran Agra, Sun He, Salvatore Sanfilippo).
Thanks to Charsyam for spotting an integer overflow.
* [NEW] New latency tool: redis-cli --latency-dist is able to show an
xterm-256 based spectrum of latencies over time. (Salvatore Sanfilippo)
* [NEW] redis-cli --lru-test implemented (cache workload simulator). (Salvatore
Sanfilippo)
* [NEW] redis-cli --stat now shows LOAD when Redis is loading data.
* [NEW] Support "1G" etc. units in CONFIG SET. (Chris Lamb, Salvatore
Sanfilippo)
>> Cluster changes
* None.
>> Sentinel changes
* None.
--[ Redis 3.0.0 RC3 (version 2.9.103) ] Release date: 30 jan 2015
Upgrade urgency: High for Redis Cluster users, low otherwise.
This is the third release candidate for Redis 3.0.0, the new RC fixes
several critical issues with Redis Cluster.
>> General changes
* [FIX] AOF bug unlikely to happen in practice and mostly harmless: child
process segfaults when parent is not reachable via pipe. (Sun He)
* [FIX] Scripting engine now reports an error when misused with Lua debug
hooks, instead of crashing. (Salvatore Sanfilippo)
>> Cluster changes
* [FIX] Several issues with Redis Cluster internal nodes objects handling.
(Matt Stancliff & Salvatore Sanfilippo)
* [FIX] Improvements in the Cluster test.
(Matt Stancliff & Salvatore Sanfilippo).
* [FIX] Cluster memory leaks / double frees (Matt Stancliff).
* [FIX] /dev/urandom surrogate for generation of unique IDs in a more
cheap way. (Salvatore Sanfilippo)
* [FIX] Fixes and improvements to PING / PONG packets gossip sections
in order to improve (and fix) failure detection and speedup
cluster info propagation. (Salvatore Sanfilippo)
* [NEW] CLUSTER count-failure-reports command added. (Salvatore Sanfilippo)
>> Sentinel changes
No changes for Sentinel.
--[ Redis 3.0.0 RC2 (version 2.9.102) ] Release date: 13 jan 2015
Upgrade urgency: LOW.
This is the second release candidate of Redis 3.0.0. The major changes
are back porting of things implemented into the unstable branch while
this was still possible (with the new development model adopted only
bug fixes will be merged in the future).
RC2 also fixes a few Redis Cluster non critical bugs.
>> General changes
* [FIX] A number of minor bug fixes.
* [NEW] Diskless replication backportede.
* [NEW] Lua bitops and updated cmsgpack backported.
* [NEW] Transparent Huge Pages warnings and reporting backported.
>> Cluster changes
* [FIX] Fix PUBLISH cluster bus message count field.
* [FIX] It is no longer possible to write outside node hash slots using Lua.
* [FIX] Valgrind warnings (no actual bugs).
* [FIX] Less strict in acceptiong myself->ip if it's not populated.
* [NEW] Better testing of Lua scripts.
>> Sentinel changes
No changes to Sentinel.
--[ Redis 3.0.0 RC1 (version 2.9.101) ] Release date: 9 oct 2014
This is the first release candidate of Redis 3.0.0.
>> General changes
* [FIX] An very large number of small fixes, old and new, merged in the
context of a the issue #1906. Please see the issue page here
for exact credits: https://github.com/antirez/redis/pull/1906
of each commit. (Matt Stancliff and many others).
* [FIX] SAVE is no longer propagated to AOF / slaves.
* [FIX] GETRANGE test no longer fails for 32 bit builds (Matt Stancliff).
* [FIX] Limit SCAN latency when the hash table is in an odd state (very few
populted buckets because rehashing is in progress). (Xiaost and
Salvatore Sanfilippo)
* [NEW] Redis is now able to load truncated AOF files without requiring a
redis-check-aof utility run. The default now is to load truncated
(but apparently not corrupted) AOFs, you can change this in redis.conf.
(Salvatore Sanfilippo).
* [NEW] DEBUG POPULATE two args form implemented. It is now possible to
call it with DEBUG POPULATE <count> <prefix>. Default prefix
is "key:" as usually.
* [NEW] INCR: Modify incremented object in-place when possible. This results
in speed improvements + possibly better memory locality.
>> Cluster changes
* [FIX] Cluster: claim ping_sent time even if we can't connect.
* [FIX] redis-trib should not abort easily on connection issues.
* [FIX] Cluster test: less console-spammy resharding test.
* [FIX] Fix logic to detect we are among a minority.
* [FIX] Process gossip section only for known nodes.
* [NEW] Redis Cluster is stable and tested enough, there is a clear MVP,
so it was promoted from beta to stable.
* [NEW] New unit 09, Pub/Sub across the cluster.
* [NEW] New unit 08, update messages.
* [NEW] New cluster option to work with partial slots coverage.
* [NEW] More chatty cluster slaves when failover is stalled. They log reason
with rate limiting, only when reason changes or a given time
has elapsed.
>> Sentinel changes
* [FIX] Sentinel critical bug fixed: the absolute majority was computed in a
wrong way because of a programming error. Now the implementation does
what the specification says and the majority to authorize a failover
(that should not be confused with the ODOWN quorum) is the majority of
*all* the Sentinels ever seen for a given master, regardless of their
current state.
* [FIX] Resolved a memory leak in the hiredis library causing a memory leak
in Redis Sentinel when a monitored instance or another Sentinel is
unavailable. Every reconnection attempt will leak a small amount of
memory, but in the long run the process can reach a considerable size.
* [NEW] Sentinel: ability to announce itself with an arbitrary IP/port to work
in the context of natted networks. However this is probably still
not enough since there is no equivalent mechanism for slaves listed
in the master INFO output. (Dara Kong and Salvatore Sanfilippo)
--[ Redis 3.0.0 Beta 8 (version 2.9.57) ] Release date: 29 jul 2014
This is the 8th beta of Redis 3.0.0.
>> General changes
* [FIX] Solaris compilation issues. (Matt Stancliff, Salvatore Sanfilippo)
* [FIX] Allow shared integer objects if maxmemory policy is not LRU based.
(Salvatore Sanfilippo)
* [FIX] PFSELFTEST: less false positives. (Salvatore Sanfilippo)
* [FIX] Fail SYNC if background save child aborted due to a signal. (Yossi
Gottlieb)
* [NEW] Latency framework backported from unstable branch. (Salvatore
Sanfilippo)
* [NEW] AOF rewrite improved for latency. (Salvatore Sanfilippo)
* [NEW] Pub/Sub PING. (Salvatore Sanfilippo)
* [NEW] Much faster ZUNIONSTORE. (Kyle Hubert, Salvatore Sanfilippo)
* [NEW] Faster ll2string() implementation. (Salvatore Sanfilippo)
>> Cluster changes
* [FIX] CLUSTER RESET: Flush slave dataset on reset. (Salvatore Sanfilippo)
* [FIX] Replica migration: don't migrate to masters that never had slaves
in the past, but only to masters that remained orphaned after
failure events. (Salvatore Sanfilippo)
* [NEW] redis-trib: allow to reshard in non-interactive way. (Salvatore
Sanfilippo)
* [NEW] Cluster test: unit 04, check consistency during resharding. (Salvatore
Sanfilippo)
* [NEW] Cluster test: unit 05, slave selection. (Salvatore Sanfilippo)
* [NEW] Cluster test: unit 06, slaves with stale data can't failover. (Salvatore
Sanfilippo)
* [NEW] Cluster test: unit 07, replicas migration. (Salvatore Sanfilippo)
>> Sentinel changes
* No Sentinel changes in this release.
--[ Redis 3.0.0 Beta 7 (version 2.9.56) ] Release date: 30 jun 2014
This is the 7th beta of Redis 3.0.0.
>> General changes
* [FIX] Scripting fixes backported from unstable, see Redis 2.8.12 changelog
for more info. (Salvatore Sanfilippo)
* [FIX] Cancel SHUTDOWN if initial AOF is being written. (Matt Stancliff)
* [NEW] New command: COMMAND, for commands introspection (Matt Stancliff &
Salvatore Sanfilippo)
* [NEW] hiredis: Update to latest version. (Matt Stancliff)
* [NEW] Jemalloc updated to 3.6.0. (Salvatore Sanfilippo)
>> Cluster changes
* [FIX] Cluster: clear NOADDR flag when updating node address.
(Salvatore Sanfilippo)
* [NEW] New CLUSTER SLOTS command to simplify Cluster clients operations.
(Matt Stancliff)
* [NEW] More Cluster tests. (Salvatore Sanfilippo)
* [NEW] Log when failover authorization are granted / denied.
(Salvatore Sanfilippo)
>> Sentinel changes
* [FIX] A few Sentinel bugs fixed and improvements, see Redis 2.8.12
changelog for more info. (Salvatore Sanfilippo & Matt Stancliff)
* [NEW] New Sentinel-Client handshake protocol, ROLE command, CLIENT KILL,
all backported to 3.0 branch. (Salvatore Sanfilippo)
--[ Redis 3.0.0 Beta 6 (version 2.9.55) ] Release date: 9 jun 2014
This is the 6th beta of Redis 3.0.0.
>> General changes
* [FIX] Fix software watchdog signal handler crash due to re-entering.
* [FIX] Better Lua number -> string conversion for Lua scripts.
* [FIX] Serious replication bug when min-slaves-* feature is used in slaves
configuration fixed.
* [FIX] Blocking pop on lists now works when the list is created by commands
other than *PUSH* (for example SORT STORE).
>> Cluster changes
* [FIX] CRITICAL: For a bug in the implementation of CLUSTER SET-CONFIG-EPOCH
introduced with beta-3 (especially beta-4 where the command
is actually used by redis-trib), a configEpoch for a node could
jump backward, breaking the eventual consistency property of the
slots -> nodes mapping in the cluster.
>> Sentinel changes
* No changes for Sentinel in this release.
--[ Redis 3.0.0 Beta 5 (version 2.9.54) ] Release date: 26 may 2014
This is the 5th beta of Redis 3.0.0. It does not include any real
worthwhile change (just three days passed since the previous beta), but
fixes two stupid bugs preventing cluster tests to pass.
--[ Redis 3.0.0 Beta 4 (version 2.9.53) ] Release date: 23 may 2014
This is the fourth beta of Redis 3.0.0.
>> General changes
* [NEW] Scripting engine performances improvements.
* [NEW] Log format slightly changed to report current node role.
* [FIX] Correct the HyperLogLog stale cache flag to prevent unnecessary
computation.
>> Cluster changes
* [NEW] redis-trib: ability to import data from standalone Redis instances.
* [NEW] redis-trib: "fix" subcommand much better at fixing errors.
* [NEW] CLUSTER FAILOVER FORCE implemented.
* [NEW] CLUSTER RESET implemented, it is now possible to completely reset
nodes and create a new cluster without restarting anything.
* [NEW] Slave validity factor (max estimated data age to still failover)
is now under the control of the user, and can be configured via
redis.conf or CONFIG SET. Option name cluster-slave-validity-factor.
* [NEW] Cluster test: failure detection and failover initial tests.
* [NEW] CLUSTER MEET: better error messages when address is invalid.
* [NEW] Bulk-accept new Cluster nodes in the Cluster bus instead of
performing just a single accept() per event fired.
* [FIX] Bypass data_age check for manual failovers.
* [FIX] Fixed data_age computation / check integer overflow.
* [FIX] Various fixes to Tcl client.tcl Redis Cluster client used in tests.
* [FIX] Better handling of stolen slots.
* [FIX] Don't accept cluster bus connections during startup.
>> Sentinel changes
* [NEW] Generate +config-update-from event when a new config is received.
* [NEW] Log when a failover will be re-attempted again.
* [FIX] Sentinel: Add "dir /tmp" directive in example sentinel.conf.
--[ Redis 3.0.0 Beta 3 (version 2.9.52) ] Release date: 5 may 2014
This is the third beta of Redis 3.0.0.
>> General changes
* [NEW] New data structure: the HyperLogLog (see 2.8 release notes).
* [NEW] Lexicograhical range queries in sorted sets (see 2.8 release notes).
* [NEW] LRU algorithm precision greatly improved.
* [FIX] Redis is now much more responsive to reply with LOADING / BUSY errors.
>> Cluster changes
* [NEW] Cluster testing framework and initial tests.
* [NEW] Cluster epochs collision resolution (make Redis Cluster more resilient
to admin and programming errors).
* [NEW] Persist / fsync some global state to ensure correct crash-recovery
semantics.
* [NEW] New command introduced: CLUSTER SET-CONFIG-EPOCH, still not used
by redis-trib. Will be used to speedup the assignment of unique
epochs to different nodes at cluster creation time. For now this is
handled as a side effect of the cluster epochs collision resolution.
* [FIX] Different fixes to redis-trib cluster creation.
* [FIX] Fix an error in the CLUSTER NODES output for nodes slots.
>> Sentinel changes
* [NEW] Sentinels are now able to send update messages in a peer-to-peer
fashion even if no Redis instances are available. Now the Sentinel
liveness property that the most updated configuration in a given
partition is propagated to all the Sentinels is extended to partitions
without reachable instances.
* [NEW] Sentinel safety properties are now ensured in a crash-recovery system
model since some state is persisted on disk before replying to other
nodes, and reloaded at startup.
* [NEW] Sentinel now uses CLIENT SETNAME so that it is easy to identify
Sentinels using CLIENT LIST among other clients.
* [NEW] Sentinel failure detection and reconnection code improved.
--[ Redis 3.0.0 Beta 2 (version 2.9.51) ] Release date: 11 mar 2014
This is the second beta of Redis 3.0.0.
>> General changes
* [FIX] Sometimes the absolute config file path was obtained in a wrong way.
This happened when there was a "dir" directive inside the config file
and at the same time the configuration file was given as a relative
path to redis-server or redis-sentinel executables.
* [FIX] redis-cli: Automatically enter --slave mode when SYNC or PSYNC are
called during an interactive session.
* [FIX] BITCOUNT: fixed unaligned access causing issues in sparc and other
archs not capable of dealing with unaligned accesses. This also makes
the code faster in archs where unaligned accesses are allowed.
* [FIX] Force INFO used_memory_peak to match peak memory. This generated some
confusion among users even if it was not an actual bug.
* [FIX] Fixed an critical EVALSHA script cache bug: scripts executed may not
propagate to AOF / Slaves correctly under certain conditions.
See issue #1549 at Github for more information.
* [FIX] Fixed multiple bugs resulting into closing the link with master or slave
during replication without good reasons. This will result in useless
resynchronizations, or infinite loops where the replication link can't
be established.
* [FIX] Don't count the time needed to populate the buffers of clients waiting
in MONITOR mode when populating the Slow Log entries.
* [NEW] Redis-cli updated to use SCAN instead of random sampling via
RANDOMKEY in order to implement --bigkeys feature. Moreover the
implementation now supports pipelining and reports more information
at the end of the scan. Much faster, much better. A special thank
you to Michael Grunder for this improvement.
* [NEW] redis-cli now supports a new --intrinsic-latency mode that is able
to meter the latency of a system due to kernel / hypervisor.
How to use it is explained at http://redis.io/topics/latency.
* [NEW] New command BITPOS: find first bit set or clear in a bitmap.
* [NEW] CONFIG REWRITE calls are now logged.
* [NEW] AOF write errors (like no space on device) no longer abort Redis if the
fsync policy is none or every second. The database enters a read-only
mode where every write is refused with an error. Normal operations are
restored as soon as Redis is able to append again data to the AOF file.
* [NEW] Sentinel now accepts SHUTDOWN command.
>> Cluster changes
* [FIX] Bind the first interface listed in the "bind" configuration directive
if any, in order to perform outgoing connections. This fixes Cluster
usage when an address is bound but there are multiple interfaces that
may be used to connect with other nodes.
* [FIX] When an "Importing" slot is closed via CLUSTER SETSLOT NODE ...
increment the configEpoch in the special case it is zero.
* [FIX] Current transaction is invalidated on redirection errors.
* [FIX] Abort if port does not allow for a valid cluster bus port that is
always at fixed +10000 offset.
* [FIX] Keys extraction algorithm fixed for ZUNIONSTORE/ZINTERSTORE and SORT.
* [FIX] Better failover timeout and retry times: failover should now work
reliabily when node-timeout is very small (a few milliseconds).
* [FIX] Don't allow SORT GET/BY options in Cluster mode.
* [FIX] Clear importing/migrating state when turning from master to slave role.
* [FIX] Set slot error if we receive an update for a busy slot.
* [FIX] Update node configEpoch on UPDATE messages.
* [NEW] Support multi-key operations as long as keys resolve to the same
hash slot, and the slot is not migrating, or it is migrating but all
the mentioned keys are available.
* [NEW] New DEBUG command CMDKEYS available to debug / test keys identification
in Redis commands.
* [NEW] redis-trib: create subcommand is now able to assign spare slaves.
* [NEW] redis-trib: new subcommand 'call'. Exec command in all nodes.
>> Sentinel changes
* [FIX] Sentinel "IDONTKNOW" error removed as it does not made sense with the
new Sentinel design. This error was actually a fix for a design error
in the first implementation of Sentinel.
* [FIX] Sentinel: added a missing exit() call to abort after config file
checks at startup. This error was introduced with an improvement in
a previous 2.8 release.
* [FIX] Sentinel: better nodes fail over start time desynchronization to avoid
split-brain during the voting process needed to get authorization to
fail over. This means the system is less likely to need to retry
and will fail over faster. No changes in behavior / correctness.
* [NEW] Sentinel unit tests and framework. More tests needed and units must
be improved in order to have less false positives, but it is a start
and features a debugging console that is useful to fix tests or to
inspect bugs causing tests failures.
* [NEW] New Sentinel events: +/-monitor and +set used to monitor when an
instance to monitor is added or removed, or when a configuration
is modified via SENTINEL SET.
--[ Redis 3.0.0 Beta 1 (version 2.9.50) ] Release date: 11 Feb 2014
This is the first beta of Redis 3.0.0.
Migrating from 2.8 to 3.0
=========================
Redis 2.8 is mostly a strict subset of 3.0, you should not have any problem
upgrading your application from 2.8 to 3.0. However this is a list of small
non-backward compatible changes introduced in the 3.0 release:
* The log format was modified. The prefix of each line included the pid
in the following format [1234]. Now instead it is 1234:? Where
'?' is actually the role of the instance. M for master, S for slave, C
if this process is a saving child (for RDB/AOF), and X for Sentinel.
* The default maxmemory policy in Redis 3.0 is no longer "volatile-lru" as
it used to be in 2.8, but "noeviction". The policies behavior is the same
(but LRU eviction is much more precise in 3.0), so only the default value
changed. Just make sure to specify in your redis.conf what you mean.
--------------------------------------------------------------------------------
Credits: Where not specified the implementation and design is done by
Salvatore Sanfilippo. Thanks to Pivotal for making all this possible.
Also many thanks to all the other contributors and the amazing community
we have.
See commit messages for more credits.
Cheers,
Salvatore

View file

@ -0,0 +1 @@
Please check https://github.com/antirez/redis/issues

View file

@ -0,0 +1,38 @@
Note: by contributing code to the Redis project in any form, including sending
a pull request via Github, a code fragment or patch via private email or
public discussion groups, you agree to release your code under the terms
of the BSD license that you can find in the COPYING file included in the Redis
source distribution. You will include BSD license in the COPYING file within
each source file that you contribute.
# IMPORTANT: HOW TO USE REDIS GITHUB ISSUES
* Github issues SHOULD ONLY BE USED to report bugs, and for DETAILED feature
requests. Everything else belongs to the Redis Google Group.
PLEASE DO NOT POST GENERAL QUESTIONS that are not about bugs or suspected
bugs in the Github issues system. We'll be very happy to help you and provide
all the support Reddit sub:
http://reddit.com/r/redis
There is also an active community of Redis users at Stack Overflow:
http://stackoverflow.com/questions/tagged/redis
# How to provide a patch for a new feature
1. If it is a major feature or a semantical change, please post it as a new submission in r/redis on Reddit at http://reddit.com/r/redis. Try to be passionate about why the feature is needed, make users upvote your proposal to gain traction and so forth. Read feedbacks about the community. But in this first step **please don't write code yet**.
2. If in step 1 you get an acknowledge from the project leaders, use the
following procedure to submit a patch:
a. Fork Redis on github ( http://help.github.com/fork-a-repo/ )
b. Create a topic branch (git checkout -b my_branch)
c. Push to your branch (git push origin my_branch)
d. Initiate a pull request on github ( http://help.github.com/send-pull-requests/ )
e. Done :)
For minor fixes just open a pull request on Github.
Thanks!

View file

@ -0,0 +1,10 @@
Copyright (c) 2006-2015, Salvatore Sanfilippo
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Redis nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -0,0 +1,67 @@
[Note: this is the Redis manifesto, for general information about
installing and running Redis read the README file instead.]
Redis Manifesto
===============
1 - A DSL for Abstract Data Types. Redis is a DSL (Domain Specific Language)
that manipulates abstract data types and implemented as a TCP daemon.
Commands manipulate a key space where keys are binary-safe strings and
values are different kinds of abstract data types. Every data type
represents an abstract version of a fundamental data structure. For instance
Redis Lists are an abstract representation of linked lists. In Redis, the
essence of a data type isn't just the kind of operations that the data types
support, but also the space and time complexity of the data type and the
operations performed upon it.
2 - Memory storage is #1. The Redis data set, composed of defined key-value
pairs, is primarily stored in the computer's memory. The amount of memory in
all kinds of computers, including entry-level servers, is increasing
significantly each year. Memory is fast, and allows Redis to have very
predictable performance. Datasets composed of 10k or 40 millions keys will
perform similarly. Complex data types like Redis Sorted Sets are easy to
implement and manipulate in memory with good performance, making Redis very
simple. Redis will continue to explore alternative options (where data can
be optionally stored on disk, say) but the main goal of the project remains
the development of an in-memory database.
3 - Fundamental data structures for a fundamental API. The Redis API is a direct
consequence of fundamental data structures. APIs can often be arbitrary but
not an API that resembles the nature of fundamental data structures. If we
ever meet intelligent life forms from another part of the universe, they'll
likely know, understand and recognize the same basic data structures we have
in our computer science books. Redis will avoid intermediate layers in API,
so that the complexity is obvious and more complex operations can be
performed as the sum of the basic operations.
4 - Code is like a poem; it's not just something we write to reach some
practical result. Sometimes people that are far from the Redis philosophy
suggest using other code written by other authors (frequently in other
languages) in order to implement something Redis currently lacks. But to us
this is like if Shakespeare decided to end Enrico IV using the Paradiso from
the Divina Commedia. Is using any external code a bad idea? Not at all. Like
in "One Thousand and One Nights" smaller self contained stories are embedded
in a bigger story, we'll be happy to use beautiful self contained libraries
when needed. At the same time, when writing the Redis story we're trying to
write smaller stories that will fit in to other code.
5 - We're against complexity. We believe designing systems is a fight against
complexity. We'll accept to fight the complexity when it's worthwhile but
we'll try hard to recognize when a small feature is not worth 1000s of lines
of code. Most of the time the best way to fight complexity is by not
creating it at all.
6 - Two levels of API. The Redis API has two levels: 1) a subset of the API fits
naturally into a distributed version of Redis and 2) a more complex API that
supports multi-key operations. Both are useful if used judiciously but
there's no way to make the more complex multi-keys API distributed in an
opaque way without violating our other principles. We don't want to provide
the illusion of something that will work magically when actually it can't in
all cases. Instead we'll provide commands to quickly migrate keys from one
instance to another to perform multi-key operations and expose the tradeoffs
to the user.
7 - We optimize for joy. We believe writing code is a lot of hard work, and the
only way it can be worth is by enjoying it. When there is no longer joy in
writing code, the best thing to do is stop. To prevent this, we'll avoid
taking paths that will make Redis less of a joy to develop.

View file

@ -0,0 +1,11 @@
# Top level makefile, the real shit is at src/Makefile
default: all
.DEFAULT:
cd src && $(MAKE) $@
install:
cd src && $(MAKE) $@
.PHONY: install

View file

@ -0,0 +1,173 @@
Where to find complete Redis documentation?
-------------------------------------------
This README is just a fast "quick start" document. You can find more detailed
documentation at http://redis.io
Building Redis
--------------
Redis can be compiled and used on Linux, OSX, OpenBSD, NetBSD, FreeBSD.
We support big endian and little endian architectures.
It may compile on Solaris derived systems (for instance SmartOS) but our
support for this platform is "best effort" and Redis is not guaranteed to
work as well as in Linux, OSX, and *BSD there.
It is as simple as:
% make
You can run a 32 bit Redis binary using:
% make 32bit
After building Redis is a good idea to test it, using:
% make test
Fixing build problems with dependencies or cached build options
—--------
Redis has some dependencies which are included into the "deps" directory.
"make" does not rebuild dependencies automatically, even if something in the
source code of dependencies is changes.
When you update the source code with `git pull` or when code inside the
dependencies tree is modified in any other way, make sure to use the following
command in order to really clean everything and rebuild from scratch:
make distclean
This will clean: jemalloc, lua, hiredis, linenoise.
Also if you force certain build options like 32bit target, no C compiler
optimizations (for debugging purposes), and other similar build time options,
those options are cached indefinitely until you issue a "make distclean"
command.
Fixing problems building 32 bit binaries
---------
If after building Redis with a 32 bit target you need to rebuild it
with a 64 bit target, or the other way around, you need to perform a
"make distclean" in the root directory of the Redis distribution.
In case of build errors when trying to build a 32 bit binary of Redis, try
the following steps:
* Install the packages libc6-dev-i386 (also try g++-multilib).
* Try using the following command line instead of "make 32bit":
make CFLAGS="-m32 -march=native" LDFLAGS="-m32"
Allocator
---------
Selecting a non-default memory allocator when building Redis is done by setting
the `MALLOC` environment variable. Redis is compiled and linked against libc
malloc by default, with the exception of jemalloc being the default on Linux
systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc.
To force compiling against libc malloc, use:
% make MALLOC=libc
To compile against jemalloc on Mac OS X systems, use:
% make MALLOC=jemalloc
Verbose build
-------------
Redis will build with a user friendly colorized output by default.
If you want to see a more verbose output use the following:
% make V=1
Running Redis
-------------
To run Redis with the default configuration just type:
% cd src
% ./redis-server
If you want to provide your redis.conf, you have to run it using an additional
parameter (the path of the configuration file):
% cd src
% ./redis-server /path/to/redis.conf
It is possible to alter the Redis configuration passing parameters directly
as options using the command line. Examples:
% ./redis-server --port 9999 --slaveof 127.0.0.1 6379
% ./redis-server /etc/redis/6379.conf --loglevel debug
All the options in redis.conf are also supported as options using the command
line, with exactly the same name.
Playing with Redis
------------------
You can use redis-cli to play with Redis. Start a redis-server instance,
then in another terminal try the following:
% cd src
% ./redis-cli
redis> ping
PONG
redis> set foo bar
OK
redis> get foo
"bar"
redis> incr mycounter
(integer) 1
redis> incr mycounter
(integer) 2
redis>
You can find the list of all the available commands here:
http://redis.io/commands
Installing Redis
-----------------
In order to install Redis binaries into /usr/local/bin just use:
% make install
You can use "make PREFIX=/some/other/directory install" if you wish to use a
different destination.
Make install will just install binaries in your system, but will not configure
init scripts and configuration files in the appropriate place. This is not
needed if you want just to play a bit with Redis, but if you are installing
it the proper way for a production system, we have a script doing this
for Ubuntu and Debian systems:
% cd utils
% ./install_server.sh
The script will ask you a few questions and will setup everything you need
to run Redis properly as a background daemon that will start again on
system reboots.
You'll be able to stop and start Redis using the script named
/etc/init.d/redis_<portnumber>, for instance /etc/init.d/redis_6379.
Code contributions
---
Note: by contributing code to the Redis project in any form, including sending
a pull request via Github, a code fragment or patch via private email or
public discussion groups, you agree to release your code under the terms
of the BSD license that you can find in the COPYING file included in the Redis
source distribution.
Please see the CONTRIBUTING file in this source distribution for more
information.
Enjoy!

View file

@ -0,0 +1,83 @@
# Redis dependency Makefile
uname_S:= $(shell sh -c 'uname -s 2>/dev/null || echo not')
CCCOLOR="\033[34m"
LINKCOLOR="\033[34;1m"
SRCCOLOR="\033[33m"
BINCOLOR="\033[37;1m"
MAKECOLOR="\033[32;1m"
ENDCOLOR="\033[0m"
default:
@echo "Explicit target required"
.PHONY: default
# Prerequisites target
.make-prerequisites:
@touch $@
# Clean everything when CFLAGS is different
ifneq ($(shell sh -c '[ -f .make-cflags ] && cat .make-cflags || echo none'), $(CFLAGS))
.make-cflags: distclean
-(echo "$(CFLAGS)" > .make-cflags)
.make-prerequisites: .make-cflags
endif
# Clean everything when LDFLAGS is different
ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), $(LDFLAGS))
.make-ldflags: distclean
-(echo "$(LDFLAGS)" > .make-ldflags)
.make-prerequisites: .make-ldflags
endif
distclean:
-(cd hiredis && $(MAKE) clean) > /dev/null || true
-(cd linenoise && $(MAKE) clean) > /dev/null || true
-(cd lua && $(MAKE) clean) > /dev/null || true
-(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true
-(rm -f .make-*)
.PHONY: distclean
hiredis: .make-prerequisites
@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
cd hiredis && $(MAKE) static
.PHONY: hiredis
linenoise: .make-prerequisites
@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
cd linenoise && $(MAKE)
.PHONY: linenoise
ifeq ($(uname_S),SunOS)
# Make isinf() available
LUA_CFLAGS= -D__C99FEATURES__=1
endif
LUA_CFLAGS+= -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL $(CFLAGS)
LUA_LDFLAGS+= $(LDFLAGS)
# lua's Makefile defines AR="ar rcu", which is unusual, and makes it more
# challenging to cross-compile lua (and redis). These defines make it easier
# to fit redis into cross-compilation environments, which typically set AR.
AR=ar
ARFLAGS=rcu
lua: .make-prerequisites
@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
cd lua/src && $(MAKE) all CFLAGS="$(LUA_CFLAGS)" MYLDFLAGS="$(LUA_LDFLAGS)" AR="$(AR) $(ARFLAGS)"
.PHONY: lua
JEMALLOC_CFLAGS= -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops $(CFLAGS)
JEMALLOC_LDFLAGS= $(LDFLAGS)
jemalloc: .make-prerequisites
@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
cd jemalloc && ./configure --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)"
cd jemalloc && $(MAKE) CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)" lib/libjemalloc.a
.PHONY: jemalloc

View file

@ -0,0 +1,6 @@
/hiredis-test
/examples/hiredis-example*
/*.o
/*.so
/*.dylib
/*.a

View file

@ -0,0 +1,6 @@
language: c
compiler:
- gcc
- clang
script: make && make check

View file

@ -0,0 +1,24 @@
### 0.11.0
* Increase the maximum multi-bulk reply depth to 7.
* Increase the read buffer size from 2k to 16k.
* Use poll(2) instead of select(2) to support large fds (>= 1024).
### 0.10.1
* Makefile overhaul. Important to check out if you override one or more
variables using environment variables or via arguments to the "make" tool.
* Issue #45: Fix potential memory leak for a multi bulk reply with 0 elements
being created by the default reply object functions.
* Issue #43: Don't crash in an asynchronous context when Redis returns an error
reply after the connection has been made (this happens when the maximum
number of connections is reached).
### 0.10.0
* See commit log.

View file

@ -0,0 +1,29 @@
Copyright (c) 2009-2011, Salvatore Sanfilippo <antirez at gmail dot com>
Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Redis nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -0,0 +1,166 @@
# Hiredis Makefile
# Copyright (C) 2010-2011 Salvatore Sanfilippo <antirez at gmail dot com>
# Copyright (C) 2010-2011 Pieter Noordhuis <pcnoordhuis at gmail dot com>
# This file is released under the BSD license, see the COPYING file
OBJ=net.o hiredis.o sds.o async.o
EXAMPLES=hiredis-example hiredis-example-libevent hiredis-example-libev
TESTS=hiredis-test
LIBNAME=libhiredis
HIREDIS_MAJOR=0
HIREDIS_MINOR=11
# redis-server configuration used for testing
REDIS_PORT=56379
REDIS_SERVER=redis-server
define REDIS_TEST_CONFIG
daemonize yes
pidfile /tmp/hiredis-test-redis.pid
port $(REDIS_PORT)
bind 127.0.0.1
unixsocket /tmp/hiredis-test-redis.sock
endef
export REDIS_TEST_CONFIG
# Fallback to gcc when $CC is not in $PATH.
CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
OPTIMIZATION?=-O3
WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings
DEBUG?= -g -ggdb
REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG) $(ARCH)
REAL_LDFLAGS=$(LDFLAGS) $(ARCH)
DYLIBSUFFIX=so
STLIBSUFFIX=a
DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR).$(HIREDIS_MINOR)
DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR)
DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX)
DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
STLIB_MAKE_CMD=ar rcs $(STLIBNAME)
# Platform-specific overrides
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
ifeq ($(uname_S),SunOS)
REAL_LDFLAGS+= -ldl -lnsl -lsocket
DYLIB_MAKE_CMD=$(CC) -G -o $(DYLIBNAME) -h $(DYLIB_MINOR_NAME) $(LDFLAGS)
INSTALL= cp -r
endif
ifeq ($(uname_S),Darwin)
DYLIBSUFFIX=dylib
DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(DYLIBSUFFIX)
DYLIB_MAJOR_NAME=$(LIBNAME).$(HIREDIS_MAJOR).$(DYLIBSUFFIX)
DYLIB_MAKE_CMD=$(CC) -shared -Wl,-install_name,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
endif
all: $(DYLIBNAME)
# Deps (use make dep to generate this)
net.o: net.c fmacros.h net.h hiredis.h
async.o: async.c async.h hiredis.h sds.h dict.c dict.h
hiredis.o: hiredis.c fmacros.h hiredis.h net.h sds.h
sds.o: sds.c sds.h
test.o: test.c hiredis.h
$(DYLIBNAME): $(OBJ)
$(DYLIB_MAKE_CMD) $(OBJ)
$(STLIBNAME): $(OBJ)
$(STLIB_MAKE_CMD) $(OBJ)
dynamic: $(DYLIBNAME)
static: $(STLIBNAME)
# Binaries:
hiredis-example-libevent: examples/example-libevent.c adapters/libevent.h $(STLIBNAME)
$(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -levent $(STLIBNAME)
hiredis-example-libev: examples/example-libev.c adapters/libev.h $(STLIBNAME)
$(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -lev $(STLIBNAME)
ifndef AE_DIR
hiredis-example-ae:
@echo "Please specify AE_DIR (e.g. <redis repository>/src)"
@false
else
hiredis-example-ae: examples/example-ae.c adapters/ae.h $(STLIBNAME)
$(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(AE_DIR) $< $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o $(AE_DIR)/../deps/jemalloc/lib/libjemalloc.a -pthread $(STLIBNAME)
endif
ifndef LIBUV_DIR
hiredis-example-libuv:
@echo "Please specify LIBUV_DIR (e.g. ../libuv/)"
@false
else
hiredis-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME)
$(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread $(STLIBNAME)
endif
hiredis-example: examples/example.c $(STLIBNAME)
$(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< $(STLIBNAME)
examples: $(EXAMPLES)
hiredis-test: test.o $(STLIBNAME)
$(CC) -o $@ $(REAL_LDFLAGS) $< $(STLIBNAME)
test: hiredis-test
./hiredis-test
check: hiredis-test
@echo "$$REDIS_TEST_CONFIG" | $(REDIS_SERVER) -
./hiredis-test -h 127.0.0.1 -p $(REDIS_PORT) -s /tmp/hiredis-test-redis.sock || \
( kill `cat /tmp/hiredis-test-redis.pid` && false )
kill `cat /tmp/hiredis-test-redis.pid`
.c.o:
$(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
clean:
rm -rf $(DYLIBNAME) $(STLIBNAME) $(TESTS) examples/hiredis-example* *.o *.gcda *.gcno *.gcov
dep:
$(CC) -MM *.c
# Installation related variables and target
PREFIX?=/usr/local
INSTALL_INCLUDE_PATH= $(PREFIX)/include/hiredis
INSTALL_LIBRARY_PATH= $(PREFIX)/lib
ifeq ($(uname_S),SunOS)
INSTALL?= cp -r
endif
INSTALL?= cp -a
install: $(DYLIBNAME) $(STLIBNAME)
mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH)
$(INSTALL) hiredis.h async.h adapters $(INSTALL_INCLUDE_PATH)
$(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME)
cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIB_MAJOR_NAME)
cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MAJOR_NAME) $(DYLIBNAME)
$(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH)
32bit:
@echo ""
@echo "WARNING: if this fails under Linux you probably need to install libc6-dev-i386"
@echo ""
$(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
gprof:
$(MAKE) CFLAGS="-pg" LDFLAGS="-pg"
gcov:
$(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs"
coverage: gcov
make check
mkdir -p tmp/lcov
lcov -d . -c -o tmp/lcov/hiredis.info
genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info
noopt:
$(MAKE) OPTIMIZATION=""
.PHONY: all test check clean dep install 32bit gprof gcov noopt

View file

@ -0,0 +1,384 @@
[![Build Status](https://travis-ci.org/redis/hiredis.png)](https://travis-ci.org/redis/hiredis)
# HIREDIS
Hiredis is a minimalistic C client library for the [Redis](http://redis.io/) database.
It is minimalistic because it just adds minimal support for the protocol, but
at the same time it uses an high level printf-alike API in order to make it
much higher level than otherwise suggested by its minimal code base and the
lack of explicit bindings for every Redis command.
Apart from supporting sending commands and receiving replies, it comes with
a reply parser that is decoupled from the I/O layer. It
is a stream parser designed for easy reusability, which can for instance be used
in higher level language bindings for efficient reply parsing.
Hiredis only supports the binary-safe Redis protocol, so you can use it with any
Redis version >= 1.2.0.
The library comes with multiple APIs. There is the
*synchronous API*, the *asynchronous API* and the *reply parsing API*.
## UPGRADING
Version 0.9.0 is a major overhaul of hiredis in every aspect. However, upgrading existing
code using hiredis should not be a big pain. The key thing to keep in mind when
upgrading is that hiredis >= 0.9.0 uses a `redisContext*` to keep state, in contrast to
the stateless 0.0.1 that only has a file descriptor to work with.
## Synchronous API
To consume the synchronous API, there are only a few function calls that need to be introduced:
redisContext *redisConnect(const char *ip, int port);
void *redisCommand(redisContext *c, const char *format, ...);
void freeReplyObject(void *reply);
### Connecting
The function `redisConnect` is used to create a so-called `redisContext`. The
context is where Hiredis holds state for a connection. The `redisContext`
struct has an integer `err` field that is non-zero when an the connection is in
an error state. The field `errstr` will contain a string with a description of
the error. More information on errors can be found in the **Errors** section.
After trying to connect to Redis using `redisConnect` you should
check the `err` field to see if establishing the connection was successful:
redisContext *c = redisConnect("127.0.0.1", 6379);
if (c != NULL && c->err) {
printf("Error: %s\n", c->errstr);
// handle error
}
### Sending commands
There are several ways to issue commands to Redis. The first that will be introduced is
`redisCommand`. This function takes a format similar to printf. In the simplest form,
it is used like this:
reply = redisCommand(context, "SET foo bar");
The specifier `%s` interpolates a string in the command, and uses `strlen` to
determine the length of the string:
reply = redisCommand(context, "SET foo %s", value);
When you need to pass binary safe strings in a command, the `%b` specifier can be
used. Together with a pointer to the string, it requires a `size_t` length argument
of the string:
reply = redisCommand(context, "SET foo %b", value, (size_t) valuelen);
Internally, Hiredis splits the command in different arguments and will
convert it to the protocol used to communicate with Redis.
One or more spaces separates arguments, so you can use the specifiers
anywhere in an argument:
reply = redisCommand(context, "SET key:%s %s", myid, value);
### Using replies
The return value of `redisCommand` holds a reply when the command was
successfully executed. When an error occurs, the return value is `NULL` and
the `err` field in the context will be set (see section on **Errors**).
Once an error is returned the context cannot be reused and you should set up
a new connection.
The standard replies that `redisCommand` are of the type `redisReply`. The
`type` field in the `redisReply` should be used to test what kind of reply
was received:
* **`REDIS_REPLY_STATUS`**:
* The command replied with a status reply. The status string can be accessed using `reply->str`.
The length of this string can be accessed using `reply->len`.
* **`REDIS_REPLY_ERROR`**:
* The command replied with an error. The error string can be accessed identical to `REDIS_REPLY_STATUS`.
* **`REDIS_REPLY_INTEGER`**:
* The command replied with an integer. The integer value can be accessed using the
`reply->integer` field of type `long long`.
* **`REDIS_REPLY_NIL`**:
* The command replied with a **nil** object. There is no data to access.
* **`REDIS_REPLY_STRING`**:
* A bulk (string) reply. The value of the reply can be accessed using `reply->str`.
The length of this string can be accessed using `reply->len`.
* **`REDIS_REPLY_ARRAY`**:
* A multi bulk reply. The number of elements in the multi bulk reply is stored in
`reply->elements`. Every element in the multi bulk reply is a `redisReply` object as well
and can be accessed via `reply->element[..index..]`.
Redis may reply with nested arrays but this is fully supported.
Replies should be freed using the `freeReplyObject()` function.
Note that this function will take care of freeing sub-replies objects
contained in arrays and nested arrays, so there is no need for the user to
free the sub replies (it is actually harmful and will corrupt the memory).
**Important:** the current version of hiredis (0.10.0) free's replies when the
asynchronous API is used. This means you should not call `freeReplyObject` when
you use this API. The reply is cleaned up by hiredis _after_ the callback
returns. This behavior will probably change in future releases, so make sure to
keep an eye on the changelog when upgrading (see issue #39).
### Cleaning up
To disconnect and free the context the following function can be used:
void redisFree(redisContext *c);
This function immediately closes the socket and then free's the allocations done in
creating the context.
### Sending commands (cont'd)
Together with `redisCommand`, the function `redisCommandArgv` can be used to issue commands.
It has the following prototype:
void *redisCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen);
It takes the number of arguments `argc`, an array of strings `argv` and the lengths of the
arguments `argvlen`. For convenience, `argvlen` may be set to `NULL` and the function will
use `strlen(3)` on every argument to determine its length. Obviously, when any of the arguments
need to be binary safe, the entire array of lengths `argvlen` should be provided.
The return value has the same semantic as `redisCommand`.
### Pipelining
To explain how Hiredis supports pipelining in a blocking connection, there needs to be
understanding of the internal execution flow.
When any of the functions in the `redisCommand` family is called, Hiredis first formats the
command according to the Redis protocol. The formatted command is then put in the output buffer
of the context. This output buffer is dynamic, so it can hold any number of commands.
After the command is put in the output buffer, `redisGetReply` is called. This function has the
following two execution paths:
1. The input buffer is non-empty:
* Try to parse a single reply from the input buffer and return it
* If no reply could be parsed, continue at *2*
2. The input buffer is empty:
* Write the **entire** output buffer to the socket
* Read from the socket until a single reply could be parsed
The function `redisGetReply` is exported as part of the Hiredis API and can be used when a reply
is expected on the socket. To pipeline commands, the only things that needs to be done is
filling up the output buffer. For this cause, two commands can be used that are identical
to the `redisCommand` family, apart from not returning a reply:
void redisAppendCommand(redisContext *c, const char *format, ...);
void redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen);
After calling either function one or more times, `redisGetReply` can be used to receive the
subsequent replies. The return value for this function is either `REDIS_OK` or `REDIS_ERR`, where
the latter means an error occurred while reading a reply. Just as with the other commands,
the `err` field in the context can be used to find out what the cause of this error is.
The following examples shows a simple pipeline (resulting in only a single call to `write(2)` and
a single call to `read(2)`):
redisReply *reply;
redisAppendCommand(context,"SET foo bar");
redisAppendCommand(context,"GET foo");
redisGetReply(context,&reply); // reply for SET
freeReplyObject(reply);
redisGetReply(context,&reply); // reply for GET
freeReplyObject(reply);
This API can also be used to implement a blocking subscriber:
reply = redisCommand(context,"SUBSCRIBE foo");
freeReplyObject(reply);
while(redisGetReply(context,&reply) == REDIS_OK) {
// consume message
freeReplyObject(reply);
}
### Errors
When a function call is not successful, depending on the function either `NULL` or `REDIS_ERR` is
returned. The `err` field inside the context will be non-zero and set to one of the
following constants:
* **`REDIS_ERR_IO`**:
There was an I/O error while creating the connection, trying to write
to the socket or read from the socket. If you included `errno.h` in your
application, you can use the global `errno` variable to find out what is
wrong.
* **`REDIS_ERR_EOF`**:
The server closed the connection which resulted in an empty read.
* **`REDIS_ERR_PROTOCOL`**:
There was an error while parsing the protocol.
* **`REDIS_ERR_OTHER`**:
Any other error. Currently, it is only used when a specified hostname to connect
to cannot be resolved.
In every case, the `errstr` field in the context will be set to hold a string representation
of the error.
## Asynchronous API
Hiredis comes with an asynchronous API that works easily with any event library.
Examples are bundled that show using Hiredis with [libev](http://software.schmorp.de/pkg/libev.html)
and [libevent](http://monkey.org/~provos/libevent/).
### Connecting
The function `redisAsyncConnect` can be used to establish a non-blocking connection to
Redis. It returns a pointer to the newly created `redisAsyncContext` struct. The `err` field
should be checked after creation to see if there were errors creating the connection.
Because the connection that will be created is non-blocking, the kernel is not able to
instantly return if the specified host and port is able to accept a connection.
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
if (c->err) {
printf("Error: %s\n", c->errstr);
// handle error
}
The asynchronous context can hold a disconnect callback function that is called when the
connection is disconnected (either because of an error or per user request). This function should
have the following prototype:
void(const redisAsyncContext *c, int status);
On a disconnect, the `status` argument is set to `REDIS_OK` when disconnection was initiated by the
user, or `REDIS_ERR` when the disconnection was caused by an error. When it is `REDIS_ERR`, the `err`
field in the context can be accessed to find out the cause of the error.
The context object is always free'd after the disconnect callback fired. When a reconnect is needed,
the disconnect callback is a good point to do so.
Setting the disconnect callback can only be done once per context. For subsequent calls it will
return `REDIS_ERR`. The function to set the disconnect callback has the following prototype:
int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn);
### Sending commands and their callbacks
In an asynchronous context, commands are automatically pipelined due to the nature of an event loop.
Therefore, unlike the synchronous API, there is only a single way to send commands.
Because commands are sent to Redis asynchronously, issuing a command requires a callback function
that is called when the reply is received. Reply callbacks should have the following prototype:
void(redisAsyncContext *c, void *reply, void *privdata);
The `privdata` argument can be used to curry arbitrary data to the callback from the point where
the command is initially queued for execution.
The functions that can be used to issue commands in an asynchronous context are:
int redisAsyncCommand(
redisAsyncContext *ac, redisCallbackFn *fn, void *privdata,
const char *format, ...);
int redisAsyncCommandArgv(
redisAsyncContext *ac, redisCallbackFn *fn, void *privdata,
int argc, const char **argv, const size_t *argvlen);
Both functions work like their blocking counterparts. The return value is `REDIS_OK` when the command
was successfully added to the output buffer and `REDIS_ERR` otherwise. Example: when the connection
is being disconnected per user-request, no new commands may be added to the output buffer and `REDIS_ERR` is
returned on calls to the `redisAsyncCommand` family.
If the reply for a command with a `NULL` callback is read, it is immediately free'd. When the callback
for a command is non-`NULL`, the memory is free'd immediately following the callback: the reply is only
valid for the duration of the callback.
All pending callbacks are called with a `NULL` reply when the context encountered an error.
### Disconnecting
An asynchronous connection can be terminated using:
void redisAsyncDisconnect(redisAsyncContext *ac);
When this function is called, the connection is **not** immediately terminated. Instead, new
commands are no longer accepted and the connection is only terminated when all pending commands
have been written to the socket, their respective replies have been read and their respective
callbacks have been executed. After this, the disconnection callback is executed with the
`REDIS_OK` status and the context object is free'd.
### Hooking it up to event library *X*
There are a few hooks that need to be set on the context object after it is created.
See the `adapters/` directory for bindings to *libev* and *libevent*.
## Reply parsing API
Hiredis comes with a reply parsing API that makes it easy for writing higher
level language bindings.
The reply parsing API consists of the following functions:
redisReader *redisReaderCreate(void);
void redisReaderFree(redisReader *reader);
int redisReaderFeed(redisReader *reader, const char *buf, size_t len);
int redisReaderGetReply(redisReader *reader, void **reply);
The same set of functions are used internally by hiredis when creating a
normal Redis context, the above API just exposes it to the user for a direct
usage.
### Usage
The function `redisReaderCreate` creates a `redisReader` structure that holds a
buffer with unparsed data and state for the protocol parser.
Incoming data -- most likely from a socket -- can be placed in the internal
buffer of the `redisReader` using `redisReaderFeed`. This function will make a
copy of the buffer pointed to by `buf` for `len` bytes. This data is parsed
when `redisReaderGetReply` is called. This function returns an integer status
and a reply object (as described above) via `void **reply`. The returned status
can be either `REDIS_OK` or `REDIS_ERR`, where the latter means something went
wrong (either a protocol error, or an out of memory error).
The parser limits the level of nesting for multi bulk payloads to 7. If the
multi bulk nesting level is higher than this, the parser returns an error.
### Customizing replies
The function `redisReaderGetReply` creates `redisReply` and makes the function
argument `reply` point to the created `redisReply` variable. For instance, if
the response of type `REDIS_REPLY_STATUS` then the `str` field of `redisReply`
will hold the status as a vanilla C string. However, the functions that are
responsible for creating instances of the `redisReply` can be customized by
setting the `fn` field on the `redisReader` struct. This should be done
immediately after creating the `redisReader`.
For example, [hiredis-rb](https://github.com/pietern/hiredis-rb/blob/master/ext/hiredis_ext/reader.c)
uses customized reply object functions to create Ruby objects.
### Reader max buffer
Both when using the Reader API directly or when using it indirectly via a
normal Redis context, the redisReader structure uses a buffer in order to
accumulate data from the server.
Usually this buffer is destroyed when it is empty and is larger than 16
kb in order to avoid wasting memory in unused buffers
However when working with very big payloads destroying the buffer may slow
down performances considerably, so it is possible to modify the max size of
an idle buffer changing the value of the `maxbuf` field of the reader structure
to the desired value. The special value of 0 means that there is no maximum
value for an idle buffer, so the buffer will never get freed.
For instance if you have a normal Redis context you can set the maximum idle
buffer to zero (unlimited) just with:
context->reader->maxbuf = 0;
This should be done only in order to maximize performances when working with
large payloads. The context should be set back to `REDIS_READER_MAX_BUF` again
as soon as possible in order to prevent allocation of useless memory.
## AUTHORS
Hiredis was written by Salvatore Sanfilippo (antirez at gmail) and
Pieter Noordhuis (pcnoordhuis at gmail) and is released under the BSD license.

View file

@ -0,0 +1,127 @@
/*
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __HIREDIS_AE_H__
#define __HIREDIS_AE_H__
#include <sys/types.h>
#include <ae.h>
#include "../hiredis.h"
#include "../async.h"
typedef struct redisAeEvents {
redisAsyncContext *context;
aeEventLoop *loop;
int fd;
int reading, writing;
} redisAeEvents;
static void redisAeReadEvent(aeEventLoop *el, int fd, void *privdata, int mask) {
((void)el); ((void)fd); ((void)mask);
redisAeEvents *e = (redisAeEvents*)privdata;
redisAsyncHandleRead(e->context);
}
static void redisAeWriteEvent(aeEventLoop *el, int fd, void *privdata, int mask) {
((void)el); ((void)fd); ((void)mask);
redisAeEvents *e = (redisAeEvents*)privdata;
redisAsyncHandleWrite(e->context);
}
static void redisAeAddRead(void *privdata) {
redisAeEvents *e = (redisAeEvents*)privdata;
aeEventLoop *loop = e->loop;
if (!e->reading) {
e->reading = 1;
aeCreateFileEvent(loop,e->fd,AE_READABLE,redisAeReadEvent,e);
}
}
static void redisAeDelRead(void *privdata) {
redisAeEvents *e = (redisAeEvents*)privdata;
aeEventLoop *loop = e->loop;
if (e->reading) {
e->reading = 0;
aeDeleteFileEvent(loop,e->fd,AE_READABLE);
}
}
static void redisAeAddWrite(void *privdata) {
redisAeEvents *e = (redisAeEvents*)privdata;
aeEventLoop *loop = e->loop;
if (!e->writing) {
e->writing = 1;
aeCreateFileEvent(loop,e->fd,AE_WRITABLE,redisAeWriteEvent,e);
}
}
static void redisAeDelWrite(void *privdata) {
redisAeEvents *e = (redisAeEvents*)privdata;
aeEventLoop *loop = e->loop;
if (e->writing) {
e->writing = 0;
aeDeleteFileEvent(loop,e->fd,AE_WRITABLE);
}
}
static void redisAeCleanup(void *privdata) {
redisAeEvents *e = (redisAeEvents*)privdata;
redisAeDelRead(privdata);
redisAeDelWrite(privdata);
free(e);
}
static int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) {
redisContext *c = &(ac->c);
redisAeEvents *e;
/* Nothing should be attached when something is already attached */
if (ac->ev.data != NULL)
return REDIS_ERR;
/* Create container for context and r/w events */
e = (redisAeEvents*)malloc(sizeof(*e));
e->context = ac;
e->loop = loop;
e->fd = c->fd;
e->reading = e->writing = 0;
/* Register functions to start/stop listening for events */
ac->ev.addRead = redisAeAddRead;
ac->ev.delRead = redisAeDelRead;
ac->ev.addWrite = redisAeAddWrite;
ac->ev.delWrite = redisAeDelWrite;
ac->ev.cleanup = redisAeCleanup;
ac->ev.data = e;
return REDIS_OK;
}
#endif

View file

@ -0,0 +1,147 @@
/*
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __HIREDIS_LIBEV_H__
#define __HIREDIS_LIBEV_H__
#include <stdlib.h>
#include <sys/types.h>
#include <ev.h>
#include "../hiredis.h"
#include "../async.h"
typedef struct redisLibevEvents {
redisAsyncContext *context;
struct ev_loop *loop;
int reading, writing;
ev_io rev, wev;
} redisLibevEvents;
static void redisLibevReadEvent(EV_P_ ev_io *watcher, int revents) {
#if EV_MULTIPLICITY
((void)loop);
#endif
((void)revents);
redisLibevEvents *e = (redisLibevEvents*)watcher->data;
redisAsyncHandleRead(e->context);
}
static void redisLibevWriteEvent(EV_P_ ev_io *watcher, int revents) {
#if EV_MULTIPLICITY
((void)loop);
#endif
((void)revents);
redisLibevEvents *e = (redisLibevEvents*)watcher->data;
redisAsyncHandleWrite(e->context);
}
static void redisLibevAddRead(void *privdata) {
redisLibevEvents *e = (redisLibevEvents*)privdata;
struct ev_loop *loop = e->loop;
((void)loop);
if (!e->reading) {
e->reading = 1;
ev_io_start(EV_A_ &e->rev);
}
}
static void redisLibevDelRead(void *privdata) {
redisLibevEvents *e = (redisLibevEvents*)privdata;
struct ev_loop *loop = e->loop;
((void)loop);
if (e->reading) {
e->reading = 0;
ev_io_stop(EV_A_ &e->rev);
}
}
static void redisLibevAddWrite(void *privdata) {
redisLibevEvents *e = (redisLibevEvents*)privdata;
struct ev_loop *loop = e->loop;
((void)loop);
if (!e->writing) {
e->writing = 1;
ev_io_start(EV_A_ &e->wev);
}
}
static void redisLibevDelWrite(void *privdata) {
redisLibevEvents *e = (redisLibevEvents*)privdata;
struct ev_loop *loop = e->loop;
((void)loop);
if (e->writing) {
e->writing = 0;
ev_io_stop(EV_A_ &e->wev);
}
}
static void redisLibevCleanup(void *privdata) {
redisLibevEvents *e = (redisLibevEvents*)privdata;
redisLibevDelRead(privdata);
redisLibevDelWrite(privdata);
free(e);
}
static int redisLibevAttach(EV_P_ redisAsyncContext *ac) {
redisContext *c = &(ac->c);
redisLibevEvents *e;
/* Nothing should be attached when something is already attached */
if (ac->ev.data != NULL)
return REDIS_ERR;
/* Create container for context and r/w events */
e = (redisLibevEvents*)malloc(sizeof(*e));
e->context = ac;
#if EV_MULTIPLICITY
e->loop = loop;
#else
e->loop = NULL;
#endif
e->reading = e->writing = 0;
e->rev.data = e;
e->wev.data = e;
/* Register functions to start/stop listening for events */
ac->ev.addRead = redisLibevAddRead;
ac->ev.delRead = redisLibevDelRead;
ac->ev.addWrite = redisLibevAddWrite;
ac->ev.delWrite = redisLibevDelWrite;
ac->ev.cleanup = redisLibevCleanup;
ac->ev.data = e;
/* Initialize read/write events */
ev_io_init(&e->rev,redisLibevReadEvent,c->fd,EV_READ);
ev_io_init(&e->wev,redisLibevWriteEvent,c->fd,EV_WRITE);
return REDIS_OK;
}
#endif

View file

@ -0,0 +1,108 @@
/*
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __HIREDIS_LIBEVENT_H__
#define __HIREDIS_LIBEVENT_H__
#include <event.h>
#include "../hiredis.h"
#include "../async.h"
typedef struct redisLibeventEvents {
redisAsyncContext *context;
struct event rev, wev;
} redisLibeventEvents;
static void redisLibeventReadEvent(int fd, short event, void *arg) {
((void)fd); ((void)event);
redisLibeventEvents *e = (redisLibeventEvents*)arg;
redisAsyncHandleRead(e->context);
}
static void redisLibeventWriteEvent(int fd, short event, void *arg) {
((void)fd); ((void)event);
redisLibeventEvents *e = (redisLibeventEvents*)arg;
redisAsyncHandleWrite(e->context);
}
static void redisLibeventAddRead(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
event_add(&e->rev,NULL);
}
static void redisLibeventDelRead(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
event_del(&e->rev);
}
static void redisLibeventAddWrite(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
event_add(&e->wev,NULL);
}
static void redisLibeventDelWrite(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
event_del(&e->wev);
}
static void redisLibeventCleanup(void *privdata) {
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
event_del(&e->rev);
event_del(&e->wev);
free(e);
}
static int redisLibeventAttach(redisAsyncContext *ac, struct event_base *base) {
redisContext *c = &(ac->c);
redisLibeventEvents *e;
/* Nothing should be attached when something is already attached */
if (ac->ev.data != NULL)
return REDIS_ERR;
/* Create container for context and r/w events */
e = (redisLibeventEvents*)malloc(sizeof(*e));
e->context = ac;
/* Register functions to start/stop listening for events */
ac->ev.addRead = redisLibeventAddRead;
ac->ev.delRead = redisLibeventDelRead;
ac->ev.addWrite = redisLibeventAddWrite;
ac->ev.delWrite = redisLibeventDelWrite;
ac->ev.cleanup = redisLibeventCleanup;
ac->ev.data = e;
/* Initialize and install read/write events */
event_set(&e->rev,c->fd,EV_READ,redisLibeventReadEvent,e);
event_set(&e->wev,c->fd,EV_WRITE,redisLibeventWriteEvent,e);
event_base_set(base,&e->rev);
event_base_set(base,&e->wev);
return REDIS_OK;
}
#endif

View file

@ -0,0 +1,121 @@
#ifndef __HIREDIS_LIBUV_H__
#define __HIREDIS_LIBUV_H__
#include <uv.h>
#include "../hiredis.h"
#include "../async.h"
#include <string.h>
typedef struct redisLibuvEvents {
redisAsyncContext* context;
uv_poll_t handle;
int events;
} redisLibuvEvents;
int redisLibuvAttach(redisAsyncContext*, uv_loop_t*);
static void redisLibuvPoll(uv_poll_t* handle, int status, int events) {
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
if (status != 0) {
return;
}
if (events & UV_READABLE) {
redisAsyncHandleRead(p->context);
}
if (events & UV_WRITABLE) {
redisAsyncHandleWrite(p->context);
}
}
static void redisLibuvAddRead(void *privdata) {
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
p->events |= UV_READABLE;
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
}
static void redisLibuvDelRead(void *privdata) {
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
p->events &= ~UV_READABLE;
if (p->events) {
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
} else {
uv_poll_stop(&p->handle);
}
}
static void redisLibuvAddWrite(void *privdata) {
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
p->events |= UV_WRITABLE;
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
}
static void redisLibuvDelWrite(void *privdata) {
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
p->events &= ~UV_WRITABLE;
if (p->events) {
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
} else {
uv_poll_stop(&p->handle);
}
}
static void on_close(uv_handle_t* handle) {
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
free(p);
}
static void redisLibuvCleanup(void *privdata) {
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
uv_close((uv_handle_t*)&p->handle, on_close);
}
static int redisLibuvAttach(redisAsyncContext* ac, uv_loop_t* loop) {
redisContext *c = &(ac->c);
if (ac->ev.data != NULL) {
return REDIS_ERR;
}
ac->ev.addRead = redisLibuvAddRead;
ac->ev.delRead = redisLibuvDelRead;
ac->ev.addWrite = redisLibuvAddWrite;
ac->ev.delWrite = redisLibuvDelWrite;
ac->ev.cleanup = redisLibuvCleanup;
redisLibuvEvents* p = (redisLibuvEvents*)malloc(sizeof(*p));
if (!p) {
return REDIS_ERR;
}
memset(p, 0, sizeof(*p));
if (uv_poll_init(loop, &p->handle, c->fd) != 0) {
return REDIS_ERR;
}
ac->ev.data = p;
p->handle.data = p;
p->context = ac;
return REDIS_OK;
}
#endif

View file

@ -0,0 +1,662 @@
/*
* Copyright (c) 2009-2011, Salvatore Sanfilippo <antirez at gmail dot com>
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "fmacros.h"
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include "async.h"
#include "net.h"
#include "dict.c"
#include "sds.h"
#define _EL_ADD_READ(ctx) do { \
if ((ctx)->ev.addRead) (ctx)->ev.addRead((ctx)->ev.data); \
} while(0)
#define _EL_DEL_READ(ctx) do { \
if ((ctx)->ev.delRead) (ctx)->ev.delRead((ctx)->ev.data); \
} while(0)
#define _EL_ADD_WRITE(ctx) do { \
if ((ctx)->ev.addWrite) (ctx)->ev.addWrite((ctx)->ev.data); \
} while(0)
#define _EL_DEL_WRITE(ctx) do { \
if ((ctx)->ev.delWrite) (ctx)->ev.delWrite((ctx)->ev.data); \
} while(0)
#define _EL_CLEANUP(ctx) do { \
if ((ctx)->ev.cleanup) (ctx)->ev.cleanup((ctx)->ev.data); \
} while(0);
/* Forward declaration of function in hiredis.c */
void __redisAppendCommand(redisContext *c, char *cmd, size_t len);
/* Functions managing dictionary of callbacks for pub/sub. */
static unsigned int callbackHash(const void *key) {
return dictGenHashFunction((const unsigned char *)key,
sdslen((const sds)key));
}
static void *callbackValDup(void *privdata, const void *src) {
((void) privdata);
redisCallback *dup = malloc(sizeof(*dup));
memcpy(dup,src,sizeof(*dup));
return dup;
}
static int callbackKeyCompare(void *privdata, const void *key1, const void *key2) {
int l1, l2;
((void) privdata);
l1 = sdslen((const sds)key1);
l2 = sdslen((const sds)key2);
if (l1 != l2) return 0;
return memcmp(key1,key2,l1) == 0;
}
static void callbackKeyDestructor(void *privdata, void *key) {
((void) privdata);
sdsfree((sds)key);
}
static void callbackValDestructor(void *privdata, void *val) {
((void) privdata);
free(val);
}
static dictType callbackDict = {
callbackHash,
NULL,
callbackValDup,
callbackKeyCompare,
callbackKeyDestructor,
callbackValDestructor
};
static redisAsyncContext *redisAsyncInitialize(redisContext *c) {
redisAsyncContext *ac;
ac = realloc(c,sizeof(redisAsyncContext));
if (ac == NULL)
return NULL;
c = &(ac->c);
/* The regular connect functions will always set the flag REDIS_CONNECTED.
* For the async API, we want to wait until the first write event is
* received up before setting this flag, so reset it here. */
c->flags &= ~REDIS_CONNECTED;
ac->err = 0;
ac->errstr = NULL;
ac->data = NULL;
ac->ev.data = NULL;
ac->ev.addRead = NULL;
ac->ev.delRead = NULL;
ac->ev.addWrite = NULL;
ac->ev.delWrite = NULL;
ac->ev.cleanup = NULL;
ac->onConnect = NULL;
ac->onDisconnect = NULL;
ac->replies.head = NULL;
ac->replies.tail = NULL;
ac->sub.invalid.head = NULL;
ac->sub.invalid.tail = NULL;
ac->sub.channels = dictCreate(&callbackDict,NULL);
ac->sub.patterns = dictCreate(&callbackDict,NULL);
return ac;
}
/* We want the error field to be accessible directly instead of requiring
* an indirection to the redisContext struct. */
static void __redisAsyncCopyError(redisAsyncContext *ac) {
redisContext *c = &(ac->c);
ac->err = c->err;
ac->errstr = c->errstr;
}
redisAsyncContext *redisAsyncConnect(const char *ip, int port) {
redisContext *c;
redisAsyncContext *ac;
c = redisConnectNonBlock(ip,port);
if (c == NULL)
return NULL;
ac = redisAsyncInitialize(c);
if (ac == NULL) {
redisFree(c);
return NULL;
}
__redisAsyncCopyError(ac);
return ac;
}
redisAsyncContext *redisAsyncConnectBind(const char *ip, int port,
const char *source_addr) {
redisContext *c = redisConnectBindNonBlock(ip,port,source_addr);
redisAsyncContext *ac = redisAsyncInitialize(c);
__redisAsyncCopyError(ac);
return ac;
}
redisAsyncContext *redisAsyncConnectUnix(const char *path) {
redisContext *c;
redisAsyncContext *ac;
c = redisConnectUnixNonBlock(path);
if (c == NULL)
return NULL;
ac = redisAsyncInitialize(c);
if (ac == NULL) {
redisFree(c);
return NULL;
}
__redisAsyncCopyError(ac);
return ac;
}
int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn) {
if (ac->onConnect == NULL) {
ac->onConnect = fn;
/* The common way to detect an established connection is to wait for
* the first write event to be fired. This assumes the related event
* library functions are already set. */
_EL_ADD_WRITE(ac);
return REDIS_OK;
}
return REDIS_ERR;
}
int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn) {
if (ac->onDisconnect == NULL) {
ac->onDisconnect = fn;
return REDIS_OK;
}
return REDIS_ERR;
}
/* Helper functions to push/shift callbacks */
static int __redisPushCallback(redisCallbackList *list, redisCallback *source) {
redisCallback *cb;
/* Copy callback from stack to heap */
cb = malloc(sizeof(*cb));
if (cb == NULL)
return REDIS_ERR_OOM;
if (source != NULL) {
memcpy(cb,source,sizeof(*cb));
cb->next = NULL;
}
/* Store callback in list */
if (list->head == NULL)
list->head = cb;
if (list->tail != NULL)
list->tail->next = cb;
list->tail = cb;
return REDIS_OK;
}
static int __redisShiftCallback(redisCallbackList *list, redisCallback *target) {
redisCallback *cb = list->head;
if (cb != NULL) {
list->head = cb->next;
if (cb == list->tail)
list->tail = NULL;
/* Copy callback from heap to stack */
if (target != NULL)
memcpy(target,cb,sizeof(*cb));
free(cb);
return REDIS_OK;
}
return REDIS_ERR;
}
static void __redisRunCallback(redisAsyncContext *ac, redisCallback *cb, redisReply *reply) {
redisContext *c = &(ac->c);
if (cb->fn != NULL) {
c->flags |= REDIS_IN_CALLBACK;
cb->fn(ac,reply,cb->privdata);
c->flags &= ~REDIS_IN_CALLBACK;
}
}
/* Helper function to free the context. */
static void __redisAsyncFree(redisAsyncContext *ac) {
redisContext *c = &(ac->c);
redisCallback cb;
dictIterator *it;
dictEntry *de;
/* Execute pending callbacks with NULL reply. */
while (__redisShiftCallback(&ac->replies,&cb) == REDIS_OK)
__redisRunCallback(ac,&cb,NULL);
/* Execute callbacks for invalid commands */
while (__redisShiftCallback(&ac->sub.invalid,&cb) == REDIS_OK)
__redisRunCallback(ac,&cb,NULL);
/* Run subscription callbacks callbacks with NULL reply */
it = dictGetIterator(ac->sub.channels);
while ((de = dictNext(it)) != NULL)
__redisRunCallback(ac,dictGetEntryVal(de),NULL);
dictReleaseIterator(it);
dictRelease(ac->sub.channels);
it = dictGetIterator(ac->sub.patterns);
while ((de = dictNext(it)) != NULL)
__redisRunCallback(ac,dictGetEntryVal(de),NULL);
dictReleaseIterator(it);
dictRelease(ac->sub.patterns);
/* Signal event lib to clean up */
_EL_CLEANUP(ac);
/* Execute disconnect callback. When redisAsyncFree() initiated destroying
* this context, the status will always be REDIS_OK. */
if (ac->onDisconnect && (c->flags & REDIS_CONNECTED)) {
if (c->flags & REDIS_FREEING) {
ac->onDisconnect(ac,REDIS_OK);
} else {
ac->onDisconnect(ac,(ac->err == 0) ? REDIS_OK : REDIS_ERR);
}
}
/* Cleanup self */
redisFree(c);
}
/* Free the async context. When this function is called from a callback,
* control needs to be returned to redisProcessCallbacks() before actual
* free'ing. To do so, a flag is set on the context which is picked up by
* redisProcessCallbacks(). Otherwise, the context is immediately free'd. */
void redisAsyncFree(redisAsyncContext *ac) {
redisContext *c = &(ac->c);
c->flags |= REDIS_FREEING;
if (!(c->flags & REDIS_IN_CALLBACK))
__redisAsyncFree(ac);
}
/* Helper function to make the disconnect happen and clean up. */
static void __redisAsyncDisconnect(redisAsyncContext *ac) {
redisContext *c = &(ac->c);
/* Make sure error is accessible if there is any */
__redisAsyncCopyError(ac);
if (ac->err == 0) {
/* For clean disconnects, there should be no pending callbacks. */
assert(__redisShiftCallback(&ac->replies,NULL) == REDIS_ERR);
} else {
/* Disconnection is caused by an error, make sure that pending
* callbacks cannot call new commands. */
c->flags |= REDIS_DISCONNECTING;
}
/* For non-clean disconnects, __redisAsyncFree() will execute pending
* callbacks with a NULL-reply. */
__redisAsyncFree(ac);
}
/* Tries to do a clean disconnect from Redis, meaning it stops new commands
* from being issued, but tries to flush the output buffer and execute
* callbacks for all remaining replies. When this function is called from a
* callback, there might be more replies and we can safely defer disconnecting
* to redisProcessCallbacks(). Otherwise, we can only disconnect immediately
* when there are no pending callbacks. */
void redisAsyncDisconnect(redisAsyncContext *ac) {
redisContext *c = &(ac->c);
c->flags |= REDIS_DISCONNECTING;
if (!(c->flags & REDIS_IN_CALLBACK) && ac->replies.head == NULL)
__redisAsyncDisconnect(ac);
}
static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply, redisCallback *dstcb) {
redisContext *c = &(ac->c);
dict *callbacks;
dictEntry *de;
int pvariant;
char *stype;
sds sname;
/* Custom reply functions are not supported for pub/sub. This will fail
* very hard when they are used... */
if (reply->type == REDIS_REPLY_ARRAY) {
assert(reply->elements >= 2);
assert(reply->element[0]->type == REDIS_REPLY_STRING);
stype = reply->element[0]->str;
pvariant = (tolower(stype[0]) == 'p') ? 1 : 0;
if (pvariant)
callbacks = ac->sub.patterns;
else
callbacks = ac->sub.channels;
/* Locate the right callback */
assert(reply->element[1]->type == REDIS_REPLY_STRING);
sname = sdsnewlen(reply->element[1]->str,reply->element[1]->len);
de = dictFind(callbacks,sname);
if (de != NULL) {
memcpy(dstcb,dictGetEntryVal(de),sizeof(*dstcb));
/* If this is an unsubscribe message, remove it. */
if (strcasecmp(stype+pvariant,"unsubscribe") == 0) {
dictDelete(callbacks,sname);
/* If this was the last unsubscribe message, revert to
* non-subscribe mode. */
assert(reply->element[2]->type == REDIS_REPLY_INTEGER);
if (reply->element[2]->integer == 0)
c->flags &= ~REDIS_SUBSCRIBED;
}
}
sdsfree(sname);
} else {
/* Shift callback for invalid commands. */
__redisShiftCallback(&ac->sub.invalid,dstcb);
}
return REDIS_OK;
}
void redisProcessCallbacks(redisAsyncContext *ac) {
redisContext *c = &(ac->c);
redisCallback cb = {NULL, NULL, NULL};
void *reply = NULL;
int status;
while((status = redisGetReply(c,&reply)) == REDIS_OK) {
if (reply == NULL) {
/* When the connection is being disconnected and there are
* no more replies, this is the cue to really disconnect. */
if (c->flags & REDIS_DISCONNECTING && sdslen(c->obuf) == 0) {
__redisAsyncDisconnect(ac);
return;
}
/* If monitor mode, repush callback */
if(c->flags & REDIS_MONITORING) {
__redisPushCallback(&ac->replies,&cb);
}
/* When the connection is not being disconnected, simply stop
* trying to get replies and wait for the next loop tick. */
break;
}
/* Even if the context is subscribed, pending regular callbacks will
* get a reply before pub/sub messages arrive. */
if (__redisShiftCallback(&ac->replies,&cb) != REDIS_OK) {
/*
* A spontaneous reply in a not-subscribed context can be the error
* reply that is sent when a new connection exceeds the maximum
* number of allowed connections on the server side.
*
* This is seen as an error instead of a regular reply because the
* server closes the connection after sending it.
*
* To prevent the error from being overwritten by an EOF error the
* connection is closed here. See issue #43.
*
* Another possibility is that the server is loading its dataset.
* In this case we also want to close the connection, and have the
* user wait until the server is ready to take our request.
*/
if (((redisReply*)reply)->type == REDIS_REPLY_ERROR) {
c->err = REDIS_ERR_OTHER;
snprintf(c->errstr,sizeof(c->errstr),"%s",((redisReply*)reply)->str);
c->reader->fn->freeObject(reply);
__redisAsyncDisconnect(ac);
return;
}
/* No more regular callbacks and no errors, the context *must* be subscribed or monitoring. */
assert((c->flags & REDIS_SUBSCRIBED || c->flags & REDIS_MONITORING));
if(c->flags & REDIS_SUBSCRIBED)
__redisGetSubscribeCallback(ac,reply,&cb);
}
if (cb.fn != NULL) {
__redisRunCallback(ac,&cb,reply);
c->reader->fn->freeObject(reply);
/* Proceed with free'ing when redisAsyncFree() was called. */
if (c->flags & REDIS_FREEING) {
__redisAsyncFree(ac);
return;
}
} else {
/* No callback for this reply. This can either be a NULL callback,
* or there were no callbacks to begin with. Either way, don't
* abort with an error, but simply ignore it because the client
* doesn't know what the server will spit out over the wire. */
c->reader->fn->freeObject(reply);
}
}
/* Disconnect when there was an error reading the reply */
if (status != REDIS_OK)
__redisAsyncDisconnect(ac);
}
/* Internal helper function to detect socket status the first time a read or
* write event fires. When connecting was not succesful, the connect callback
* is called with a REDIS_ERR status and the context is free'd. */
static int __redisAsyncHandleConnect(redisAsyncContext *ac) {
redisContext *c = &(ac->c);
if (redisCheckSocketError(c) == REDIS_ERR) {
/* Try again later when connect(2) is still in progress. */
if (errno == EINPROGRESS)
return REDIS_OK;
if (ac->onConnect) ac->onConnect(ac,REDIS_ERR);
__redisAsyncDisconnect(ac);
return REDIS_ERR;
}
/* Mark context as connected. */
c->flags |= REDIS_CONNECTED;
if (ac->onConnect) ac->onConnect(ac,REDIS_OK);
return REDIS_OK;
}
/* This function should be called when the socket is readable.
* It processes all replies that can be read and executes their callbacks.
*/
void redisAsyncHandleRead(redisAsyncContext *ac) {
redisContext *c = &(ac->c);
if (!(c->flags & REDIS_CONNECTED)) {
/* Abort connect was not successful. */
if (__redisAsyncHandleConnect(ac) != REDIS_OK)
return;
/* Try again later when the context is still not connected. */
if (!(c->flags & REDIS_CONNECTED))
return;
}
if (redisBufferRead(c) == REDIS_ERR) {
__redisAsyncDisconnect(ac);
} else {
/* Always re-schedule reads */
_EL_ADD_READ(ac);
redisProcessCallbacks(ac);
}
}
void redisAsyncHandleWrite(redisAsyncContext *ac) {
redisContext *c = &(ac->c);
int done = 0;
if (!(c->flags & REDIS_CONNECTED)) {
/* Abort connect was not successful. */
if (__redisAsyncHandleConnect(ac) != REDIS_OK)
return;
/* Try again later when the context is still not connected. */
if (!(c->flags & REDIS_CONNECTED))
return;
}
if (redisBufferWrite(c,&done) == REDIS_ERR) {
__redisAsyncDisconnect(ac);
} else {
/* Continue writing when not done, stop writing otherwise */
if (!done)
_EL_ADD_WRITE(ac);
else
_EL_DEL_WRITE(ac);
/* Always schedule reads after writes */
_EL_ADD_READ(ac);
}
}
/* Sets a pointer to the first argument and its length starting at p. Returns
* the number of bytes to skip to get to the following argument. */
static char *nextArgument(char *start, char **str, size_t *len) {
char *p = start;
if (p[0] != '$') {
p = strchr(p,'$');
if (p == NULL) return NULL;
}
*len = (int)strtol(p+1,NULL,10);
p = strchr(p,'\r');
assert(p);
*str = p+2;
return p+2+(*len)+2;
}
/* Helper function for the redisAsyncCommand* family of functions. Writes a
* formatted command to the output buffer and registers the provided callback
* function with the context. */
static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, char *cmd, size_t len) {
redisContext *c = &(ac->c);
redisCallback cb;
int pvariant, hasnext;
char *cstr, *astr;
size_t clen, alen;
char *p;
sds sname;
/* Don't accept new commands when the connection is about to be closed. */
if (c->flags & (REDIS_DISCONNECTING | REDIS_FREEING)) return REDIS_ERR;
/* Setup callback */
cb.fn = fn;
cb.privdata = privdata;
/* Find out which command will be appended. */
p = nextArgument(cmd,&cstr,&clen);
assert(p != NULL);
hasnext = (p[0] == '$');
pvariant = (tolower(cstr[0]) == 'p') ? 1 : 0;
cstr += pvariant;
clen -= pvariant;
if (hasnext && strncasecmp(cstr,"subscribe\r\n",11) == 0) {
c->flags |= REDIS_SUBSCRIBED;
/* Add every channel/pattern to the list of subscription callbacks. */
while ((p = nextArgument(p,&astr,&alen)) != NULL) {
sname = sdsnewlen(astr,alen);
if (pvariant)
dictReplace(ac->sub.patterns,sname,&cb);
else
dictReplace(ac->sub.channels,sname,&cb);
}
} else if (strncasecmp(cstr,"unsubscribe\r\n",13) == 0) {
/* It is only useful to call (P)UNSUBSCRIBE when the context is
* subscribed to one or more channels or patterns. */
if (!(c->flags & REDIS_SUBSCRIBED)) return REDIS_ERR;
/* (P)UNSUBSCRIBE does not have its own response: every channel or
* pattern that is unsubscribed will receive a message. This means we
* should not append a callback function for this command. */
} else if(strncasecmp(cstr,"monitor\r\n",9) == 0) {
/* Set monitor flag and push callback */
c->flags |= REDIS_MONITORING;
__redisPushCallback(&ac->replies,&cb);
} else {
if (c->flags & REDIS_SUBSCRIBED)
/* This will likely result in an error reply, but it needs to be
* received and passed to the callback. */
__redisPushCallback(&ac->sub.invalid,&cb);
else
__redisPushCallback(&ac->replies,&cb);
}
__redisAppendCommand(c,cmd,len);
/* Always schedule a write when the write buffer is non-empty */
_EL_ADD_WRITE(ac);
return REDIS_OK;
}
int redisvAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, va_list ap) {
char *cmd;
int len;
int status;
len = redisvFormatCommand(&cmd,format,ap);
status = __redisAsyncCommand(ac,fn,privdata,cmd,len);
free(cmd);
return status;
}
int redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, ...) {
va_list ap;
int status;
va_start(ap,format);
status = redisvAsyncCommand(ac,fn,privdata,format,ap);
va_end(ap);
return status;
}
int redisAsyncCommandArgv(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen) {
char *cmd;
int len;
int status;
len = redisFormatCommandArgv(&cmd,argc,argv,argvlen);
status = __redisAsyncCommand(ac,fn,privdata,cmd,len);
free(cmd);
return status;
}

View file

@ -0,0 +1,126 @@
/*
* Copyright (c) 2009-2011, Salvatore Sanfilippo <antirez at gmail dot com>
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __HIREDIS_ASYNC_H
#define __HIREDIS_ASYNC_H
#include "hiredis.h"
#ifdef __cplusplus
extern "C" {
#endif
struct redisAsyncContext; /* need forward declaration of redisAsyncContext */
struct dict; /* dictionary header is included in async.c */
/* Reply callback prototype and container */
typedef void (redisCallbackFn)(struct redisAsyncContext*, void*, void*);
typedef struct redisCallback {
struct redisCallback *next; /* simple singly linked list */
redisCallbackFn *fn;
void *privdata;
} redisCallback;
/* List of callbacks for either regular replies or pub/sub */
typedef struct redisCallbackList {
redisCallback *head, *tail;
} redisCallbackList;
/* Connection callback prototypes */
typedef void (redisDisconnectCallback)(const struct redisAsyncContext*, int status);
typedef void (redisConnectCallback)(const struct redisAsyncContext*, int status);
/* Context for an async connection to Redis */
typedef struct redisAsyncContext {
/* Hold the regular context, so it can be realloc'ed. */
redisContext c;
/* Setup error flags so they can be used directly. */
int err;
char *errstr;
/* Not used by hiredis */
void *data;
/* Event library data and hooks */
struct {
void *data;
/* Hooks that are called when the library expects to start
* reading/writing. These functions should be idempotent. */
void (*addRead)(void *privdata);
void (*delRead)(void *privdata);
void (*addWrite)(void *privdata);
void (*delWrite)(void *privdata);
void (*cleanup)(void *privdata);
} ev;
/* Called when either the connection is terminated due to an error or per
* user request. The status is set accordingly (REDIS_OK, REDIS_ERR). */
redisDisconnectCallback *onDisconnect;
/* Called when the first write event was received. */
redisConnectCallback *onConnect;
/* Regular command callbacks */
redisCallbackList replies;
/* Subscription callbacks */
struct {
redisCallbackList invalid;
struct dict *channels;
struct dict *patterns;
} sub;
} redisAsyncContext;
/* Functions that proxy to hiredis */
redisAsyncContext *redisAsyncConnect(const char *ip, int port);
redisAsyncContext *redisAsyncConnectBind(const char *ip, int port, const char *source_addr);
redisAsyncContext *redisAsyncConnectUnix(const char *path);
int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn);
int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn);
void redisAsyncDisconnect(redisAsyncContext *ac);
void redisAsyncFree(redisAsyncContext *ac);
/* Handle read/write events */
void redisAsyncHandleRead(redisAsyncContext *ac);
void redisAsyncHandleWrite(redisAsyncContext *ac);
/* Command functions for an async context. Write the command to the
* output buffer and register the provided callback. */
int redisvAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, va_list ap);
int redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, ...);
int redisAsyncCommandArgv(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,338 @@
/* Hash table implementation.
*
* This file implements in memory hash tables with insert/del/replace/find/
* get-random-element operations. Hash tables will auto resize if needed
* tables of power of two in size are used, collisions are handled by
* chaining. See the source code for more information... :)
*
* Copyright (c) 2006-2010, Salvatore Sanfilippo <antirez at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "fmacros.h"
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include "dict.h"
/* -------------------------- private prototypes ---------------------------- */
static int _dictExpandIfNeeded(dict *ht);
static unsigned long _dictNextPower(unsigned long size);
static int _dictKeyIndex(dict *ht, const void *key);
static int _dictInit(dict *ht, dictType *type, void *privDataPtr);
/* -------------------------- hash functions -------------------------------- */
/* Generic hash function (a popular one from Bernstein).
* I tested a few and this was the best. */
static unsigned int dictGenHashFunction(const unsigned char *buf, int len) {
unsigned int hash = 5381;
while (len--)
hash = ((hash << 5) + hash) + (*buf++); /* hash * 33 + c */
return hash;
}
/* ----------------------------- API implementation ------------------------- */
/* Reset an hashtable already initialized with ht_init().
* NOTE: This function should only called by ht_destroy(). */
static void _dictReset(dict *ht) {
ht->table = NULL;
ht->size = 0;
ht->sizemask = 0;
ht->used = 0;
}
/* Create a new hash table */
static dict *dictCreate(dictType *type, void *privDataPtr) {
dict *ht = malloc(sizeof(*ht));
_dictInit(ht,type,privDataPtr);
return ht;
}
/* Initialize the hash table */
static int _dictInit(dict *ht, dictType *type, void *privDataPtr) {
_dictReset(ht);
ht->type = type;
ht->privdata = privDataPtr;
return DICT_OK;
}
/* Expand or create the hashtable */
static int dictExpand(dict *ht, unsigned long size) {
dict n; /* the new hashtable */
unsigned long realsize = _dictNextPower(size), i;
/* the size is invalid if it is smaller than the number of
* elements already inside the hashtable */
if (ht->used > size)
return DICT_ERR;
_dictInit(&n, ht->type, ht->privdata);
n.size = realsize;
n.sizemask = realsize-1;
n.table = calloc(realsize,sizeof(dictEntry*));
/* Copy all the elements from the old to the new table:
* note that if the old hash table is empty ht->size is zero,
* so dictExpand just creates an hash table. */
n.used = ht->used;
for (i = 0; i < ht->size && ht->used > 0; i++) {
dictEntry *he, *nextHe;
if (ht->table[i] == NULL) continue;
/* For each hash entry on this slot... */
he = ht->table[i];
while(he) {
unsigned int h;
nextHe = he->next;
/* Get the new element index */
h = dictHashKey(ht, he->key) & n.sizemask;
he->next = n.table[h];
n.table[h] = he;
ht->used--;
/* Pass to the next element */
he = nextHe;
}
}
assert(ht->used == 0);
free(ht->table);
/* Remap the new hashtable in the old */
*ht = n;
return DICT_OK;
}
/* Add an element to the target hash table */
static int dictAdd(dict *ht, void *key, void *val) {
int index;
dictEntry *entry;
/* Get the index of the new element, or -1 if
* the element already exists. */
if ((index = _dictKeyIndex(ht, key)) == -1)
return DICT_ERR;
/* Allocates the memory and stores key */
entry = malloc(sizeof(*entry));
entry->next = ht->table[index];
ht->table[index] = entry;
/* Set the hash entry fields. */
dictSetHashKey(ht, entry, key);
dictSetHashVal(ht, entry, val);
ht->used++;
return DICT_OK;
}
/* Add an element, discarding the old if the key already exists.
* Return 1 if the key was added from scratch, 0 if there was already an
* element with such key and dictReplace() just performed a value update
* operation. */
static int dictReplace(dict *ht, void *key, void *val) {
dictEntry *entry, auxentry;
/* Try to add the element. If the key
* does not exists dictAdd will suceed. */
if (dictAdd(ht, key, val) == DICT_OK)
return 1;
/* It already exists, get the entry */
entry = dictFind(ht, key);
/* Free the old value and set the new one */
/* Set the new value and free the old one. Note that it is important
* to do that in this order, as the value may just be exactly the same
* as the previous one. In this context, think to reference counting,
* you want to increment (set), and then decrement (free), and not the
* reverse. */
auxentry = *entry;
dictSetHashVal(ht, entry, val);
dictFreeEntryVal(ht, &auxentry);
return 0;
}
/* Search and remove an element */
static int dictDelete(dict *ht, const void *key) {
unsigned int h;
dictEntry *de, *prevde;
if (ht->size == 0)
return DICT_ERR;
h = dictHashKey(ht, key) & ht->sizemask;
de = ht->table[h];
prevde = NULL;
while(de) {
if (dictCompareHashKeys(ht,key,de->key)) {
/* Unlink the element from the list */
if (prevde)
prevde->next = de->next;
else
ht->table[h] = de->next;
dictFreeEntryKey(ht,de);
dictFreeEntryVal(ht,de);
free(de);
ht->used--;
return DICT_OK;
}
prevde = de;
de = de->next;
}
return DICT_ERR; /* not found */
}
/* Destroy an entire hash table */
static int _dictClear(dict *ht) {
unsigned long i;
/* Free all the elements */
for (i = 0; i < ht->size && ht->used > 0; i++) {
dictEntry *he, *nextHe;
if ((he = ht->table[i]) == NULL) continue;
while(he) {
nextHe = he->next;
dictFreeEntryKey(ht, he);
dictFreeEntryVal(ht, he);
free(he);
ht->used--;
he = nextHe;
}
}
/* Free the table and the allocated cache structure */
free(ht->table);
/* Re-initialize the table */
_dictReset(ht);
return DICT_OK; /* never fails */
}
/* Clear & Release the hash table */
static void dictRelease(dict *ht) {
_dictClear(ht);
free(ht);
}
static dictEntry *dictFind(dict *ht, const void *key) {
dictEntry *he;
unsigned int h;
if (ht->size == 0) return NULL;
h = dictHashKey(ht, key) & ht->sizemask;
he = ht->table[h];
while(he) {
if (dictCompareHashKeys(ht, key, he->key))
return he;
he = he->next;
}
return NULL;
}
static dictIterator *dictGetIterator(dict *ht) {
dictIterator *iter = malloc(sizeof(*iter));
iter->ht = ht;
iter->index = -1;
iter->entry = NULL;
iter->nextEntry = NULL;
return iter;
}
static dictEntry *dictNext(dictIterator *iter) {
while (1) {
if (iter->entry == NULL) {
iter->index++;
if (iter->index >=
(signed)iter->ht->size) break;
iter->entry = iter->ht->table[iter->index];
} else {
iter->entry = iter->nextEntry;
}
if (iter->entry) {
/* We need to save the 'next' here, the iterator user
* may delete the entry we are returning. */
iter->nextEntry = iter->entry->next;
return iter->entry;
}
}
return NULL;
}
static void dictReleaseIterator(dictIterator *iter) {
free(iter);
}
/* ------------------------- private functions ------------------------------ */
/* Expand the hash table if needed */
static int _dictExpandIfNeeded(dict *ht) {
/* If the hash table is empty expand it to the intial size,
* if the table is "full" dobule its size. */
if (ht->size == 0)
return dictExpand(ht, DICT_HT_INITIAL_SIZE);
if (ht->used == ht->size)
return dictExpand(ht, ht->size*2);
return DICT_OK;
}
/* Our hash table capability is a power of two */
static unsigned long _dictNextPower(unsigned long size) {
unsigned long i = DICT_HT_INITIAL_SIZE;
if (size >= LONG_MAX) return LONG_MAX;
while(1) {
if (i >= size)
return i;
i *= 2;
}
}
/* Returns the index of a free slot that can be populated with
* an hash entry for the given 'key'.
* If the key already exists, -1 is returned. */
static int _dictKeyIndex(dict *ht, const void *key) {
unsigned int h;
dictEntry *he;
/* Expand the hashtable if needed */
if (_dictExpandIfNeeded(ht) == DICT_ERR)
return -1;
/* Compute the key hash value */
h = dictHashKey(ht, key) & ht->sizemask;
/* Search if this slot does not already contain the given key */
he = ht->table[h];
while(he) {
if (dictCompareHashKeys(ht, key, he->key))
return -1;
he = he->next;
}
return h;
}

View file

@ -0,0 +1,126 @@
/* Hash table implementation.
*
* This file implements in memory hash tables with insert/del/replace/find/
* get-random-element operations. Hash tables will auto resize if needed
* tables of power of two in size are used, collisions are handled by
* chaining. See the source code for more information... :)
*
* Copyright (c) 2006-2010, Salvatore Sanfilippo <antirez at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __DICT_H
#define __DICT_H
#define DICT_OK 0
#define DICT_ERR 1
/* Unused arguments generate annoying warnings... */
#define DICT_NOTUSED(V) ((void) V)
typedef struct dictEntry {
void *key;
void *val;
struct dictEntry *next;
} dictEntry;
typedef struct dictType {
unsigned int (*hashFunction)(const void *key);
void *(*keyDup)(void *privdata, const void *key);
void *(*valDup)(void *privdata, const void *obj);
int (*keyCompare)(void *privdata, const void *key1, const void *key2);
void (*keyDestructor)(void *privdata, void *key);
void (*valDestructor)(void *privdata, void *obj);
} dictType;
typedef struct dict {
dictEntry **table;
dictType *type;
unsigned long size;
unsigned long sizemask;
unsigned long used;
void *privdata;
} dict;
typedef struct dictIterator {
dict *ht;
int index;
dictEntry *entry, *nextEntry;
} dictIterator;
/* This is the initial size of every hash table */
#define DICT_HT_INITIAL_SIZE 4
/* ------------------------------- Macros ------------------------------------*/
#define dictFreeEntryVal(ht, entry) \
if ((ht)->type->valDestructor) \
(ht)->type->valDestructor((ht)->privdata, (entry)->val)
#define dictSetHashVal(ht, entry, _val_) do { \
if ((ht)->type->valDup) \
entry->val = (ht)->type->valDup((ht)->privdata, _val_); \
else \
entry->val = (_val_); \
} while(0)
#define dictFreeEntryKey(ht, entry) \
if ((ht)->type->keyDestructor) \
(ht)->type->keyDestructor((ht)->privdata, (entry)->key)
#define dictSetHashKey(ht, entry, _key_) do { \
if ((ht)->type->keyDup) \
entry->key = (ht)->type->keyDup((ht)->privdata, _key_); \
else \
entry->key = (_key_); \
} while(0)
#define dictCompareHashKeys(ht, key1, key2) \
(((ht)->type->keyCompare) ? \
(ht)->type->keyCompare((ht)->privdata, key1, key2) : \
(key1) == (key2))
#define dictHashKey(ht, key) (ht)->type->hashFunction(key)
#define dictGetEntryKey(he) ((he)->key)
#define dictGetEntryVal(he) ((he)->val)
#define dictSlots(ht) ((ht)->size)
#define dictSize(ht) ((ht)->used)
/* API */
static unsigned int dictGenHashFunction(const unsigned char *buf, int len);
static dict *dictCreate(dictType *type, void *privDataPtr);
static int dictExpand(dict *ht, unsigned long size);
static int dictAdd(dict *ht, void *key, void *val);
static int dictReplace(dict *ht, void *key, void *val);
static int dictDelete(dict *ht, const void *key);
static void dictRelease(dict *ht);
static dictEntry * dictFind(dict *ht, const void *key);
static dictIterator *dictGetIterator(dict *ht);
static dictEntry *dictNext(dictIterator *iter);
static void dictReleaseIterator(dictIterator *iter);
#endif /* __DICT_H */

View file

@ -0,0 +1,62 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <hiredis.h>
#include <async.h>
#include <adapters/ae.h>
/* Put event loop in the global scope, so it can be explicitly stopped */
static aeEventLoop *loop;
void getCallback(redisAsyncContext *c, void *r, void *privdata) {
redisReply *reply = r;
if (reply == NULL) return;
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
/* Disconnect after receiving the reply to GET */
redisAsyncDisconnect(c);
}
void connectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
aeStop(loop);
return;
}
printf("Connected...\n");
}
void disconnectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
aeStop(loop);
return;
}
printf("Disconnected...\n");
aeStop(loop);
}
int main (int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
if (c->err) {
/* Let *c leak for now... */
printf("Error: %s\n", c->errstr);
return 1;
}
loop = aeCreateEventLoop(64);
redisAeAttach(loop, c);
redisAsyncSetConnectCallback(c,connectCallback);
redisAsyncSetDisconnectCallback(c,disconnectCallback);
redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
aeMain(loop);
return 0;
}

View file

@ -0,0 +1,52 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <hiredis.h>
#include <async.h>
#include <adapters/libev.h>
void getCallback(redisAsyncContext *c, void *r, void *privdata) {
redisReply *reply = r;
if (reply == NULL) return;
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
/* Disconnect after receiving the reply to GET */
redisAsyncDisconnect(c);
}
void connectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
return;
}
printf("Connected...\n");
}
void disconnectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
return;
}
printf("Disconnected...\n");
}
int main (int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
if (c->err) {
/* Let *c leak for now... */
printf("Error: %s\n", c->errstr);
return 1;
}
redisLibevAttach(EV_DEFAULT_ c);
redisAsyncSetConnectCallback(c,connectCallback);
redisAsyncSetDisconnectCallback(c,disconnectCallback);
redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
ev_loop(EV_DEFAULT_ 0);
return 0;
}

View file

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <hiredis.h>
#include <async.h>
#include <adapters/libevent.h>
void getCallback(redisAsyncContext *c, void *r, void *privdata) {
redisReply *reply = r;
if (reply == NULL) return;
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
/* Disconnect after receiving the reply to GET */
redisAsyncDisconnect(c);
}
void connectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
return;
}
printf("Connected...\n");
}
void disconnectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
return;
}
printf("Disconnected...\n");
}
int main (int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
struct event_base *base = event_base_new();
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
if (c->err) {
/* Let *c leak for now... */
printf("Error: %s\n", c->errstr);
return 1;
}
redisLibeventAttach(c,base);
redisAsyncSetConnectCallback(c,connectCallback);
redisAsyncSetDisconnectCallback(c,disconnectCallback);
redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
event_base_dispatch(base);
return 0;
}

View file

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <hiredis.h>
#include <async.h>
#include <adapters/libuv.h>
void getCallback(redisAsyncContext *c, void *r, void *privdata) {
redisReply *reply = r;
if (reply == NULL) return;
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
/* Disconnect after receiving the reply to GET */
redisAsyncDisconnect(c);
}
void connectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
return;
}
printf("Connected...\n");
}
void disconnectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
return;
}
printf("Disconnected...\n");
}
int main (int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
uv_loop_t* loop = uv_default_loop();
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
if (c->err) {
/* Let *c leak for now... */
printf("Error: %s\n", c->errstr);
return 1;
}
redisLibuvAttach(c,loop);
redisAsyncSetConnectCallback(c,connectCallback);
redisAsyncSetDisconnectCallback(c,disconnectCallback);
redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
uv_run(loop, UV_RUN_DEFAULT);
return 0;
}

View file

@ -0,0 +1,78 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hiredis.h>
int main(int argc, char **argv) {
unsigned int j;
redisContext *c;
redisReply *reply;
const char *hostname = (argc > 1) ? argv[1] : "127.0.0.1";
int port = (argc > 2) ? atoi(argv[2]) : 6379;
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
c = redisConnectWithTimeout(hostname, port, timeout);
if (c == NULL || c->err) {
if (c) {
printf("Connection error: %s\n", c->errstr);
redisFree(c);
} else {
printf("Connection error: can't allocate redis context\n");
}
exit(1);
}
/* PING server */
reply = redisCommand(c,"PING");
printf("PING: %s\n", reply->str);
freeReplyObject(reply);
/* Set a key */
reply = redisCommand(c,"SET %s %s", "foo", "hello world");
printf("SET: %s\n", reply->str);
freeReplyObject(reply);
/* Set a key using binary safe API */
reply = redisCommand(c,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5);
printf("SET (binary API): %s\n", reply->str);
freeReplyObject(reply);
/* Try a GET and two INCR */
reply = redisCommand(c,"GET foo");
printf("GET foo: %s\n", reply->str);
freeReplyObject(reply);
reply = redisCommand(c,"INCR counter");
printf("INCR counter: %lld\n", reply->integer);
freeReplyObject(reply);
/* again ... */
reply = redisCommand(c,"INCR counter");
printf("INCR counter: %lld\n", reply->integer);
freeReplyObject(reply);
/* Create a list of numbers, from 0 to 9 */
reply = redisCommand(c,"DEL mylist");
freeReplyObject(reply);
for (j = 0; j < 10; j++) {
char buf[64];
snprintf(buf,64,"%d",j);
reply = redisCommand(c,"LPUSH mylist element-%s", buf);
freeReplyObject(reply);
}
/* Let's check what we have inside the list */
reply = redisCommand(c,"LRANGE mylist 0 -1");
if (reply->type == REDIS_REPLY_ARRAY) {
for (j = 0; j < reply->elements; j++) {
printf("%u) %s\n", j, reply->element[j]->str);
}
}
freeReplyObject(reply);
/* Disconnects and frees the context */
redisFree(c);
return 0;
}

View file

@ -0,0 +1,24 @@
#ifndef __HIREDIS_FMACRO_H
#define __HIREDIS_FMACRO_H
#if !defined(_BSD_SOURCE)
#define _BSD_SOURCE
#endif
#if defined(_AIX)
#define _ALL_SOURCE
#endif
#if defined(__sun__)
#define _POSIX_C_SOURCE 200112L
#elif defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__)
#define _XOPEN_SOURCE 600
#else
#define _XOPEN_SOURCE
#endif
#if __APPLE__ && __MACH__
#define _OSX
#endif
#endif

View file

@ -0,0 +1,220 @@
/*
* Copyright (c) 2009-2011, Salvatore Sanfilippo <antirez at gmail dot com>
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __HIREDIS_H
#define __HIREDIS_H
#include <stdio.h> /* for size_t */
#include <stdarg.h> /* for va_list */
#include <sys/time.h> /* for struct timeval */
#define HIREDIS_MAJOR 0
#define HIREDIS_MINOR 11
#define HIREDIS_PATCH 0
#define REDIS_ERR -1
#define REDIS_OK 0
/* When an error occurs, the err flag in a context is set to hold the type of
* error that occured. REDIS_ERR_IO means there was an I/O error and you
* should use the "errno" variable to find out what is wrong.
* For other values, the "errstr" field will hold a description. */
#define REDIS_ERR_IO 1 /* Error in read or write */
#define REDIS_ERR_EOF 3 /* End of file */
#define REDIS_ERR_PROTOCOL 4 /* Protocol error */
#define REDIS_ERR_OOM 5 /* Out of memory */
#define REDIS_ERR_OTHER 2 /* Everything else... */
/* Connection type can be blocking or non-blocking and is set in the
* least significant bit of the flags field in redisContext. */
#define REDIS_BLOCK 0x1
/* Connection may be disconnected before being free'd. The second bit
* in the flags field is set when the context is connected. */
#define REDIS_CONNECTED 0x2
/* The async API might try to disconnect cleanly and flush the output
* buffer and read all subsequent replies before disconnecting.
* This flag means no new commands can come in and the connection
* should be terminated once all replies have been read. */
#define REDIS_DISCONNECTING 0x4
/* Flag specific to the async API which means that the context should be clean
* up as soon as possible. */
#define REDIS_FREEING 0x8
/* Flag that is set when an async callback is executed. */
#define REDIS_IN_CALLBACK 0x10
/* Flag that is set when the async context has one or more subscriptions. */
#define REDIS_SUBSCRIBED 0x20
/* Flag that is set when monitor mode is active */
#define REDIS_MONITORING 0x40
#define REDIS_REPLY_STRING 1
#define REDIS_REPLY_ARRAY 2
#define REDIS_REPLY_INTEGER 3
#define REDIS_REPLY_NIL 4
#define REDIS_REPLY_STATUS 5
#define REDIS_REPLY_ERROR 6
#define REDIS_READER_MAX_BUF (1024*16) /* Default max unused reader buffer. */
#define REDIS_KEEPALIVE_INTERVAL 15 /* seconds */
#ifdef __cplusplus
extern "C" {
#endif
/* This is the reply object returned by redisCommand() */
typedef struct redisReply {
int type; /* REDIS_REPLY_* */
long long integer; /* The integer when type is REDIS_REPLY_INTEGER */
int len; /* Length of string */
char *str; /* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */
size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */
} redisReply;
typedef struct redisReadTask {
int type;
int elements; /* number of elements in multibulk container */
int idx; /* index in parent (array) object */
void *obj; /* holds user-generated value for a read task */
struct redisReadTask *parent; /* parent task */
void *privdata; /* user-settable arbitrary field */
} redisReadTask;
typedef struct redisReplyObjectFunctions {
void *(*createString)(const redisReadTask*, char*, size_t);
void *(*createArray)(const redisReadTask*, int);
void *(*createInteger)(const redisReadTask*, long long);
void *(*createNil)(const redisReadTask*);
void (*freeObject)(void*);
} redisReplyObjectFunctions;
/* State for the protocol parser */
typedef struct redisReader {
int err; /* Error flags, 0 when there is no error */
char errstr[128]; /* String representation of error when applicable */
char *buf; /* Read buffer */
size_t pos; /* Buffer cursor */
size_t len; /* Buffer length */
size_t maxbuf; /* Max length of unused buffer */
redisReadTask rstack[9];
int ridx; /* Index of current read task */
void *reply; /* Temporary reply pointer */
redisReplyObjectFunctions *fn;
void *privdata;
} redisReader;
/* Public API for the protocol parser. */
redisReader *redisReaderCreate(void);
void redisReaderFree(redisReader *r);
int redisReaderFeed(redisReader *r, const char *buf, size_t len);
int redisReaderGetReply(redisReader *r, void **reply);
/* Backwards compatibility, can be removed on big version bump. */
#define redisReplyReaderCreate redisReaderCreate
#define redisReplyReaderFree redisReaderFree
#define redisReplyReaderFeed redisReaderFeed
#define redisReplyReaderGetReply redisReaderGetReply
#define redisReplyReaderSetPrivdata(_r, _p) (int)(((redisReader*)(_r))->privdata = (_p))
#define redisReplyReaderGetObject(_r) (((redisReader*)(_r))->reply)
#define redisReplyReaderGetError(_r) (((redisReader*)(_r))->errstr)
/* Function to free the reply objects hiredis returns by default. */
void freeReplyObject(void *reply);
/* Functions to format a command according to the protocol. */
int redisvFormatCommand(char **target, const char *format, va_list ap);
int redisFormatCommand(char **target, const char *format, ...);
int redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen);
/* Context for a connection to Redis */
typedef struct redisContext {
int err; /* Error flags, 0 when there is no error */
char errstr[128]; /* String representation of error when applicable */
int fd;
int flags;
char *obuf; /* Write buffer */
redisReader *reader; /* Protocol reader */
} redisContext;
redisContext *redisConnect(const char *ip, int port);
redisContext *redisConnectWithTimeout(const char *ip, int port, const struct timeval tv);
redisContext *redisConnectNonBlock(const char *ip, int port);
redisContext *redisConnectBindNonBlock(const char *ip, int port, const char *source_addr);
redisContext *redisConnectUnix(const char *path);
redisContext *redisConnectUnixWithTimeout(const char *path, const struct timeval tv);
redisContext *redisConnectUnixNonBlock(const char *path);
redisContext *redisConnectFd(int fd);
int redisSetTimeout(redisContext *c, const struct timeval tv);
int redisEnableKeepAlive(redisContext *c);
void redisFree(redisContext *c);
int redisFreeKeepFd(redisContext *c);
int redisBufferRead(redisContext *c);
int redisBufferWrite(redisContext *c, int *done);
/* In a blocking context, this function first checks if there are unconsumed
* replies to return and returns one if so. Otherwise, it flushes the output
* buffer to the socket and reads until it has a reply. In a non-blocking
* context, it will return unconsumed replies until there are no more. */
int redisGetReply(redisContext *c, void **reply);
int redisGetReplyFromReader(redisContext *c, void **reply);
/* Write a formatted command to the output buffer. Use these functions in blocking mode
* to get a pipeline of commands. */
int redisAppendFormattedCommand(redisContext *c, const char *cmd, size_t len);
/* Write a command to the output buffer. Use these functions in blocking mode
* to get a pipeline of commands. */
int redisvAppendCommand(redisContext *c, const char *format, va_list ap);
int redisAppendCommand(redisContext *c, const char *format, ...);
int redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen);
/* Issue a command to Redis. In a blocking context, it is identical to calling
* redisAppendCommand, followed by redisGetReply. The function will return
* NULL if there was an error in performing the request, otherwise it will
* return the reply. In a non-blocking context, it is identical to calling
* only redisAppendCommand and will always return NULL. */
void *redisvCommand(redisContext *c, const char *format, va_list ap);
void *redisCommand(redisContext *c, const char *format, ...);
void *redisCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,382 @@
/* Extracted from anet.c to work properly with Hiredis error reporting.
*
* Copyright (c) 2006-2011, Salvatore Sanfilippo <antirez at gmail dot com>
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "fmacros.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <netdb.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <poll.h>
#include <limits.h>
#include "net.h"
#include "sds.h"
/* Defined in hiredis.c */
void __redisSetError(redisContext *c, int type, const char *str);
static void redisContextCloseFd(redisContext *c) {
if (c && c->fd >= 0) {
close(c->fd);
c->fd = -1;
}
}
static void __redisSetErrorFromErrno(redisContext *c, int type, const char *prefix) {
char buf[128] = { 0 };
size_t len = 0;
if (prefix != NULL)
len = snprintf(buf,sizeof(buf),"%s: ",prefix);
strerror_r(errno,buf+len,sizeof(buf)-len);
__redisSetError(c,type,buf);
}
static int redisSetReuseAddr(redisContext *c) {
int on = 1;
if (setsockopt(c->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
redisContextCloseFd(c);
return REDIS_ERR;
}
return REDIS_OK;
}
static int redisCreateSocket(redisContext *c, int type) {
int s;
if ((s = socket(type, SOCK_STREAM, 0)) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
return REDIS_ERR;
}
c->fd = s;
if (type == AF_INET) {
if (redisSetReuseAddr(c) == REDIS_ERR) {
return REDIS_ERR;
}
}
return REDIS_OK;
}
static int redisSetBlocking(redisContext *c, int blocking) {
int flags;
/* Set the socket nonblocking.
* Note that fcntl(2) for F_GETFL and F_SETFL can't be
* interrupted by a signal. */
if ((flags = fcntl(c->fd, F_GETFL)) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(F_GETFL)");
redisContextCloseFd(c);
return REDIS_ERR;
}
if (blocking)
flags &= ~O_NONBLOCK;
else
flags |= O_NONBLOCK;
if (fcntl(c->fd, F_SETFL, flags) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(F_SETFL)");
redisContextCloseFd(c);
return REDIS_ERR;
}
return REDIS_OK;
}
int redisKeepAlive(redisContext *c, int interval) {
int val = 1;
int fd = c->fd;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) == -1){
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
return REDIS_ERR;
}
val = interval;
#ifdef _OSX
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &val, sizeof(val)) < 0) {
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
return REDIS_ERR;
}
#else
#ifndef __sun
val = interval;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) {
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
return REDIS_ERR;
}
val = interval/3;
if (val == 0) val = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) {
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
return REDIS_ERR;
}
val = 3;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof(val)) < 0) {
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
return REDIS_ERR;
}
#endif
#endif
return REDIS_OK;
}
static int redisSetTcpNoDelay(redisContext *c) {
int yes = 1;
if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(TCP_NODELAY)");
redisContextCloseFd(c);
return REDIS_ERR;
}
return REDIS_OK;
}
#define __MAX_MSEC (((LONG_MAX) - 999) / 1000)
static int redisContextWaitReady(redisContext *c, const struct timeval *timeout) {
struct pollfd wfd[1];
long msec;
msec = -1;
wfd[0].fd = c->fd;
wfd[0].events = POLLOUT;
/* Only use timeout when not NULL. */
if (timeout != NULL) {
if (timeout->tv_usec > 1000000 || timeout->tv_sec > __MAX_MSEC) {
__redisSetErrorFromErrno(c, REDIS_ERR_IO, NULL);
redisContextCloseFd(c);
return REDIS_ERR;
}
msec = (timeout->tv_sec * 1000) + ((timeout->tv_usec + 999) / 1000);
if (msec < 0 || msec > INT_MAX) {
msec = INT_MAX;
}
}
if (errno == EINPROGRESS) {
int res;
if ((res = poll(wfd, 1, msec)) == -1) {
__redisSetErrorFromErrno(c, REDIS_ERR_IO, "poll(2)");
redisContextCloseFd(c);
return REDIS_ERR;
} else if (res == 0) {
errno = ETIMEDOUT;
__redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
redisContextCloseFd(c);
return REDIS_ERR;
}
if (redisCheckSocketError(c) != REDIS_OK)
return REDIS_ERR;
return REDIS_OK;
}
__redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
redisContextCloseFd(c);
return REDIS_ERR;
}
int redisCheckSocketError(redisContext *c) {
int err = 0;
socklen_t errlen = sizeof(err);
if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, &err, &errlen) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"getsockopt(SO_ERROR)");
return REDIS_ERR;
}
if (err) {
errno = err;
__redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
return REDIS_ERR;
}
return REDIS_OK;
}
int redisContextSetTimeout(redisContext *c, const struct timeval tv) {
if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof(tv)) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_RCVTIMEO)");
return REDIS_ERR;
}
if (setsockopt(c->fd,SOL_SOCKET,SO_SNDTIMEO,&tv,sizeof(tv)) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_SNDTIMEO)");
return REDIS_ERR;
}
return REDIS_OK;
}
static int _redisContextConnectTcp(redisContext *c, const char *addr, int port,
const struct timeval *timeout,
const char *source_addr) {
int s, rv;
char _port[6]; /* strlen("65535"); */
struct addrinfo hints, *servinfo, *bservinfo, *p, *b;
int blocking = (c->flags & REDIS_BLOCK);
snprintf(_port, 6, "%d", port);
memset(&hints,0,sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
/* Try with IPv6 if no IPv4 address was found. We do it in this order since
* in a Redis client you can't afford to test if you have IPv6 connectivity
* as this would add latency to every connect. Otherwise a more sensible
* route could be: Use IPv6 if both addresses are available and there is IPv6
* connectivity. */
if ((rv = getaddrinfo(addr,_port,&hints,&servinfo)) != 0) {
hints.ai_family = AF_INET6;
if ((rv = getaddrinfo(addr,_port,&hints,&servinfo)) != 0) {
__redisSetError(c,REDIS_ERR_OTHER,gai_strerror(rv));
return REDIS_ERR;
}
}
for (p = servinfo; p != NULL; p = p->ai_next) {
if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == -1)
continue;
c->fd = s;
if (redisSetBlocking(c,0) != REDIS_OK)
goto error;
if (source_addr) {
int bound = 0;
/* Using getaddrinfo saves us from self-determining IPv4 vs IPv6 */
if ((rv = getaddrinfo(source_addr, NULL, &hints, &bservinfo)) != 0) {
char buf[128];
snprintf(buf,sizeof(buf),"Can't get addr: %s",gai_strerror(rv));
__redisSetError(c,REDIS_ERR_OTHER,buf);
goto error;
}
for (b = bservinfo; b != NULL; b = b->ai_next) {
if (bind(s,b->ai_addr,b->ai_addrlen) != -1) {
bound = 1;
break;
}
}
freeaddrinfo(bservinfo);
if (!bound) {
char buf[128];
snprintf(buf,sizeof(buf),"Can't bind socket: %s",strerror(errno));
__redisSetError(c,REDIS_ERR_OTHER,buf);
goto error;
}
}
if (connect(s,p->ai_addr,p->ai_addrlen) == -1) {
if (errno == EHOSTUNREACH) {
redisContextCloseFd(c);
continue;
} else if (errno == EINPROGRESS && !blocking) {
/* This is ok. */
} else {
if (redisContextWaitReady(c,timeout) != REDIS_OK)
goto error;
}
}
if (blocking && redisSetBlocking(c,1) != REDIS_OK)
goto error;
if (redisSetTcpNoDelay(c) != REDIS_OK)
goto error;
c->flags |= REDIS_CONNECTED;
rv = REDIS_OK;
goto end;
}
if (p == NULL) {
char buf[128];
snprintf(buf,sizeof(buf),"Can't create socket: %s",strerror(errno));
__redisSetError(c,REDIS_ERR_OTHER,buf);
goto error;
}
error:
rv = REDIS_ERR;
end:
freeaddrinfo(servinfo);
return rv; // Need to return REDIS_OK if alright
}
int redisContextConnectTcp(redisContext *c, const char *addr, int port,
const struct timeval *timeout) {
return _redisContextConnectTcp(c, addr, port, timeout, NULL);
}
int redisContextConnectBindTcp(redisContext *c, const char *addr, int port,
const struct timeval *timeout,
const char *source_addr) {
return _redisContextConnectTcp(c, addr, port, timeout, source_addr);
}
int redisContextConnectUnix(redisContext *c, const char *path, const struct timeval *timeout) {
int blocking = (c->flags & REDIS_BLOCK);
struct sockaddr_un sa;
if (redisCreateSocket(c,AF_LOCAL) < 0)
return REDIS_ERR;
if (redisSetBlocking(c,0) != REDIS_OK)
return REDIS_ERR;
sa.sun_family = AF_LOCAL;
strncpy(sa.sun_path,path,sizeof(sa.sun_path)-1);
if (connect(c->fd, (struct sockaddr*)&sa, sizeof(sa)) == -1) {
if (errno == EINPROGRESS && !blocking) {
/* This is ok. */
} else {
if (redisContextWaitReady(c,timeout) != REDIS_OK)
return REDIS_ERR;
}
}
/* Reset socket to be blocking after connect(2). */
if (blocking && redisSetBlocking(c,1) != REDIS_OK)
return REDIS_ERR;
c->flags |= REDIS_CONNECTED;
return REDIS_OK;
}

View file

@ -0,0 +1,51 @@
/* Extracted from anet.c to work properly with Hiredis error reporting.
*
* Copyright (c) 2006-2011, Salvatore Sanfilippo <antirez at gmail dot com>
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __NET_H
#define __NET_H
#include "hiredis.h"
#if defined(__sun) || defined(_AIX)
#define AF_LOCAL AF_UNIX
#endif
int redisCheckSocketError(redisContext *c);
int redisContextSetTimeout(redisContext *c, const struct timeval tv);
int redisContextConnectTcp(redisContext *c, const char *addr, int port, const struct timeval *timeout);
int redisContextConnectBindTcp(redisContext *c, const char *addr, int port,
const struct timeval *timeout,
const char *source_addr);
int redisContextConnectUnix(redisContext *c, const char *path, const struct timeval *timeout);
int redisKeepAlive(redisContext *c, int interval);
#endif

View file

@ -0,0 +1,101 @@
/* SDSLib, A C dynamic strings library
*
* Copyright (c) 2006-2010, Salvatore Sanfilippo <antirez at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Redis nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SDS_H
#define __SDS_H
#define SDS_MAX_PREALLOC (1024*1024)
#include <sys/types.h>
#include <stdarg.h>
typedef char *sds;
struct sdshdr {
unsigned int len;
unsigned int free;
char buf[];
};
static inline size_t sdslen(const sds s) {
struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr)));
return sh->len;
}
static inline size_t sdsavail(const sds s) {
struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr)));
return sh->free;
}
sds sdsnewlen(const void *init, size_t initlen);
sds sdsnew(const char *init);
sds sdsempty(void);
size_t sdslen(const sds s);
sds sdsdup(const sds s);
void sdsfree(sds s);
size_t sdsavail(const sds s);
sds sdsgrowzero(sds s, size_t len);
sds sdscatlen(sds s, const void *t, size_t len);
sds sdscat(sds s, const char *t);
sds sdscatsds(sds s, const sds t);
sds sdscpylen(sds s, const char *t, size_t len);
sds sdscpy(sds s, const char *t);
sds sdscatvprintf(sds s, const char *fmt, va_list ap);
#ifdef __GNUC__
sds sdscatprintf(sds s, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
#else
sds sdscatprintf(sds s, const char *fmt, ...);
#endif
sds sdscatfmt(sds s, char const *fmt, ...);
sds sdstrim(sds s, const char *cset);
void sdsrange(sds s, int start, int end);
void sdsupdatelen(sds s);
void sdsclear(sds s);
int sdscmp(const sds s1, const sds s2);
sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count);
void sdsfreesplitres(sds *tokens, int count);
void sdstolower(sds s);
void sdstoupper(sds s);
sds sdsfromlonglong(long long value);
sds sdscatrepr(sds s, const char *p, size_t len);
sds *sdssplitargs(const char *line, int *argc);
sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen);
sds sdsjoin(char **argv, int argc, char *sep);
/* Low level functions exposed to the user API */
sds sdsMakeRoomFor(sds s, size_t addlen);
void sdsIncrLen(sds s, int incr);
sds sdsRemoveFreeSpace(sds s);
size_t sdsAllocSize(sds s);
#endif

View file

@ -0,0 +1,733 @@
#include "fmacros.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/time.h>
#include <assert.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <limits.h>
#include "hiredis.h"
enum connection_type {
CONN_TCP,
CONN_UNIX,
CONN_FD
};
struct config {
enum connection_type type;
struct {
const char *host;
int port;
struct timeval timeout;
} tcp;
struct {
const char *path;
} unix;
};
/* The following lines make up our testing "framework" :) */
static int tests = 0, fails = 0;
#define test(_s) { printf("#%02d ", ++tests); printf(_s); }
#define test_cond(_c) if(_c) printf("\033[0;32mPASSED\033[0;0m\n"); else {printf("\033[0;31mFAILED\033[0;0m\n"); fails++;}
static long long usec(void) {
struct timeval tv;
gettimeofday(&tv,NULL);
return (((long long)tv.tv_sec)*1000000)+tv.tv_usec;
}
static redisContext *select_database(redisContext *c) {
redisReply *reply;
/* Switch to DB 9 for testing, now that we know we can chat. */
reply = redisCommand(c,"SELECT 9");
assert(reply != NULL);
freeReplyObject(reply);
/* Make sure the DB is empty */
reply = redisCommand(c,"DBSIZE");
assert(reply != NULL);
if (reply->type == REDIS_REPLY_INTEGER && reply->integer == 0) {
/* Awesome, DB 9 is empty and we can continue. */
freeReplyObject(reply);
} else {
printf("Database #9 is not empty, test can not continue\n");
exit(1);
}
return c;
}
static int disconnect(redisContext *c, int keep_fd) {
redisReply *reply;
/* Make sure we're on DB 9. */
reply = redisCommand(c,"SELECT 9");
assert(reply != NULL);
freeReplyObject(reply);
reply = redisCommand(c,"FLUSHDB");
assert(reply != NULL);
freeReplyObject(reply);
/* Free the context as well, but keep the fd if requested. */
if (keep_fd)
return redisFreeKeepFd(c);
redisFree(c);
return -1;
}
static redisContext *connect(struct config config) {
redisContext *c = NULL;
if (config.type == CONN_TCP) {
c = redisConnect(config.tcp.host, config.tcp.port);
} else if (config.type == CONN_UNIX) {
c = redisConnectUnix(config.unix.path);
} else if (config.type == CONN_FD) {
/* Create a dummy connection just to get an fd to inherit */
redisContext *dummy_ctx = redisConnectUnix(config.unix.path);
if (dummy_ctx) {
int fd = disconnect(dummy_ctx, 1);
printf("Connecting to inherited fd %d\n", fd);
c = redisConnectFd(fd);
}
} else {
assert(NULL);
}
if (c == NULL) {
printf("Connection error: can't allocate redis context\n");
exit(1);
} else if (c->err) {
printf("Connection error: %s\n", c->errstr);
exit(1);
}
return select_database(c);
}
static void test_format_commands(void) {
char *cmd;
int len;
test("Format command without interpolation: ");
len = redisFormatCommand(&cmd,"SET foo bar");
test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n",len) == 0 &&
len == 4+4+(3+2)+4+(3+2)+4+(3+2));
free(cmd);
test("Format command with %%s string interpolation: ");
len = redisFormatCommand(&cmd,"SET %s %s","foo","bar");
test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n",len) == 0 &&
len == 4+4+(3+2)+4+(3+2)+4+(3+2));
free(cmd);
test("Format command with %%s and an empty string: ");
len = redisFormatCommand(&cmd,"SET %s %s","foo","");
test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$0\r\n\r\n",len) == 0 &&
len == 4+4+(3+2)+4+(3+2)+4+(0+2));
free(cmd);
test("Format command with an empty string in between proper interpolations: ");
len = redisFormatCommand(&cmd,"SET %s %s","","foo");
test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$0\r\n\r\n$3\r\nfoo\r\n",len) == 0 &&
len == 4+4+(3+2)+4+(0+2)+4+(3+2));
free(cmd);
test("Format command with %%b string interpolation: ");
len = redisFormatCommand(&cmd,"SET %b %b","foo",(size_t)3,"b\0r",(size_t)3);
test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nb\0r\r\n",len) == 0 &&
len == 4+4+(3+2)+4+(3+2)+4+(3+2));
free(cmd);
test("Format command with %%b and an empty string: ");
len = redisFormatCommand(&cmd,"SET %b %b","foo",(size_t)3,"",(size_t)0);
test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$0\r\n\r\n",len) == 0 &&
len == 4+4+(3+2)+4+(3+2)+4+(0+2));
free(cmd);
test("Format command with literal %%: ");
len = redisFormatCommand(&cmd,"SET %% %%");
test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$1\r\n%\r\n$1\r\n%\r\n",len) == 0 &&
len == 4+4+(3+2)+4+(1+2)+4+(1+2));
free(cmd);
/* Vararg width depends on the type. These tests make sure that the
* width is correctly determined using the format and subsequent varargs
* can correctly be interpolated. */
#define INTEGER_WIDTH_TEST(fmt, type) do { \
type value = 123; \
test("Format command with printf-delegation (" #type "): "); \
len = redisFormatCommand(&cmd,"key:%08" fmt " str:%s", value, "hello"); \
test_cond(strncmp(cmd,"*2\r\n$12\r\nkey:00000123\r\n$9\r\nstr:hello\r\n",len) == 0 && \
len == 4+5+(12+2)+4+(9+2)); \
free(cmd); \
} while(0)
#define FLOAT_WIDTH_TEST(type) do { \
type value = 123.0; \
test("Format command with printf-delegation (" #type "): "); \
len = redisFormatCommand(&cmd,"key:%08.3f str:%s", value, "hello"); \
test_cond(strncmp(cmd,"*2\r\n$12\r\nkey:0123.000\r\n$9\r\nstr:hello\r\n",len) == 0 && \
len == 4+5+(12+2)+4+(9+2)); \
free(cmd); \
} while(0)
INTEGER_WIDTH_TEST("d", int);
INTEGER_WIDTH_TEST("hhd", char);
INTEGER_WIDTH_TEST("hd", short);
INTEGER_WIDTH_TEST("ld", long);
INTEGER_WIDTH_TEST("lld", long long);
INTEGER_WIDTH_TEST("u", unsigned int);
INTEGER_WIDTH_TEST("hhu", unsigned char);
INTEGER_WIDTH_TEST("hu", unsigned short);
INTEGER_WIDTH_TEST("lu", unsigned long);
INTEGER_WIDTH_TEST("llu", unsigned long long);
FLOAT_WIDTH_TEST(float);
FLOAT_WIDTH_TEST(double);
test("Format command with invalid printf format: ");
len = redisFormatCommand(&cmd,"key:%08p %b",(void*)1234,"foo",(size_t)3);
test_cond(len == -1);
const char *argv[3];
argv[0] = "SET";
argv[1] = "foo\0xxx";
argv[2] = "bar";
size_t lens[3] = { 3, 7, 3 };
int argc = 3;
test("Format command by passing argc/argv without lengths: ");
len = redisFormatCommandArgv(&cmd,argc,argv,NULL);
test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n",len) == 0 &&
len == 4+4+(3+2)+4+(3+2)+4+(3+2));
free(cmd);
test("Format command by passing argc/argv with lengths: ");
len = redisFormatCommandArgv(&cmd,argc,argv,lens);
test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$7\r\nfoo\0xxx\r\n$3\r\nbar\r\n",len) == 0 &&
len == 4+4+(3+2)+4+(7+2)+4+(3+2));
free(cmd);
}
static void test_append_formatted_commands(struct config config) {
redisContext *c;
redisReply *reply;
char *cmd;
int len;
c = connect(config);
test("Append format command: ");
len = redisFormatCommand(&cmd, "SET foo bar");
test_cond(redisAppendFormattedCommand(c, cmd, len) == REDIS_OK);
assert(redisGetReply(c, (void*)&reply) == REDIS_OK);
free(cmd);
freeReplyObject(reply);
disconnect(c, 0);
}
static void test_reply_reader(void) {
redisReader *reader;
void *reply;
int ret;
int i;
test("Error handling in reply parser: ");
reader = redisReaderCreate();
redisReaderFeed(reader,(char*)"@foo\r\n",6);
ret = redisReaderGetReply(reader,NULL);
test_cond(ret == REDIS_ERR &&
strcasecmp(reader->errstr,"Protocol error, got \"@\" as reply type byte") == 0);
redisReaderFree(reader);
/* when the reply already contains multiple items, they must be free'd
* on an error. valgrind will bark when this doesn't happen. */
test("Memory cleanup in reply parser: ");
reader = redisReaderCreate();
redisReaderFeed(reader,(char*)"*2\r\n",4);
redisReaderFeed(reader,(char*)"$5\r\nhello\r\n",11);
redisReaderFeed(reader,(char*)"@foo\r\n",6);
ret = redisReaderGetReply(reader,NULL);
test_cond(ret == REDIS_ERR &&
strcasecmp(reader->errstr,"Protocol error, got \"@\" as reply type byte") == 0);
redisReaderFree(reader);
test("Set error on nested multi bulks with depth > 7: ");
reader = redisReaderCreate();
for (i = 0; i < 9; i++) {
redisReaderFeed(reader,(char*)"*1\r\n",4);
}
ret = redisReaderGetReply(reader,NULL);
test_cond(ret == REDIS_ERR &&
strncasecmp(reader->errstr,"No support for",14) == 0);
redisReaderFree(reader);
test("Works with NULL functions for reply: ");
reader = redisReaderCreate();
reader->fn = NULL;
redisReaderFeed(reader,(char*)"+OK\r\n",5);
ret = redisReaderGetReply(reader,&reply);
test_cond(ret == REDIS_OK && reply == (void*)REDIS_REPLY_STATUS);
redisReaderFree(reader);
test("Works when a single newline (\\r\\n) covers two calls to feed: ");
reader = redisReaderCreate();
reader->fn = NULL;
redisReaderFeed(reader,(char*)"+OK\r",4);
ret = redisReaderGetReply(reader,&reply);
assert(ret == REDIS_OK && reply == NULL);
redisReaderFeed(reader,(char*)"\n",1);
ret = redisReaderGetReply(reader,&reply);
test_cond(ret == REDIS_OK && reply == (void*)REDIS_REPLY_STATUS);
redisReaderFree(reader);
test("Don't reset state after protocol error: ");
reader = redisReaderCreate();
reader->fn = NULL;
redisReaderFeed(reader,(char*)"x",1);
ret = redisReaderGetReply(reader,&reply);
assert(ret == REDIS_ERR);
ret = redisReaderGetReply(reader,&reply);
test_cond(ret == REDIS_ERR && reply == NULL);
redisReaderFree(reader);
/* Regression test for issue #45 on GitHub. */
test("Don't do empty allocation for empty multi bulk: ");
reader = redisReaderCreate();
redisReaderFeed(reader,(char*)"*0\r\n",4);
ret = redisReaderGetReply(reader,&reply);
test_cond(ret == REDIS_OK &&
((redisReply*)reply)->type == REDIS_REPLY_ARRAY &&
((redisReply*)reply)->elements == 0);
freeReplyObject(reply);
redisReaderFree(reader);
}
static void test_blocking_connection_errors(void) {
redisContext *c;
test("Returns error when host cannot be resolved: ");
c = redisConnect((char*)"idontexist.local", 6379);
test_cond(c->err == REDIS_ERR_OTHER &&
(strcmp(c->errstr,"Name or service not known") == 0 ||
strcmp(c->errstr,"Can't resolve: idontexist.local") == 0 ||
strcmp(c->errstr,"nodename nor servname provided, or not known") == 0 ||
strcmp(c->errstr,"No address associated with hostname") == 0 ||
strcmp(c->errstr,"no address associated with name") == 0));
redisFree(c);
test("Returns error when the port is not open: ");
c = redisConnect((char*)"localhost", 1);
test_cond(c->err == REDIS_ERR_IO &&
strcmp(c->errstr,"Connection refused") == 0);
redisFree(c);
test("Returns error when the unix socket path doesn't accept connections: ");
c = redisConnectUnix((char*)"/tmp/idontexist.sock");
test_cond(c->err == REDIS_ERR_IO); /* Don't care about the message... */
redisFree(c);
}
static void test_blocking_connection(struct config config) {
redisContext *c;
redisReply *reply;
c = connect(config);
test("Is able to deliver commands: ");
reply = redisCommand(c,"PING");
test_cond(reply->type == REDIS_REPLY_STATUS &&
strcasecmp(reply->str,"pong") == 0)
freeReplyObject(reply);
test("Is a able to send commands verbatim: ");
reply = redisCommand(c,"SET foo bar");
test_cond (reply->type == REDIS_REPLY_STATUS &&
strcasecmp(reply->str,"ok") == 0)
freeReplyObject(reply);
test("%%s String interpolation works: ");
reply = redisCommand(c,"SET %s %s","foo","hello world");
freeReplyObject(reply);
reply = redisCommand(c,"GET foo");
test_cond(reply->type == REDIS_REPLY_STRING &&
strcmp(reply->str,"hello world") == 0);
freeReplyObject(reply);
test("%%b String interpolation works: ");
reply = redisCommand(c,"SET %b %b","foo",(size_t)3,"hello\x00world",(size_t)11);
freeReplyObject(reply);
reply = redisCommand(c,"GET foo");
test_cond(reply->type == REDIS_REPLY_STRING &&
memcmp(reply->str,"hello\x00world",11) == 0)
test("Binary reply length is correct: ");
test_cond(reply->len == 11)
freeReplyObject(reply);
test("Can parse nil replies: ");
reply = redisCommand(c,"GET nokey");
test_cond(reply->type == REDIS_REPLY_NIL)
freeReplyObject(reply);
/* test 7 */
test("Can parse integer replies: ");
reply = redisCommand(c,"INCR mycounter");
test_cond(reply->type == REDIS_REPLY_INTEGER && reply->integer == 1)
freeReplyObject(reply);
test("Can parse multi bulk replies: ");
freeReplyObject(redisCommand(c,"LPUSH mylist foo"));
freeReplyObject(redisCommand(c,"LPUSH mylist bar"));
reply = redisCommand(c,"LRANGE mylist 0 -1");
test_cond(reply->type == REDIS_REPLY_ARRAY &&
reply->elements == 2 &&
!memcmp(reply->element[0]->str,"bar",3) &&
!memcmp(reply->element[1]->str,"foo",3))
freeReplyObject(reply);
/* m/e with multi bulk reply *before* other reply.
* specifically test ordering of reply items to parse. */
test("Can handle nested multi bulk replies: ");
freeReplyObject(redisCommand(c,"MULTI"));
freeReplyObject(redisCommand(c,"LRANGE mylist 0 -1"));
freeReplyObject(redisCommand(c,"PING"));
reply = (redisCommand(c,"EXEC"));
test_cond(reply->type == REDIS_REPLY_ARRAY &&
reply->elements == 2 &&
reply->element[0]->type == REDIS_REPLY_ARRAY &&
reply->element[0]->elements == 2 &&
!memcmp(reply->element[0]->element[0]->str,"bar",3) &&
!memcmp(reply->element[0]->element[1]->str,"foo",3) &&
reply->element[1]->type == REDIS_REPLY_STATUS &&
strcasecmp(reply->element[1]->str,"pong") == 0);
freeReplyObject(reply);
disconnect(c, 0);
}
static void test_blocking_io_errors(struct config config) {
redisContext *c;
redisReply *reply;
void *_reply;
int major, minor;
/* Connect to target given by config. */
c = connect(config);
{
/* Find out Redis version to determine the path for the next test */
const char *field = "redis_version:";
char *p, *eptr;
reply = redisCommand(c,"INFO");
p = strstr(reply->str,field);
major = strtol(p+strlen(field),&eptr,10);
p = eptr+1; /* char next to the first "." */
minor = strtol(p,&eptr,10);
freeReplyObject(reply);
}
test("Returns I/O error when the connection is lost: ");
reply = redisCommand(c,"QUIT");
if (major >= 2 && minor > 0) {
/* > 2.0 returns OK on QUIT and read() should be issued once more
* to know the descriptor is at EOF. */
test_cond(strcasecmp(reply->str,"OK") == 0 &&
redisGetReply(c,&_reply) == REDIS_ERR);
freeReplyObject(reply);
} else {
test_cond(reply == NULL);
}
/* On 2.0, QUIT will cause the connection to be closed immediately and
* the read(2) for the reply on QUIT will set the error to EOF.
* On >2.0, QUIT will return with OK and another read(2) needed to be
* issued to find out the socket was closed by the server. In both
* conditions, the error will be set to EOF. */
assert(c->err == REDIS_ERR_EOF &&
strcmp(c->errstr,"Server closed the connection") == 0);
redisFree(c);
c = connect(config);
test("Returns I/O error on socket timeout: ");
struct timeval tv = { 0, 1000 };
assert(redisSetTimeout(c,tv) == REDIS_OK);
test_cond(redisGetReply(c,&_reply) == REDIS_ERR &&
c->err == REDIS_ERR_IO && errno == EAGAIN);
redisFree(c);
}
static void test_invalid_timeout_errors(struct config config) {
redisContext *c;
test("Set error when an invalid timeout usec value is given to redisConnectWithTimeout: ");
config.tcp.timeout.tv_sec = 0;
config.tcp.timeout.tv_usec = 10000001;
c = redisConnectWithTimeout(config.tcp.host, config.tcp.port, config.tcp.timeout);
test_cond(c->err == REDIS_ERR_IO);
test("Set error when an invalid timeout sec value is given to redisConnectWithTimeout: ");
config.tcp.timeout.tv_sec = (((LONG_MAX) - 999) / 1000) + 1;
config.tcp.timeout.tv_usec = 0;
c = redisConnectWithTimeout(config.tcp.host, config.tcp.port, config.tcp.timeout);
test_cond(c->err == REDIS_ERR_IO);
redisFree(c);
}
static void test_throughput(struct config config) {
redisContext *c = connect(config);
redisReply **replies;
int i, num;
long long t1, t2;
test("Throughput:\n");
for (i = 0; i < 500; i++)
freeReplyObject(redisCommand(c,"LPUSH mylist foo"));
num = 1000;
replies = malloc(sizeof(redisReply*)*num);
t1 = usec();
for (i = 0; i < num; i++) {
replies[i] = redisCommand(c,"PING");
assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_STATUS);
}
t2 = usec();
for (i = 0; i < num; i++) freeReplyObject(replies[i]);
free(replies);
printf("\t(%dx PING: %.3fs)\n", num, (t2-t1)/1000000.0);
replies = malloc(sizeof(redisReply*)*num);
t1 = usec();
for (i = 0; i < num; i++) {
replies[i] = redisCommand(c,"LRANGE mylist 0 499");
assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_ARRAY);
assert(replies[i] != NULL && replies[i]->elements == 500);
}
t2 = usec();
for (i = 0; i < num; i++) freeReplyObject(replies[i]);
free(replies);
printf("\t(%dx LRANGE with 500 elements: %.3fs)\n", num, (t2-t1)/1000000.0);
num = 10000;
replies = malloc(sizeof(redisReply*)*num);
for (i = 0; i < num; i++)
redisAppendCommand(c,"PING");
t1 = usec();
for (i = 0; i < num; i++) {
assert(redisGetReply(c, (void*)&replies[i]) == REDIS_OK);
assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_STATUS);
}
t2 = usec();
for (i = 0; i < num; i++) freeReplyObject(replies[i]);
free(replies);
printf("\t(%dx PING (pipelined): %.3fs)\n", num, (t2-t1)/1000000.0);
replies = malloc(sizeof(redisReply*)*num);
for (i = 0; i < num; i++)
redisAppendCommand(c,"LRANGE mylist 0 499");
t1 = usec();
for (i = 0; i < num; i++) {
assert(redisGetReply(c, (void*)&replies[i]) == REDIS_OK);
assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_ARRAY);
assert(replies[i] != NULL && replies[i]->elements == 500);
}
t2 = usec();
for (i = 0; i < num; i++) freeReplyObject(replies[i]);
free(replies);
printf("\t(%dx LRANGE with 500 elements (pipelined): %.3fs)\n", num, (t2-t1)/1000000.0);
disconnect(c, 0);
}
// static long __test_callback_flags = 0;
// static void __test_callback(redisContext *c, void *privdata) {
// ((void)c);
// /* Shift to detect execution order */
// __test_callback_flags <<= 8;
// __test_callback_flags |= (long)privdata;
// }
//
// static void __test_reply_callback(redisContext *c, redisReply *reply, void *privdata) {
// ((void)c);
// /* Shift to detect execution order */
// __test_callback_flags <<= 8;
// __test_callback_flags |= (long)privdata;
// if (reply) freeReplyObject(reply);
// }
//
// static redisContext *__connect_nonblock() {
// /* Reset callback flags */
// __test_callback_flags = 0;
// return redisConnectNonBlock("127.0.0.1", port, NULL);
// }
//
// static void test_nonblocking_connection() {
// redisContext *c;
// int wdone = 0;
//
// test("Calls command callback when command is issued: ");
// c = __connect_nonblock();
// redisSetCommandCallback(c,__test_callback,(void*)1);
// redisCommand(c,"PING");
// test_cond(__test_callback_flags == 1);
// redisFree(c);
//
// test("Calls disconnect callback on redisDisconnect: ");
// c = __connect_nonblock();
// redisSetDisconnectCallback(c,__test_callback,(void*)2);
// redisDisconnect(c);
// test_cond(__test_callback_flags == 2);
// redisFree(c);
//
// test("Calls disconnect callback and free callback on redisFree: ");
// c = __connect_nonblock();
// redisSetDisconnectCallback(c,__test_callback,(void*)2);
// redisSetFreeCallback(c,__test_callback,(void*)4);
// redisFree(c);
// test_cond(__test_callback_flags == ((2 << 8) | 4));
//
// test("redisBufferWrite against empty write buffer: ");
// c = __connect_nonblock();
// test_cond(redisBufferWrite(c,&wdone) == REDIS_OK && wdone == 1);
// redisFree(c);
//
// test("redisBufferWrite against not yet connected fd: ");
// c = __connect_nonblock();
// redisCommand(c,"PING");
// test_cond(redisBufferWrite(c,NULL) == REDIS_ERR &&
// strncmp(c->error,"write:",6) == 0);
// redisFree(c);
//
// test("redisBufferWrite against closed fd: ");
// c = __connect_nonblock();
// redisCommand(c,"PING");
// redisDisconnect(c);
// test_cond(redisBufferWrite(c,NULL) == REDIS_ERR &&
// strncmp(c->error,"write:",6) == 0);
// redisFree(c);
//
// test("Process callbacks in the right sequence: ");
// c = __connect_nonblock();
// redisCommandWithCallback(c,__test_reply_callback,(void*)1,"PING");
// redisCommandWithCallback(c,__test_reply_callback,(void*)2,"PING");
// redisCommandWithCallback(c,__test_reply_callback,(void*)3,"PING");
//
// /* Write output buffer */
// wdone = 0;
// while(!wdone) {
// usleep(500);
// redisBufferWrite(c,&wdone);
// }
//
// /* Read until at least one callback is executed (the 3 replies will
// * arrive in a single packet, causing all callbacks to be executed in
// * a single pass). */
// while(__test_callback_flags == 0) {
// assert(redisBufferRead(c) == REDIS_OK);
// redisProcessCallbacks(c);
// }
// test_cond(__test_callback_flags == 0x010203);
// redisFree(c);
//
// test("redisDisconnect executes pending callbacks with NULL reply: ");
// c = __connect_nonblock();
// redisSetDisconnectCallback(c,__test_callback,(void*)1);
// redisCommandWithCallback(c,__test_reply_callback,(void*)2,"PING");
// redisDisconnect(c);
// test_cond(__test_callback_flags == 0x0201);
// redisFree(c);
// }
int main(int argc, char **argv) {
struct config cfg = {
.tcp = {
.host = "127.0.0.1",
.port = 6379
},
.unix = {
.path = "/tmp/redis.sock"
}
};
int throughput = 1;
int test_inherit_fd = 1;
/* Ignore broken pipe signal (for I/O error tests). */
signal(SIGPIPE, SIG_IGN);
/* Parse command line options. */
argv++; argc--;
while (argc) {
if (argc >= 2 && !strcmp(argv[0],"-h")) {
argv++; argc--;
cfg.tcp.host = argv[0];
} else if (argc >= 2 && !strcmp(argv[0],"-p")) {
argv++; argc--;
cfg.tcp.port = atoi(argv[0]);
} else if (argc >= 2 && !strcmp(argv[0],"-s")) {
argv++; argc--;
cfg.unix.path = argv[0];
} else if (argc >= 1 && !strcmp(argv[0],"--skip-throughput")) {
throughput = 0;
} else if (argc >= 1 && !strcmp(argv[0],"--skip-inherit-fd")) {
test_inherit_fd = 0;
} else {
fprintf(stderr, "Invalid argument: %s\n", argv[0]);
exit(1);
}
argv++; argc--;
}
test_format_commands();
test_reply_reader();
test_blocking_connection_errors();
printf("\nTesting against TCP connection (%s:%d):\n", cfg.tcp.host, cfg.tcp.port);
cfg.type = CONN_TCP;
test_blocking_connection(cfg);
test_blocking_io_errors(cfg);
test_invalid_timeout_errors(cfg);
test_append_formatted_commands(cfg);
if (throughput) test_throughput(cfg);
printf("\nTesting against Unix socket connection (%s):\n", cfg.unix.path);
cfg.type = CONN_UNIX;
test_blocking_connection(cfg);
test_blocking_io_errors(cfg);
if (throughput) test_throughput(cfg);
if (test_inherit_fd) {
printf("\nTesting against inherited fd (%s):\n", cfg.unix.path);
cfg.type = CONN_FD;
test_blocking_connection(cfg);
}
if (fails) {
printf("*** %d TESTS FAILED ***\n", fails);
return 1;
}
printf("ALL TESTS PASSED\n");
return 0;
}

View file

@ -0,0 +1,13 @@
/* Drop in replacement for zmalloc.h in order to just use libc malloc without
* any wrappering. */
#ifndef ZMALLOC_H
#define ZMALLOC_H
#define zmalloc malloc
#define zrealloc realloc
#define zcalloc(x) calloc(x,1)
#define zfree free
#define zstrdup strdup
#endif

View file

@ -0,0 +1,72 @@
/*.gcov.*
/autom4te.cache/
/bin/jemalloc.sh
/config.stamp
/config.log
/config.status
/configure
/doc/html.xsl
/doc/manpages.xsl
/doc/jemalloc.xml
/doc/jemalloc.html
/doc/jemalloc.3
/lib/
/Makefile
/include/jemalloc/internal/jemalloc_internal.h
/include/jemalloc/internal/jemalloc_internal_defs.h
/include/jemalloc/internal/private_namespace.h
/include/jemalloc/internal/private_unnamespace.h
/include/jemalloc/internal/public_namespace.h
/include/jemalloc/internal/public_symbols.txt
/include/jemalloc/internal/public_unnamespace.h
/include/jemalloc/internal/size_classes.h
/include/jemalloc/jemalloc.h
/include/jemalloc/jemalloc_defs.h
/include/jemalloc/jemalloc_macros.h
/include/jemalloc/jemalloc_mangle.h
/include/jemalloc/jemalloc_mangle_jet.h
/include/jemalloc/jemalloc_protos.h
/include/jemalloc/jemalloc_protos_jet.h
/include/jemalloc/jemalloc_rename.h
/src/*.[od]
/src/*.gcda
/src/*.gcno
/test/test.sh
test/include/test/jemalloc_test.h
test/include/test/jemalloc_test_defs.h
/test/integration/[A-Za-z]*
!/test/integration/[A-Za-z]*.*
/test/integration/*.[od]
/test/integration/*.gcda
/test/integration/*.gcno
/test/integration/*.out
/test/src/*.[od]
/test/src/*.gcda
/test/src/*.gcno
/test/stress/[A-Za-z]*
!/test/stress/[A-Za-z]*.*
/test/stress/*.[od]
/test/stress/*.gcda
/test/stress/*.gcno
/test/stress/*.out
/test/unit/[A-Za-z]*
!/test/unit/[A-Za-z]*.*
/test/unit/*.[od]
/test/unit/*.gcda
/test/unit/*.gcno
/test/unit/*.out
/VERSION

View file

@ -0,0 +1,27 @@
Unless otherwise specified, files in the jemalloc source distribution are
subject to the following license:
--------------------------------------------------------------------------------
Copyright (C) 2002-2014 Jason Evans <jasone@canonware.com>.
All rights reserved.
Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved.
Copyright (C) 2009-2014 Facebook, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice(s),
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice(s),
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------

View file

@ -0,0 +1,548 @@
Following are change highlights associated with official releases. Important
bug fixes are all mentioned, but internal enhancements are omitted here for
brevity (even though they are more fun to write about). Much more detail can be
found in the git revision history:
https://github.com/jemalloc/jemalloc
* 3.6.0 (March 31, 2014)
This version contains a critical bug fix for a regression present in 3.5.0 and
3.5.1.
Bug fixes:
- Fix a regression in arena_chunk_alloc() that caused crashes during
small/large allocation if chunk allocation failed. In the absence of this
bug, chunk allocation failure would result in allocation failure, e.g. NULL
return from malloc(). This regression was introduced in 3.5.0.
- Fix backtracing for gcc intrinsics-based backtracing by specifying
-fno-omit-frame-pointer to gcc. Note that the application (and all the
libraries it links to) must also be compiled with this option for
backtracing to be reliable.
- Use dss allocation precedence for huge allocations as well as small/large
allocations.
- Fix test assertion failure message formatting. This bug did not manifect on
x86_64 systems because of implementation subtleties in va_list.
- Fix inconsequential test failures for hash and SFMT code.
New features:
- Support heap profiling on FreeBSD. This feature depends on the proc
filesystem being mounted during heap profile dumping.
* 3.5.1 (February 25, 2014)
This version primarily addresses minor bugs in test code.
Bug fixes:
- Configure Solaris/Illumos to use MADV_FREE.
- Fix junk filling for mremap(2)-based huge reallocation. This is only
relevant if configuring with the --enable-mremap option specified.
- Avoid compilation failure if 'restrict' C99 keyword is not supported by the
compiler.
- Add a configure test for SSE2 rather than assuming it is usable on i686
systems. This fixes test compilation errors, especially on 32-bit Linux
systems.
- Fix mallctl argument size mismatches (size_t vs. uint64_t) in the stats unit
test.
- Fix/remove flawed alignment-related overflow tests.
- Prevent compiler optimizations that could change backtraces in the
prof_accum unit test.
* 3.5.0 (January 22, 2014)
This version focuses on refactoring and automated testing, though it also
includes some non-trivial heap profiling optimizations not mentioned below.
New features:
- Add the *allocx() API, which is a successor to the experimental *allocm()
API. The *allocx() functions are slightly simpler to use because they have
fewer parameters, they directly return the results of primary interest, and
mallocx()/rallocx() avoid the strict aliasing pitfall that
allocm()/rallocm() share with posix_memalign(). Note that *allocm() is
slated for removal in the next non-bugfix release.
- Add support for LinuxThreads.
Bug fixes:
- Unless heap profiling is enabled, disable floating point code and don't link
with libm. This, in combination with e.g. EXTRA_CFLAGS=-mno-sse on x64
systems, makes it possible to completely disable floating point register
use. Some versions of glibc neglect to save/restore caller-saved floating
point registers during dynamic lazy symbol loading, and the symbol loading
code uses whatever malloc the application happens to have linked/loaded
with, the result being potential floating point register corruption.
- Report ENOMEM rather than EINVAL if an OOM occurs during heap profiling
backtrace creation in imemalign(). This bug impacted posix_memalign() and
aligned_alloc().
- Fix a file descriptor leak in a prof_dump_maps() error path.
- Fix prof_dump() to close the dump file descriptor for all relevant error
paths.
- Fix rallocm() to use the arena specified by the ALLOCM_ARENA(s) flag for
allocation, not just deallocation.
- Fix a data race for large allocation stats counters.
- Fix a potential infinite loop during thread exit. This bug occurred on
Solaris, and could affect other platforms with similar pthreads TSD
implementations.
- Don't junk-fill reallocations unless usable size changes. This fixes a
violation of the *allocx()/*allocm() semantics.
- Fix growing large reallocation to junk fill new space.
- Fix huge deallocation to junk fill when munmap is disabled.
- Change the default private namespace prefix from empty to je_, and change
--with-private-namespace-prefix so that it prepends an additional prefix
rather than replacing je_. This reduces the likelihood of applications
which statically link jemalloc experiencing symbol name collisions.
- Add missing private namespace mangling (relevant when
--with-private-namespace is specified).
- Add and use JEMALLOC_INLINE_C so that static inline functions are marked as
static even for debug builds.
- Add a missing mutex unlock in a malloc_init_hard() error path. In practice
this error path is never executed.
- Fix numerous bugs in malloc_strotumax() error handling/reporting. These
bugs had no impact except for malformed inputs.
- Fix numerous bugs in malloc_snprintf(). These bugs were not exercised by
existing calls, so they had no impact.
* 3.4.1 (October 20, 2013)
Bug fixes:
- Fix a race in the "arenas.extend" mallctl that could cause memory corruption
of internal data structures and subsequent crashes.
- Fix Valgrind integration flaws that caused Valgrind warnings about reads of
uninitialized memory in:
+ arena chunk headers
+ internal zero-initialized data structures (relevant to tcache and prof
code)
- Preserve errno during the first allocation. A readlink(2) call during
initialization fails unless /etc/malloc.conf exists, so errno was typically
set during the first allocation prior to this fix.
- Fix compilation warnings reported by gcc 4.8.1.
* 3.4.0 (June 2, 2013)
This version is essentially a small bugfix release, but the addition of
aarch64 support requires that the minor version be incremented.
Bug fixes:
- Fix race-triggered deadlocks in chunk_record(). These deadlocks were
typically triggered by multiple threads concurrently deallocating huge
objects.
New features:
- Add support for the aarch64 architecture.
* 3.3.1 (March 6, 2013)
This version fixes bugs that are typically encountered only when utilizing
custom run-time options.
Bug fixes:
- Fix a locking order bug that could cause deadlock during fork if heap
profiling were enabled.
- Fix a chunk recycling bug that could cause the allocator to lose track of
whether a chunk was zeroed. On FreeBSD, NetBSD, and OS X, it could cause
corruption if allocating via sbrk(2) (unlikely unless running with the
"dss:primary" option specified). This was completely harmless on Linux
unless using mlockall(2) (and unlikely even then, unless the
--disable-munmap configure option or the "dss:primary" option was
specified). This regression was introduced in 3.1.0 by the
mlockall(2)/madvise(2) interaction fix.
- Fix TLS-related memory corruption that could occur during thread exit if the
thread never allocated memory. Only the quarantine and prof facilities were
susceptible.
- Fix two quarantine bugs:
+ Internal reallocation of the quarantined object array leaked the old
array.
+ Reallocation failure for internal reallocation of the quarantined object
array (very unlikely) resulted in memory corruption.
- Fix Valgrind integration to annotate all internally allocated memory in a
way that keeps Valgrind happy about internal data structure access.
- Fix building for s390 systems.
* 3.3.0 (January 23, 2013)
This version includes a few minor performance improvements in addition to the
listed new features and bug fixes.
New features:
- Add clipping support to lg_chunk option processing.
- Add the --enable-ivsalloc option.
- Add the --without-export option.
- Add the --disable-zone-allocator option.
Bug fixes:
- Fix "arenas.extend" mallctl to output the number of arenas.
- Fix chunk_recycle() to unconditionally inform Valgrind that returned memory
is undefined.
- Fix build break on FreeBSD related to alloca.h.
* 3.2.0 (November 9, 2012)
In addition to a couple of bug fixes, this version modifies page run
allocation and dirty page purging algorithms in order to better control
page-level virtual memory fragmentation.
Incompatible changes:
- Change the "opt.lg_dirty_mult" default from 5 to 3 (32:1 to 8:1).
Bug fixes:
- Fix dss/mmap allocation precedence code to use recyclable mmap memory only
after primary dss allocation fails.
- Fix deadlock in the "arenas.purge" mallctl. This regression was introduced
in 3.1.0 by the addition of the "arena.<i>.purge" mallctl.
* 3.1.0 (October 16, 2012)
New features:
- Auto-detect whether running inside Valgrind, thus removing the need to
manually specify MALLOC_CONF=valgrind:true.
- Add the "arenas.extend" mallctl, which allows applications to create
manually managed arenas.
- Add the ALLOCM_ARENA() flag for {,r,d}allocm().
- Add the "opt.dss", "arena.<i>.dss", and "stats.arenas.<i>.dss" mallctls,
which provide control over dss/mmap precedence.
- Add the "arena.<i>.purge" mallctl, which obsoletes "arenas.purge".
- Define LG_QUANTUM for hppa.
Incompatible changes:
- Disable tcache by default if running inside Valgrind, in order to avoid
making unallocated objects appear reachable to Valgrind.
- Drop const from malloc_usable_size() argument on Linux.
Bug fixes:
- Fix heap profiling crash if sampled object is freed via realloc(p, 0).
- Remove const from __*_hook variable declarations, so that glibc can modify
them during process forking.
- Fix mlockall(2)/madvise(2) interaction.
- Fix fork(2)-related deadlocks.
- Fix error return value for "thread.tcache.enabled" mallctl.
* 3.0.0 (May 11, 2012)
Although this version adds some major new features, the primary focus is on
internal code cleanup that facilitates maintainability and portability, most
of which is not reflected in the ChangeLog. This is the first release to
incorporate substantial contributions from numerous other developers, and the
result is a more broadly useful allocator (see the git revision history for
contribution details). Note that the license has been unified, thanks to
Facebook granting a license under the same terms as the other copyright
holders (see COPYING).
New features:
- Implement Valgrind support, redzones, and quarantine.
- Add support for additional platforms:
+ FreeBSD
+ Mac OS X Lion
+ MinGW
+ Windows (no support yet for replacing the system malloc)
- Add support for additional architectures:
+ MIPS
+ SH4
+ Tilera
- Add support for cross compiling.
- Add nallocm(), which rounds a request size up to the nearest size class
without actually allocating.
- Implement aligned_alloc() (blame C11).
- Add the "thread.tcache.enabled" mallctl.
- Add the "opt.prof_final" mallctl.
- Update pprof (from gperftools 2.0).
- Add the --with-mangling option.
- Add the --disable-experimental option.
- Add the --disable-munmap option, and make it the default on Linux.
- Add the --enable-mremap option, which disables use of mremap(2) by default.
Incompatible changes:
- Enable stats by default.
- Enable fill by default.
- Disable lazy locking by default.
- Rename the "tcache.flush" mallctl to "thread.tcache.flush".
- Rename the "arenas.pagesize" mallctl to "arenas.page".
- Change the "opt.lg_prof_sample" default from 0 to 19 (1 B to 512 KiB).
- Change the "opt.prof_accum" default from true to false.
Removed features:
- Remove the swap feature, including the "config.swap", "swap.avail",
"swap.prezeroed", "swap.nfds", and "swap.fds" mallctls.
- Remove highruns statistics, including the
"stats.arenas.<i>.bins.<j>.highruns" and
"stats.arenas.<i>.lruns.<j>.highruns" mallctls.
- As part of small size class refactoring, remove the "opt.lg_[qc]space_max",
"arenas.cacheline", "arenas.subpage", "arenas.[tqcs]space_{min,max}", and
"arenas.[tqcs]bins" mallctls.
- Remove the "arenas.chunksize" mallctl.
- Remove the "opt.lg_prof_tcmax" option.
- Remove the "opt.lg_prof_bt_max" option.
- Remove the "opt.lg_tcache_gc_sweep" option.
- Remove the --disable-tiny option, including the "config.tiny" mallctl.
- Remove the --enable-dynamic-page-shift configure option.
- Remove the --enable-sysv configure option.
Bug fixes:
- Fix a statistics-related bug in the "thread.arena" mallctl that could cause
invalid statistics and crashes.
- Work around TLS deallocation via free() on Linux. This bug could cause
write-after-free memory corruption.
- Fix a potential deadlock that could occur during interval- and
growth-triggered heap profile dumps.
- Fix large calloc() zeroing bugs due to dropping chunk map unzeroed flags.
- Fix chunk_alloc_dss() to stop claiming memory is zeroed. This bug could
cause memory corruption and crashes with --enable-dss specified.
- Fix fork-related bugs that could cause deadlock in children between fork
and exec.
- Fix malloc_stats_print() to honor 'b' and 'l' in the opts parameter.
- Fix realloc(p, 0) to act like free(p).
- Do not enforce minimum alignment in memalign().
- Check for NULL pointer in malloc_usable_size().
- Fix an off-by-one heap profile statistics bug that could be observed in
interval- and growth-triggered heap profiles.
- Fix the "epoch" mallctl to update cached stats even if the passed in epoch
is 0.
- Fix bin->runcur management to fix a layout policy bug. This bug did not
affect correctness.
- Fix a bug in choose_arena_hard() that potentially caused more arenas to be
initialized than necessary.
- Add missing "opt.lg_tcache_max" mallctl implementation.
- Use glibc allocator hooks to make mixed allocator usage less likely.
- Fix build issues for --disable-tcache.
- Don't mangle pthread_create() when --with-private-namespace is specified.
* 2.2.5 (November 14, 2011)
Bug fixes:
- Fix huge_ralloc() race when using mremap(2). This is a serious bug that
could cause memory corruption and/or crashes.
- Fix huge_ralloc() to maintain chunk statistics.
- Fix malloc_stats_print(..., "a") output.
* 2.2.4 (November 5, 2011)
Bug fixes:
- Initialize arenas_tsd before using it. This bug existed for 2.2.[0-3], as
well as for --disable-tls builds in earlier releases.
- Do not assume a 4 KiB page size in test/rallocm.c.
* 2.2.3 (August 31, 2011)
This version fixes numerous bugs related to heap profiling.
Bug fixes:
- Fix a prof-related race condition. This bug could cause memory corruption,
but only occurred in non-default configurations (prof_accum:false).
- Fix off-by-one backtracing issues (make sure that prof_alloc_prep() is
excluded from backtraces).
- Fix a prof-related bug in realloc() (only triggered by OOM errors).
- Fix prof-related bugs in allocm() and rallocm().
- Fix prof_tdata_cleanup() for --disable-tls builds.
- Fix a relative include path, to fix objdir builds.
* 2.2.2 (July 30, 2011)
Bug fixes:
- Fix a build error for --disable-tcache.
- Fix assertions in arena_purge() (for real this time).
- Add the --with-private-namespace option. This is a workaround for symbol
conflicts that can inadvertently arise when using static libraries.
* 2.2.1 (March 30, 2011)
Bug fixes:
- Implement atomic operations for x86/x64. This fixes compilation failures
for versions of gcc that are still in wide use.
- Fix an assertion in arena_purge().
* 2.2.0 (March 22, 2011)
This version incorporates several improvements to algorithms and data
structures that tend to reduce fragmentation and increase speed.
New features:
- Add the "stats.cactive" mallctl.
- Update pprof (from google-perftools 1.7).
- Improve backtracing-related configuration logic, and add the
--disable-prof-libgcc option.
Bug fixes:
- Change default symbol visibility from "internal", to "hidden", which
decreases the overhead of library-internal function calls.
- Fix symbol visibility so that it is also set on OS X.
- Fix a build dependency regression caused by the introduction of the .pic.o
suffix for PIC object files.
- Add missing checks for mutex initialization failures.
- Don't use libgcc-based backtracing except on x64, where it is known to work.
- Fix deadlocks on OS X that were due to memory allocation in
pthread_mutex_lock().
- Heap profiling-specific fixes:
+ Fix memory corruption due to integer overflow in small region index
computation, when using a small enough sample interval that profiling
context pointers are stored in small run headers.
+ Fix a bootstrap ordering bug that only occurred with TLS disabled.
+ Fix a rallocm() rsize bug.
+ Fix error detection bugs for aligned memory allocation.
* 2.1.3 (March 14, 2011)
Bug fixes:
- Fix a cpp logic regression (due to the "thread.{de,}allocatedp" mallctl fix
for OS X in 2.1.2).
- Fix a "thread.arena" mallctl bug.
- Fix a thread cache stats merging bug.
* 2.1.2 (March 2, 2011)
Bug fixes:
- Fix "thread.{de,}allocatedp" mallctl for OS X.
- Add missing jemalloc.a to build system.
* 2.1.1 (January 31, 2011)
Bug fixes:
- Fix aligned huge reallocation (affected allocm()).
- Fix the ALLOCM_LG_ALIGN macro definition.
- Fix a heap dumping deadlock.
- Fix a "thread.arena" mallctl bug.
* 2.1.0 (December 3, 2010)
This version incorporates some optimizations that can't quite be considered
bug fixes.
New features:
- Use Linux's mremap(2) for huge object reallocation when possible.
- Avoid locking in mallctl*() when possible.
- Add the "thread.[de]allocatedp" mallctl's.
- Convert the manual page source from roff to DocBook, and generate both roff
and HTML manuals.
Bug fixes:
- Fix a crash due to incorrect bootstrap ordering. This only impacted
--enable-debug --enable-dss configurations.
- Fix a minor statistics bug for mallctl("swap.avail", ...).
* 2.0.1 (October 29, 2010)
Bug fixes:
- Fix a race condition in heap profiling that could cause undefined behavior
if "opt.prof_accum" were disabled.
- Add missing mutex unlocks for some OOM error paths in the heap profiling
code.
- Fix a compilation error for non-C99 builds.
* 2.0.0 (October 24, 2010)
This version focuses on the experimental *allocm() API, and on improved
run-time configuration/introspection. Nonetheless, numerous performance
improvements are also included.
New features:
- Implement the experimental {,r,s,d}allocm() API, which provides a superset
of the functionality available via malloc(), calloc(), posix_memalign(),
realloc(), malloc_usable_size(), and free(). These functions can be used to
allocate/reallocate aligned zeroed memory, ask for optional extra memory
during reallocation, prevent object movement during reallocation, etc.
- Replace JEMALLOC_OPTIONS/JEMALLOC_PROF_PREFIX with MALLOC_CONF, which is
more human-readable, and more flexible. For example:
JEMALLOC_OPTIONS=AJP
is now:
MALLOC_CONF=abort:true,fill:true,stats_print:true
- Port to Apple OS X. Sponsored by Mozilla.
- Make it possible for the application to control thread-->arena mappings via
the "thread.arena" mallctl.
- Add compile-time support for all TLS-related functionality via pthreads TSD.
This is mainly of interest for OS X, which does not support TLS, but has a
TSD implementation with similar performance.
- Override memalign() and valloc() if they are provided by the system.
- Add the "arenas.purge" mallctl, which can be used to synchronously purge all
dirty unused pages.
- Make cumulative heap profiling data optional, so that it is possible to
limit the amount of memory consumed by heap profiling data structures.
- Add per thread allocation counters that can be accessed via the
"thread.allocated" and "thread.deallocated" mallctls.
Incompatible changes:
- Remove JEMALLOC_OPTIONS and malloc_options (see MALLOC_CONF above).
- Increase default backtrace depth from 4 to 128 for heap profiling.
- Disable interval-based profile dumps by default.
Bug fixes:
- Remove bad assertions in fork handler functions. These assertions could
cause aborts for some combinations of configure settings.
- Fix strerror_r() usage to deal with non-standard semantics in GNU libc.
- Fix leak context reporting. This bug tended to cause the number of contexts
to be underreported (though the reported number of objects and bytes were
correct).
- Fix a realloc() bug for large in-place growing reallocation. This bug could
cause memory corruption, but it was hard to trigger.
- Fix an allocation bug for small allocations that could be triggered if
multiple threads raced to create a new run of backing pages.
- Enhance the heap profiler to trigger samples based on usable size, rather
than request size.
- Fix a heap profiling bug due to sometimes losing track of requested object
size for sampled objects.
* 1.0.3 (August 12, 2010)
Bug fixes:
- Fix the libunwind-based implementation of stack backtracing (used for heap
profiling). This bug could cause zero-length backtraces to be reported.
- Add a missing mutex unlock in library initialization code. If multiple
threads raced to initialize malloc, some of them could end up permanently
blocked.
* 1.0.2 (May 11, 2010)
Bug fixes:
- Fix junk filling of large objects, which could cause memory corruption.
- Add MAP_NORESERVE support for chunk mapping, because otherwise virtual
memory limits could cause swap file configuration to fail. Contributed by
Jordan DeLong.
* 1.0.1 (April 14, 2010)
Bug fixes:
- Fix compilation when --enable-fill is specified.
- Fix threads-related profiling bugs that affected accuracy and caused memory
to be leaked during thread exit.
- Fix dirty page purging race conditions that could cause crashes.
- Fix crash in tcache flushing code during thread destruction.
* 1.0.0 (April 11, 2010)
This release focuses on speed and run-time introspection. Numerous
algorithmic improvements make this release substantially faster than its
predecessors.
New features:
- Implement autoconf-based configuration system.
- Add mallctl*(), for the purposes of introspection and run-time
configuration.
- Make it possible for the application to manually flush a thread's cache, via
the "tcache.flush" mallctl.
- Base maximum dirty page count on proportion of active memory.
- Compute various addtional run-time statistics, including per size class
statistics for large objects.
- Expose malloc_stats_print(), which can be called repeatedly by the
application.
- Simplify the malloc_message() signature to only take one string argument,
and incorporate an opaque data pointer argument for use by the application
in combination with malloc_stats_print().
- Add support for allocation backed by one or more swap files, and allow the
application to disable over-commit if swap files are in use.
- Implement allocation profiling and leak checking.
Removed features:
- Remove the dynamic arena rebalancing code, since thread-specific caching
reduces its utility.
Bug fixes:
- Modify chunk allocation to work when address space layout randomization
(ASLR) is in use.
- Fix thread cleanup bugs related to TLS destruction.
- Handle 0-size allocation requests in posix_memalign().
- Fix a chunk leak. The leaked chunks were never touched, so this impacted
virtual memory usage, but not physical memory usage.
* linux_2008082[78]a (August 27/28, 2008)
These snapshot releases are the simple result of incorporating Linux-specific
support into the FreeBSD malloc sources.
--------------------------------------------------------------------------------
vim:filetype=text:textwidth=80

View file

@ -0,0 +1,306 @@
Building and installing jemalloc can be as simple as typing the following while
in the root directory of the source tree:
./configure
make
make install
=== Advanced configuration =====================================================
The 'configure' script supports numerous options that allow control of which
functionality is enabled, where jemalloc is installed, etc. Optionally, pass
any of the following arguments (not a definitive list) to 'configure':
--help
Print a definitive list of options.
--prefix=<install-root-dir>
Set the base directory in which to install. For example:
./configure --prefix=/usr/local
will cause files to be installed into /usr/local/include, /usr/local/lib,
and /usr/local/man.
--with-rpath=<colon-separated-rpath>
Embed one or more library paths, so that libjemalloc can find the libraries
it is linked to. This works only on ELF-based systems.
--with-mangling=<map>
Mangle public symbols specified in <map> which is a comma-separated list of
name:mangled pairs.
For example, to use ld's --wrap option as an alternative method for
overriding libc's malloc implementation, specify something like:
--with-mangling=malloc:__wrap_malloc,free:__wrap_free[...]
Note that mangling happens prior to application of the prefix specified by
--with-jemalloc-prefix, and mangled symbols are then ignored when applying
the prefix.
--with-jemalloc-prefix=<prefix>
Prefix all public APIs with <prefix>. For example, if <prefix> is
"prefix_", API changes like the following occur:
malloc() --> prefix_malloc()
malloc_conf --> prefix_malloc_conf
/etc/malloc.conf --> /etc/prefix_malloc.conf
MALLOC_CONF --> PREFIX_MALLOC_CONF
This makes it possible to use jemalloc at the same time as the system
allocator, or even to use multiple copies of jemalloc simultaneously.
By default, the prefix is "", except on OS X, where it is "je_". On OS X,
jemalloc overlays the default malloc zone, but makes no attempt to actually
replace the "malloc", "calloc", etc. symbols.
--without-export
Don't export public APIs. This can be useful when building jemalloc as a
static library, or to avoid exporting public APIs when using the zone
allocator on OSX.
--with-private-namespace=<prefix>
Prefix all library-private APIs with <prefix>je_. For shared libraries,
symbol visibility mechanisms prevent these symbols from being exported, but
for static libraries, naming collisions are a real possibility. By
default, <prefix> is empty, which results in a symbol prefix of je_ .
--with-install-suffix=<suffix>
Append <suffix> to the base name of all installed files, such that multiple
versions of jemalloc can coexist in the same installation directory. For
example, libjemalloc.so.0 becomes libjemalloc<suffix>.so.0.
--enable-cc-silence
Enable code that silences non-useful compiler warnings. This is helpful
when trying to tell serious warnings from those due to compiler
limitations, but it potentially incurs a performance penalty.
--enable-debug
Enable assertions and validation code. This incurs a substantial
performance hit, but is very useful during application development.
Implies --enable-ivsalloc.
--enable-code-coverage
Enable code coverage support, for use during jemalloc test development.
Additional testing targets are available if this option is enabled:
coverage
coverage_unit
coverage_integration
coverage_stress
These targets do not clear code coverage results from previous runs, and
there are interactions between the various coverage targets, so it is
usually advisable to run 'make clean' between repeated code coverage runs.
--enable-ivsalloc
Enable validation code, which verifies that pointers reside within
jemalloc-owned chunks before dereferencing them. This incurs a substantial
performance hit.
--disable-stats
Disable statistics gathering functionality. See the "opt.stats_print"
option documentation for usage details.
--enable-prof
Enable heap profiling and leak detection functionality. See the "opt.prof"
option documentation for usage details. When enabled, there are several
approaches to backtracing, and the configure script chooses the first one
in the following list that appears to function correctly:
+ libunwind (requires --enable-prof-libunwind)
+ libgcc (unless --disable-prof-libgcc)
+ gcc intrinsics (unless --disable-prof-gcc)
--enable-prof-libunwind
Use the libunwind library (http://www.nongnu.org/libunwind/) for stack
backtracing.
--disable-prof-libgcc
Disable the use of libgcc's backtracing functionality.
--disable-prof-gcc
Disable the use of gcc intrinsics for backtracing.
--with-static-libunwind=<libunwind.a>
Statically link against the specified libunwind.a rather than dynamically
linking with -lunwind.
--disable-tcache
Disable thread-specific caches for small objects. Objects are cached and
released in bulk, thus reducing the total number of mutex operations. See
the "opt.tcache" option for usage details.
--enable-mremap
Enable huge realloc() via mremap(2). mremap() is disabled by default
because the flavor used is specific to Linux, which has a quirk in its
virtual memory allocation algorithm that causes semi-permanent VM map holes
under normal jemalloc operation.
--disable-munmap
Disable virtual memory deallocation via munmap(2); instead keep track of
the virtual memory for later use. munmap() is disabled by default (i.e.
--disable-munmap is implied) on Linux, which has a quirk in its virtual
memory allocation algorithm that causes semi-permanent VM map holes under
normal jemalloc operation.
--enable-dss
Enable support for page allocation/deallocation via sbrk(2), in addition to
mmap(2).
--disable-fill
Disable support for junk/zero filling of memory, quarantine, and redzones.
See the "opt.junk", "opt.zero", "opt.quarantine", and "opt.redzone" option
documentation for usage details.
--disable-valgrind
Disable support for Valgrind.
--disable-experimental
Disable support for the experimental API (*allocm()).
--disable-zone-allocator
Disable zone allocator for Darwin. This means jemalloc won't be hooked as
the default allocator on OSX/iOS.
--enable-utrace
Enable utrace(2)-based allocation tracing. This feature is not broadly
portable (FreeBSD has it, but Linux and OS X do not).
--enable-xmalloc
Enable support for optional immediate termination due to out-of-memory
errors, as is commonly implemented by "xmalloc" wrapper function for malloc.
See the "opt.xmalloc" option documentation for usage details.
--enable-lazy-lock
Enable code that wraps pthread_create() to detect when an application
switches from single-threaded to multi-threaded mode, so that it can avoid
mutex locking/unlocking operations while in single-threaded mode. In
practice, this feature usually has little impact on performance unless
thread-specific caching is disabled.
--disable-tls
Disable thread-local storage (TLS), which allows for fast access to
thread-local variables via the __thread keyword. If TLS is available,
jemalloc uses it for several purposes.
--with-xslroot=<path>
Specify where to find DocBook XSL stylesheets when building the
documentation.
The following environment variables (not a definitive list) impact configure's
behavior:
CFLAGS="?"
Pass these flags to the compiler. You probably shouldn't define this unless
you know what you are doing. (Use EXTRA_CFLAGS instead.)
EXTRA_CFLAGS="?"
Append these flags to CFLAGS. This makes it possible to add flags such as
-Werror, while allowing the configure script to determine what other flags
are appropriate for the specified configuration.
The configure script specifically checks whether an optimization flag (-O*)
is specified in EXTRA_CFLAGS, and refrains from specifying an optimization
level if it finds that one has already been specified.
CPPFLAGS="?"
Pass these flags to the C preprocessor. Note that CFLAGS is not passed to
'cpp' when 'configure' is looking for include files, so you must use
CPPFLAGS instead if you need to help 'configure' find header files.
LD_LIBRARY_PATH="?"
'ld' uses this colon-separated list to find libraries.
LDFLAGS="?"
Pass these flags when linking.
PATH="?"
'configure' uses this to find programs.
=== Advanced compilation =======================================================
To build only parts of jemalloc, use the following targets:
build_lib_shared
build_lib_static
build_lib
build_doc_html
build_doc_man
build_doc
To install only parts of jemalloc, use the following targets:
install_bin
install_include
install_lib_shared
install_lib_static
install_lib
install_doc_html
install_doc_man
install_doc
To clean up build results to varying degrees, use the following make targets:
clean
distclean
relclean
=== Advanced installation ======================================================
Optionally, define make variables when invoking make, including (not
exclusively):
INCLUDEDIR="?"
Use this as the installation prefix for header files.
LIBDIR="?"
Use this as the installation prefix for libraries.
MANDIR="?"
Use this as the installation prefix for man pages.
DESTDIR="?"
Prepend DESTDIR to INCLUDEDIR, LIBDIR, DATADIR, and MANDIR. This is useful
when installing to a different path than was specified via --prefix.
CC="?"
Use this to invoke the C compiler.
CFLAGS="?"
Pass these flags to the compiler.
CPPFLAGS="?"
Pass these flags to the C preprocessor.
LDFLAGS="?"
Pass these flags when linking.
PATH="?"
Use this to search for programs used during configuration and building.
=== Development ================================================================
If you intend to make non-trivial changes to jemalloc, use the 'autogen.sh'
script rather than 'configure'. This re-generates 'configure', enables
configuration dependency rules, and enables re-generation of automatically
generated source files.
The build system supports using an object directory separate from the source
tree. For example, you can create an 'obj' directory, and from within that
directory, issue configuration and build commands:
autoconf
mkdir obj
cd obj
../configure --enable-autogen
make
=== Documentation ==============================================================
The manual page is generated in both html and roff formats. Any web browser
can be used to view the html manual. The roff manual page can be formatted
prior to installation via the following command:
nroff -man -t doc/jemalloc.3

View file

@ -0,0 +1,438 @@
# Clear out all vpaths, then set just one (default vpath) for the main build
# directory.
vpath
vpath % .
# Clear the default suffixes, so that built-in rules are not used.
.SUFFIXES :
SHELL := /bin/sh
CC := @CC@
# Configuration parameters.
DESTDIR =
BINDIR := $(DESTDIR)@BINDIR@
INCLUDEDIR := $(DESTDIR)@INCLUDEDIR@
LIBDIR := $(DESTDIR)@LIBDIR@
DATADIR := $(DESTDIR)@DATADIR@
MANDIR := $(DESTDIR)@MANDIR@
srcroot := @srcroot@
objroot := @objroot@
abs_srcroot := @abs_srcroot@
abs_objroot := @abs_objroot@
# Build parameters.
CPPFLAGS := @CPPFLAGS@ -I$(srcroot)include -I$(objroot)include
CFLAGS := @CFLAGS@
LDFLAGS := @LDFLAGS@
EXTRA_LDFLAGS := @EXTRA_LDFLAGS@
LIBS := @LIBS@
RPATH_EXTRA := @RPATH_EXTRA@
SO := @so@
IMPORTLIB := @importlib@
O := @o@
A := @a@
EXE := @exe@
LIBPREFIX := @libprefix@
REV := @rev@
install_suffix := @install_suffix@
ABI := @abi@
XSLTPROC := @XSLTPROC@
AUTOCONF := @AUTOCONF@
_RPATH = @RPATH@
RPATH = $(if $(1),$(call _RPATH,$(1)))
cfghdrs_in := @cfghdrs_in@
cfghdrs_out := @cfghdrs_out@
cfgoutputs_in := @cfgoutputs_in@
cfgoutputs_out := @cfgoutputs_out@
enable_autogen := @enable_autogen@
enable_code_coverage := @enable_code_coverage@
enable_experimental := @enable_experimental@
enable_zone_allocator := @enable_zone_allocator@
DSO_LDFLAGS = @DSO_LDFLAGS@
SOREV = @SOREV@
PIC_CFLAGS = @PIC_CFLAGS@
CTARGET = @CTARGET@
LDTARGET = @LDTARGET@
MKLIB = @MKLIB@
AR = @AR@
ARFLAGS = @ARFLAGS@
CC_MM = @CC_MM@
ifeq (macho, $(ABI))
TEST_LIBRARY_PATH := DYLD_FALLBACK_LIBRARY_PATH="$(objroot)lib"
else
ifeq (pecoff, $(ABI))
TEST_LIBRARY_PATH := PATH="$(PATH):$(objroot)lib"
else
TEST_LIBRARY_PATH :=
endif
endif
LIBJEMALLOC := $(LIBPREFIX)jemalloc$(install_suffix)
# Lists of files.
BINS := $(srcroot)bin/pprof $(objroot)bin/jemalloc.sh
C_HDRS := $(objroot)include/jemalloc/jemalloc$(install_suffix).h
C_SRCS := $(srcroot)src/jemalloc.c $(srcroot)src/arena.c \
$(srcroot)src/atomic.c $(srcroot)src/base.c $(srcroot)src/bitmap.c \
$(srcroot)src/chunk.c $(srcroot)src/chunk_dss.c \
$(srcroot)src/chunk_mmap.c $(srcroot)src/ckh.c $(srcroot)src/ctl.c \
$(srcroot)src/extent.c $(srcroot)src/hash.c $(srcroot)src/huge.c \
$(srcroot)src/mb.c $(srcroot)src/mutex.c $(srcroot)src/prof.c \
$(srcroot)src/quarantine.c $(srcroot)src/rtree.c $(srcroot)src/stats.c \
$(srcroot)src/tcache.c $(srcroot)src/util.c $(srcroot)src/tsd.c
ifeq ($(enable_zone_allocator), 1)
C_SRCS += $(srcroot)src/zone.c
endif
ifeq ($(IMPORTLIB),$(SO))
STATIC_LIBS := $(objroot)lib/$(LIBJEMALLOC).$(A)
endif
ifdef PIC_CFLAGS
STATIC_LIBS += $(objroot)lib/$(LIBJEMALLOC)_pic.$(A)
else
STATIC_LIBS += $(objroot)lib/$(LIBJEMALLOC)_s.$(A)
endif
DSOS := $(objroot)lib/$(LIBJEMALLOC).$(SOREV)
ifneq ($(SOREV),$(SO))
DSOS += $(objroot)lib/$(LIBJEMALLOC).$(SO)
endif
MAN3 := $(objroot)doc/jemalloc$(install_suffix).3
DOCS_XML := $(objroot)doc/jemalloc$(install_suffix).xml
DOCS_HTML := $(DOCS_XML:$(objroot)%.xml=$(srcroot)%.html)
DOCS_MAN3 := $(DOCS_XML:$(objroot)%.xml=$(srcroot)%.3)
DOCS := $(DOCS_HTML) $(DOCS_MAN3)
C_TESTLIB_SRCS := $(srcroot)test/src/math.c $(srcroot)test/src/mtx.c \
$(srcroot)test/src/SFMT.c $(srcroot)test/src/test.c \
$(srcroot)test/src/thd.c
C_UTIL_INTEGRATION_SRCS := $(srcroot)src/util.c
TESTS_UNIT := $(srcroot)test/unit/bitmap.c \
$(srcroot)test/unit/ckh.c \
$(srcroot)test/unit/hash.c \
$(srcroot)test/unit/junk.c \
$(srcroot)test/unit/mallctl.c \
$(srcroot)test/unit/math.c \
$(srcroot)test/unit/mq.c \
$(srcroot)test/unit/mtx.c \
$(srcroot)test/unit/prof_accum.c \
$(srcroot)test/unit/prof_gdump.c \
$(srcroot)test/unit/prof_idump.c \
$(srcroot)test/unit/ql.c \
$(srcroot)test/unit/qr.c \
$(srcroot)test/unit/quarantine.c \
$(srcroot)test/unit/rb.c \
$(srcroot)test/unit/rtree.c \
$(srcroot)test/unit/SFMT.c \
$(srcroot)test/unit/stats.c \
$(srcroot)test/unit/tsd.c \
$(srcroot)test/unit/util.c \
$(srcroot)test/unit/zero.c
TESTS_UNIT_AUX := $(srcroot)test/unit/prof_accum_a.c \
$(srcroot)test/unit/prof_accum_b.c
TESTS_INTEGRATION := $(srcroot)test/integration/aligned_alloc.c \
$(srcroot)test/integration/allocated.c \
$(srcroot)test/integration/mallocx.c \
$(srcroot)test/integration/mremap.c \
$(srcroot)test/integration/posix_memalign.c \
$(srcroot)test/integration/rallocx.c \
$(srcroot)test/integration/thread_arena.c \
$(srcroot)test/integration/thread_tcache_enabled.c \
$(srcroot)test/integration/xallocx.c
ifeq ($(enable_experimental), 1)
TESTS_INTEGRATION += $(srcroot)test/integration/allocm.c \
$(srcroot)test/integration/MALLOCX_ARENA.c \
$(srcroot)test/integration/rallocm.c
endif
TESTS_STRESS :=
TESTS := $(TESTS_UNIT) $(TESTS_INTEGRATION) $(TESTS_STRESS)
C_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.$(O))
C_PIC_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.pic.$(O))
C_JET_OBJS := $(C_SRCS:$(srcroot)%.c=$(objroot)%.jet.$(O))
C_TESTLIB_UNIT_OBJS := $(C_TESTLIB_SRCS:$(srcroot)%.c=$(objroot)%.unit.$(O))
C_TESTLIB_INTEGRATION_OBJS := $(C_TESTLIB_SRCS:$(srcroot)%.c=$(objroot)%.integration.$(O))
C_UTIL_INTEGRATION_OBJS := $(C_UTIL_INTEGRATION_SRCS:$(srcroot)%.c=$(objroot)%.integration.$(O))
C_TESTLIB_STRESS_OBJS := $(C_TESTLIB_SRCS:$(srcroot)%.c=$(objroot)%.stress.$(O))
C_TESTLIB_OBJS := $(C_TESTLIB_UNIT_OBJS) $(C_TESTLIB_INTEGRATION_OBJS) $(C_UTIL_INTEGRATION_OBJS) $(C_TESTLIB_STRESS_OBJS)
TESTS_UNIT_OBJS := $(TESTS_UNIT:$(srcroot)%.c=$(objroot)%.$(O))
TESTS_UNIT_AUX_OBJS := $(TESTS_UNIT_AUX:$(srcroot)%.c=$(objroot)%.$(O))
TESTS_INTEGRATION_OBJS := $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%.$(O))
TESTS_STRESS_OBJS := $(TESTS_STRESS:$(srcroot)%.c=$(objroot)%.$(O))
TESTS_OBJS := $(TESTS_UNIT_OBJS) $(TESTS_UNIT_AUX_OBJS) $(TESTS_INTEGRATION_OBJS) $(TESTS_STRESS_OBJS)
.PHONY: all dist build_doc_html build_doc_man build_doc
.PHONY: install_bin install_include install_lib
.PHONY: install_doc_html install_doc_man install_doc install
.PHONY: tests check clean distclean relclean
.SECONDARY : $(TESTS_OBJS)
# Default target.
all: build_lib
dist: build_doc
$(srcroot)doc/%.html : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/html.xsl
$(XSLTPROC) -o $@ $(objroot)doc/html.xsl $<
$(srcroot)doc/%.3 : $(objroot)doc/%.xml $(srcroot)doc/stylesheet.xsl $(objroot)doc/manpages.xsl
$(XSLTPROC) -o $@ $(objroot)doc/manpages.xsl $<
build_doc_html: $(DOCS_HTML)
build_doc_man: $(DOCS_MAN3)
build_doc: $(DOCS)
#
# Include generated dependency files.
#
ifdef CC_MM
-include $(C_OBJS:%.$(O)=%.d)
-include $(C_PIC_OBJS:%.$(O)=%.d)
-include $(C_JET_OBJS:%.$(O)=%.d)
-include $(C_TESTLIB_OBJS:%.$(O)=%.d)
-include $(TESTS_OBJS:%.$(O)=%.d)
endif
$(C_OBJS): $(objroot)src/%.$(O): $(srcroot)src/%.c
$(C_PIC_OBJS): $(objroot)src/%.pic.$(O): $(srcroot)src/%.c
$(C_PIC_OBJS): CFLAGS += $(PIC_CFLAGS)
$(C_JET_OBJS): $(objroot)src/%.jet.$(O): $(srcroot)src/%.c
$(C_JET_OBJS): CFLAGS += -DJEMALLOC_JET
$(C_TESTLIB_UNIT_OBJS): $(objroot)test/src/%.unit.$(O): $(srcroot)test/src/%.c
$(C_TESTLIB_UNIT_OBJS): CPPFLAGS += -DJEMALLOC_UNIT_TEST
$(C_TESTLIB_INTEGRATION_OBJS): $(objroot)test/src/%.integration.$(O): $(srcroot)test/src/%.c
$(C_TESTLIB_INTEGRATION_OBJS): CPPFLAGS += -DJEMALLOC_INTEGRATION_TEST
$(C_UTIL_INTEGRATION_OBJS): $(objroot)src/%.integration.$(O): $(srcroot)src/%.c
$(C_TESTLIB_STRESS_OBJS): $(objroot)test/src/%.stress.$(O): $(srcroot)test/src/%.c
$(C_TESTLIB_STRESS_OBJS): CPPFLAGS += -DJEMALLOC_STRESS_TEST -DJEMALLOC_STRESS_TESTLIB
$(C_TESTLIB_OBJS): CPPFLAGS += -I$(srcroot)test/include -I$(objroot)test/include
$(TESTS_UNIT_OBJS): CPPFLAGS += -DJEMALLOC_UNIT_TEST
$(TESTS_UNIT_AUX_OBJS): CPPFLAGS += -DJEMALLOC_UNIT_TEST
define make-unit-link-dep
$(1): TESTS_UNIT_LINK_OBJS += $(2)
$(1): $(2)
endef
$(foreach test, $(TESTS_UNIT:$(srcroot)test/unit/%.c=$(objroot)test/unit/%$(EXE)), $(eval $(call make-unit-link-dep,$(test),$(filter $(test:%=%_a.$(O)) $(test:%=%_b.$(O)),$(TESTS_UNIT_AUX_OBJS)))))
$(TESTS_INTEGRATION_OBJS): CPPFLAGS += -DJEMALLOC_INTEGRATION_TEST
$(TESTS_STRESS_OBJS): CPPFLAGS += -DJEMALLOC_STRESS_TEST
$(TESTS_OBJS): $(objroot)test/%.$(O): $(srcroot)test/%.c
$(TESTS_OBJS): CPPFLAGS += -I$(srcroot)test/include -I$(objroot)test/include
ifneq ($(IMPORTLIB),$(SO))
$(C_OBJS): CPPFLAGS += -DDLLEXPORT
endif
ifndef CC_MM
# Dependencies.
HEADER_DIRS = $(srcroot)include/jemalloc/internal \
$(objroot)include/jemalloc $(objroot)include/jemalloc/internal
HEADERS = $(wildcard $(foreach dir,$(HEADER_DIRS),$(dir)/*.h))
$(C_OBJS) $(C_PIC_OBJS) $(C_JET_OBJS) $(C_TESTLIB_OBJS) $(TESTS_OBJS): $(HEADERS)
$(TESTS_OBJS): $(objroot)test/unit/jemalloc_test.h
endif
$(C_OBJS) $(C_PIC_OBJS) $(C_JET_OBJS) $(C_TESTLIB_OBJS) $(TESTS_OBJS): %.$(O):
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $(CPPFLAGS) $(CTARGET) $<
ifdef CC_MM
@$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $<
endif
ifneq ($(SOREV),$(SO))
%.$(SO) : %.$(SOREV)
@mkdir -p $(@D)
ln -sf $(<F) $@
endif
$(objroot)lib/$(LIBJEMALLOC).$(SOREV) : $(if $(PIC_CFLAGS),$(C_PIC_OBJS),$(C_OBJS))
@mkdir -p $(@D)
$(CC) $(DSO_LDFLAGS) $(call RPATH,$(RPATH_EXTRA)) $(LDTARGET) $+ $(LDFLAGS) $(LIBS) $(EXTRA_LDFLAGS)
$(objroot)lib/$(LIBJEMALLOC)_pic.$(A) : $(C_PIC_OBJS)
$(objroot)lib/$(LIBJEMALLOC).$(A) : $(C_OBJS)
$(objroot)lib/$(LIBJEMALLOC)_s.$(A) : $(C_OBJS)
$(STATIC_LIBS):
@mkdir -p $(@D)
$(AR) $(ARFLAGS)@AROUT@ $+
$(objroot)test/unit/%$(EXE): $(objroot)test/unit/%.$(O) $(TESTS_UNIT_LINK_OBJS) $(C_JET_OBJS) $(C_TESTLIB_UNIT_OBJS)
@mkdir -p $(@D)
$(CC) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(LDFLAGS) $(filter-out -lm,$(LIBS)) -lm $(EXTRA_LDFLAGS)
$(objroot)test/integration/%$(EXE): $(objroot)test/integration/%.$(O) $(C_TESTLIB_INTEGRATION_OBJS) $(C_UTIL_INTEGRATION_OBJS) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB)
@mkdir -p $(@D)
$(CC) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB) $(LDFLAGS) $(filter-out -lm,$(filter -lpthread,$(LIBS))) -lm $(EXTRA_LDFLAGS)
$(objroot)test/stress/%$(EXE): $(objroot)test/stress/%.$(O) $(C_JET_OBJS) $(C_TESTLIB_STRESS_OBJS) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB)
@mkdir -p $(@D)
$(CC) $(LDTARGET) $(filter %.$(O),$^) $(call RPATH,$(objroot)lib) $(objroot)lib/$(LIBJEMALLOC).$(IMPORTLIB) $(LDFLAGS) $(filter-out -lm,$(LIBS)) -lm $(EXTRA_LDFLAGS)
build_lib_shared: $(DSOS)
build_lib_static: $(STATIC_LIBS)
build_lib: build_lib_shared build_lib_static
install_bin:
install -d $(BINDIR)
@for b in $(BINS); do \
echo "install -m 755 $$b $(BINDIR)"; \
install -m 755 $$b $(BINDIR); \
done
install_include:
install -d $(INCLUDEDIR)/jemalloc
@for h in $(C_HDRS); do \
echo "install -m 644 $$h $(INCLUDEDIR)/jemalloc"; \
install -m 644 $$h $(INCLUDEDIR)/jemalloc; \
done
install_lib_shared: $(DSOS)
install -d $(LIBDIR)
install -m 755 $(objroot)lib/$(LIBJEMALLOC).$(SOREV) $(LIBDIR)
ifneq ($(SOREV),$(SO))
ln -sf $(LIBJEMALLOC).$(SOREV) $(LIBDIR)/$(LIBJEMALLOC).$(SO)
endif
install_lib_static: $(STATIC_LIBS)
install -d $(LIBDIR)
@for l in $(STATIC_LIBS); do \
echo "install -m 755 $$l $(LIBDIR)"; \
install -m 755 $$l $(LIBDIR); \
done
install_lib: install_lib_shared install_lib_static
install_doc_html:
install -d $(DATADIR)/doc/jemalloc$(install_suffix)
@for d in $(DOCS_HTML); do \
echo "install -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix)"; \
install -m 644 $$d $(DATADIR)/doc/jemalloc$(install_suffix); \
done
install_doc_man:
install -d $(MANDIR)/man3
@for d in $(DOCS_MAN3); do \
echo "install -m 644 $$d $(MANDIR)/man3"; \
install -m 644 $$d $(MANDIR)/man3; \
done
install_doc: install_doc_html install_doc_man
install: install_bin install_include install_lib install_doc
tests_unit: $(TESTS_UNIT:$(srcroot)%.c=$(objroot)%$(EXE))
tests_integration: $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%$(EXE))
tests_stress: $(TESTS_STRESS:$(srcroot)%.c=$(objroot)%$(EXE))
tests: tests_unit tests_integration tests_stress
check_unit_dir:
@mkdir -p $(objroot)test/unit
check_integration_dir:
@mkdir -p $(objroot)test/integration
check_stress_dir:
@mkdir -p $(objroot)test/stress
check_dir: check_unit_dir check_integration_dir check_stress_dir
check_unit: tests_unit check_unit_dir
$(SHELL) $(objroot)test/test.sh $(TESTS_UNIT:$(srcroot)%.c=$(objroot)%)
check_integration: tests_integration check_integration_dir
$(SHELL) $(objroot)test/test.sh $(TESTS_INTEGRATION:$(srcroot)%.c=$(objroot)%)
check_stress: tests_stress check_stress_dir
$(SHELL) $(objroot)test/test.sh $(TESTS_STRESS:$(srcroot)%.c=$(objroot)%)
check: tests check_dir
$(SHELL) $(objroot)test/test.sh $(TESTS:$(srcroot)%.c=$(objroot)%)
ifeq ($(enable_code_coverage), 1)
coverage_unit: check_unit
$(SHELL) $(srcroot)coverage.sh $(srcroot)src jet $(C_JET_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/src unit $(C_TESTLIB_UNIT_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/unit unit $(TESTS_UNIT_OBJS)
coverage_integration: check_integration
$(SHELL) $(srcroot)coverage.sh $(srcroot)src pic $(C_PIC_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)src integration $(C_UTIL_INTEGRATION_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/src integration $(C_TESTLIB_INTEGRATION_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/integration integration $(TESTS_INTEGRATION_OBJS)
coverage_stress: check_stress
$(SHELL) $(srcroot)coverage.sh $(srcroot)src pic $(C_PIC_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)src jet $(C_JET_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/src stress $(C_TESTLIB_STRESS_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/stress stress $(TESTS_STRESS_OBJS)
coverage: check
$(SHELL) $(srcroot)coverage.sh $(srcroot)src pic $(C_PIC_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)src jet $(C_JET_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)src integration $(C_UTIL_INTEGRATION_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/src unit $(C_TESTLIB_UNIT_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/src integration $(C_TESTLIB_INTEGRATION_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/src stress $(C_TESTLIB_STRESS_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/unit unit $(TESTS_UNIT_OBJS) $(TESTS_UNIT_AUX_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/integration integration $(TESTS_INTEGRATION_OBJS)
$(SHELL) $(srcroot)coverage.sh $(srcroot)test/stress integration $(TESTS_STRESS_OBJS)
endif
clean:
rm -f $(C_OBJS)
rm -f $(C_PIC_OBJS)
rm -f $(C_JET_OBJS)
rm -f $(C_TESTLIB_OBJS)
rm -f $(C_OBJS:%.$(O)=%.d)
rm -f $(C_OBJS:%.$(O)=%.gcda)
rm -f $(C_OBJS:%.$(O)=%.gcno)
rm -f $(C_PIC_OBJS:%.$(O)=%.d)
rm -f $(C_PIC_OBJS:%.$(O)=%.gcda)
rm -f $(C_PIC_OBJS:%.$(O)=%.gcno)
rm -f $(C_JET_OBJS:%.$(O)=%.d)
rm -f $(C_JET_OBJS:%.$(O)=%.gcda)
rm -f $(C_JET_OBJS:%.$(O)=%.gcno)
rm -f $(C_TESTLIB_OBJS:%.$(O)=%.d)
rm -f $(C_TESTLIB_OBJS:%.$(O)=%.gcda)
rm -f $(C_TESTLIB_OBJS:%.$(O)=%.gcno)
rm -f $(TESTS_OBJS:%.$(O)=%$(EXE))
rm -f $(TESTS_OBJS)
rm -f $(TESTS_OBJS:%.$(O)=%.d)
rm -f $(TESTS_OBJS:%.$(O)=%.gcda)
rm -f $(TESTS_OBJS:%.$(O)=%.gcno)
rm -f $(TESTS_OBJS:%.$(O)=%.out)
rm -f $(DSOS) $(STATIC_LIBS)
rm -f $(objroot)*.gcov.*
distclean: clean
rm -rf $(objroot)autom4te.cache
rm -f $(objroot)bin/jemalloc.sh
rm -f $(objroot)config.log
rm -f $(objroot)config.status
rm -f $(objroot)config.stamp
rm -f $(cfghdrs_out)
rm -f $(cfgoutputs_out)
relclean: distclean
rm -f $(objroot)configure
rm -f $(srcroot)VERSION
rm -f $(DOCS_HTML)
rm -f $(DOCS_MAN3)
#===============================================================================
# Re-configuration rules.
ifeq ($(enable_autogen), 1)
$(srcroot)configure : $(srcroot)configure.ac
cd ./$(srcroot) && $(AUTOCONF)
$(objroot)config.status : $(srcroot)configure
./$(objroot)config.status --recheck
$(srcroot)config.stamp.in : $(srcroot)configure.ac
echo stamp > $(srcroot)config.stamp.in
$(objroot)config.stamp : $(cfgoutputs_in) $(cfghdrs_in) $(srcroot)configure
./$(objroot)config.status
@touch $@
# There must be some action in order for make to re-read Makefile when it is
# out of date.
$(cfgoutputs_out) $(cfghdrs_out) : $(objroot)config.stamp
@true
endif

Some files were not shown because too many files have changed in this diff Show more