├── README.md ├── convertDayKline.js ├── convertMinuteKline.js ├── moment.js ├── node_modules ├── .bin │ ├── express │ └── stylus ├── async │ ├── .gitmodules │ ├── .npmignore │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── index.js │ ├── lib │ │ └── async.js │ └── package.json ├── hiredis │ ├── .lock-wscript │ ├── Makefile │ ├── README │ ├── bench.js │ ├── build │ │ ├── .wafpickle-7 │ │ ├── Release │ │ │ ├── hiredis.node │ │ │ ├── hiredis_1.o │ │ │ └── reader_1.o │ │ ├── c4che │ │ │ ├── Release.cache.py │ │ │ └── build.config.py │ │ └── config.log │ ├── deps │ │ └── hiredis │ │ │ ├── CHANGELOG.md │ │ │ ├── COPYING │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── adapters │ │ │ ├── ae.h │ │ │ ├── libev.h │ │ │ └── libevent.h │ │ │ ├── async.c │ │ │ ├── async.h │ │ │ ├── async.o │ │ │ ├── dict.c │ │ │ ├── dict.h │ │ │ ├── example-ae.c │ │ │ ├── example-libev.c │ │ │ ├── example-libevent.c │ │ │ ├── example.c │ │ │ ├── fmacros.h │ │ │ ├── hiredis.c │ │ │ ├── hiredis.h │ │ │ ├── hiredis.o │ │ │ ├── libhiredis.a │ │ │ ├── net.c │ │ │ ├── net.h │ │ │ ├── net.o │ │ │ ├── sds.c │ │ │ ├── sds.h │ │ │ ├── sds.o │ │ │ └── test.c │ ├── hiredis.cc │ ├── hiredis.js │ ├── package.json │ ├── parser_bench.js │ ├── reader.cc │ ├── reader.h │ ├── test │ │ └── reader.js │ └── wscript ├── redis │ ├── .npmignore │ ├── README.md │ ├── benches │ │ ├── buffer_bench.js │ │ ├── hiredis_parser.js │ │ ├── re_sub_test.js │ │ ├── reconnect_test.js │ │ ├── stress │ │ │ ├── codec.js │ │ │ ├── pubsub │ │ │ │ ├── pub.js │ │ │ │ ├── run │ │ │ │ └── server.js │ │ │ ├── rpushblpop │ │ │ │ ├── pub.js │ │ │ │ ├── run │ │ │ │ └── server.js │ │ │ └── speed │ │ │ │ ├── 00 │ │ │ │ ├── plot │ │ │ │ ├── size-rate.png │ │ │ │ └── speed.js │ │ └── sub_quit_test.js │ ├── changelog.md │ ├── diff_multi_bench_output.js │ ├── examples │ │ ├── auth.js │ │ ├── backpressure_drain.js │ │ ├── eval.js │ │ ├── extend.js │ │ ├── file.js │ │ ├── mget.js │ │ ├── monitor.js │ │ ├── multi.js │ │ ├── multi2.js │ │ ├── psubscribe.js │ │ ├── pub_sub.js │ │ ├── simple.js │ │ ├── sort.js │ │ ├── subqueries.js │ │ ├── subquery.js │ │ ├── unix_socket.js │ │ └── web_server.js │ ├── generate_commands.js │ ├── index.js │ ├── lib │ │ ├── commands.js │ │ ├── parser │ │ │ ├── hiredis.js │ │ │ └── javascript.js │ │ ├── queue.js │ │ ├── to_array.js │ │ └── util.js │ ├── multi_bench.js │ ├── package.json │ ├── test.js │ └── test3.js └── underscore │ ├── .npmignore │ ├── CNAME │ ├── LICENSE │ ├── README.md │ ├── favicon.ico │ ├── index.html │ ├── index.js │ ├── package.json │ ├── raw │ └── underscore.psd │ ├── underscore-min.js │ └── underscore.js ├── package.json ├── tdxKLine.js ├── test.js └── unpacker.js /README.md: -------------------------------------------------------------------------------- 1 | tdx_fetchKlineData 2 | ================== 3 | 4 | 根据通达信的盘后数据,转换成分钟K线 日K 周K 月K 半年K 年K 季K -------------------------------------------------------------------------------- /convertDayKline.js: -------------------------------------------------------------------------------- 1 | var worker = require('./tdxKLine'); 2 | worker.startDayMission(); -------------------------------------------------------------------------------- /convertMinuteKline.js: -------------------------------------------------------------------------------- 1 | var worker = require('./tdxKLine'); 2 | worker.startMission(); -------------------------------------------------------------------------------- /moment.js: -------------------------------------------------------------------------------- 1 | // moment.js 2 | // version : 1.7.2 3 | // author : Tim Wood 4 | // license : MIT 5 | // momentjs.com 6 | (function(a){function E(a,b,c,d){var e=c.lang();return e[a].call?e[a](c,d):e[a][b]}function F(a,b){return function(c){return K(a.call(this,c),b)}}function G(a){return function(b){var c=a.call(this,b);return c+this.lang().ordinal(c)}}function H(a,b,c){this._d=a,this._isUTC=!!b,this._a=a._a||null,this._lang=c||!1}function I(a){var b=this._data={},c=a.years||a.y||0,d=a.months||a.M||0,e=a.weeks||a.w||0,f=a.days||a.d||0,g=a.hours||a.h||0,h=a.minutes||a.m||0,i=a.seconds||a.s||0,j=a.milliseconds||a.ms||0;this._milliseconds=j+i*1e3+h*6e4+g*36e5,this._days=f+e*7,this._months=d+c*12,b.milliseconds=j%1e3,i+=J(j/1e3),b.seconds=i%60,h+=J(i/60),b.minutes=h%60,g+=J(h/60),b.hours=g%24,f+=J(g/24),f+=e*7,b.days=f%30,d+=J(f/30),b.months=d%12,c+=J(d/12),b.years=c,this._lang=!1}function J(a){return a<0?Math.ceil(a):Math.floor(a)}function K(a,b){var c=a+"";while(c.length70?1900:2e3);break;case"YYYY":c[0]=~~Math.abs(b);break;case"a":case"A":d.isPm=(b+"").toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":c[3]=~~b;break;case"m":case"mm":c[4]=~~b;break;case"s":case"ss":c[5]=~~b;break;case"S":case"SS":case"SSS":c[6]=~~(("0."+b)*1e3);break;case"Z":case"ZZ":d.isUTC=!0,e=(b+"").match(x),e&&e[1]&&(d.tzh=~~e[1]),e&&e[2]&&(d.tzm=~~e[2]),e&&e[0]==="+"&&(d.tzh=-d.tzh,d.tzm=-d.tzm)}b==null&&(c[8]=!1)}function W(a,b){var c=[0,0,1,0,0,0,0],d={tzh:0,tzm:0},e=b.match(k),f,g;for(f=0;f0,j[4]=c,Z.apply({},j)}function _(a,c){b.fn[a]=function(a){var b=this._isUTC?"UTC":"";return a!=null?(this._d["set"+b+c](a),this):this._d["get"+b+c]()}}function ab(a){b.duration.fn[a]=function(){return this._data[a]}}function bb(a,c){b.duration.fn["as"+a]=function(){return+this/c}}var b,c="1.7.2",d=Math.round,e,f={},g="en",h=typeof module!="undefined"&&module.exports,i="months|monthsShort|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal|meridiem".split("|"),j=/^\/?Date\((\-?\d+)/i,k=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?|.)/g,l=/(\[[^\[]*\])|(\\)?(LT|LL?L?L?)/g,m=/([0-9a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)/gi,n=/\d\d?/,o=/\d{1,3}/,p=/\d{3}/,q=/\d{1,4}/,r=/[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/i,s=/Z|[\+\-]\d\d:?\d\d/i,t=/T/i,u=/^\s*\d{4}-\d\d-\d\d(T(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/,v="YYYY-MM-DDTHH:mm:ssZ",w=[["HH:mm:ss.S",/T\d\d:\d\d:\d\d\.\d{1,3}/],["HH:mm:ss",/T\d\d:\d\d:\d\d/],["HH:mm",/T\d\d:\d\d/],["HH",/T\d\d/]],x=/([\+\-]|\d\d)/gi,y="Month|Date|Hours|Minutes|Seconds|Milliseconds".split("|"),z={Milliseconds:1,Seconds:1e3,Minutes:6e4,Hours:36e5,Days:864e5,Months:2592e6,Years:31536e6},A={},B="DDD w M D d".split(" "),C="M D H h m s w".split(" "),D={M:function(){return this.month()+1},MMM:function(a){return E("monthsShort",this.month(),this,a)},MMMM:function(a){return E("months",this.month(),this,a)},D:function(){return this.date()},DDD:function(){var a=new Date(this.year(),this.month(),this.date()),b=new Date(this.year(),0,1);return~~((a-b)/864e5+1.5)},d:function(){return this.day()},dd:function(a){return E("weekdaysMin",this.day(),this,a)},ddd:function(a){return E("weekdaysShort",this.day(),this,a)},dddd:function(a){return E("weekdays",this.day(),this,a)},w:function(){var a=new Date(this.year(),this.month(),this.date()-this.day()+5),b=new Date(a.getFullYear(),0,4);return~~((a-b)/864e5/7+1.5)},YY:function(){return K(this.year()%100,2)},YYYY:function(){return K(this.year(),4)},a:function(){return this.lang().meridiem(this.hours(),this.minutes(),!0)},A:function(){return this.lang().meridiem(this.hours(),this.minutes(),!1)},H:function(){return this.hours()},h:function(){return this.hours()%12||12},m:function(){return this.minutes()},s:function(){return this.seconds()},S:function(){return~~(this.milliseconds()/100)},SS:function(){return K(~~(this.milliseconds()/10),2)},SSS:function(){return K(this.milliseconds(),3)},Z:function(){var a=-this.zone(),b="+";return a<0&&(a=-a,b="-"),b+K(~~(a/60),2)+":"+K(~~a%60,2)},ZZ:function(){var a=-this.zone(),b="+";return a<0&&(a=-a,b="-"),b+K(~~(10*a/6),4)}};while(B.length)e=B.pop(),D[e+"o"]=G(D[e]);while(C.length)e=C.pop(),D[e+e]=F(D[e],2);D.DDDD=F(D.DDD,3),b=function(c,d){if(c===null||c==="")return null;var e,f;return b.isMoment(c)?new H(new Date(+c._d),c._isUTC,c._lang):(d?M(d)?e=X(c,d):e=W(c,d):(f=j.exec(c),e=c===a?new Date:f?new Date(+f[1]):c instanceof Date?c:M(c)?O(c):typeof c=="string"?Y(c):new Date(c)),new H(e))},b.utc=function(a,c){return M(a)?new H(O(a,!0),!0):(typeof a=="string"&&!s.exec(a)&&(a+=" +0000",c&&(c+=" Z")),b(a,c).utc())},b.unix=function(a){return b(a*1e3)},b.duration=function(a,c){var d=b.isDuration(a),e=typeof a=="number",f=d?a._data:e?{}:a,g;return e&&(c?f[c]=a:f.milliseconds=a),g=new I(f),d&&(g._lang=a._lang),g},b.humanizeDuration=function(a,c,d){return b.duration(a,c===!0?null:c).humanize(c===!0?!0:d)},b.version=c,b.defaultFormat=v,b.lang=function(a,c){var d;if(!a)return g;(c||!f[a])&&P(a,c);if(f[a]){for(d=0;d11?c?"pm":"PM":c?"am":"AM"},calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[last] dddd [at] LT",sameElse:"L"},relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},ordinal:function(a){var b=a%10;return~~(a%100/10)===1?"th":b===1?"st":b===2?"nd":b===3?"rd":"th"}}),b.fn=H.prototype={clone:function(){return b(this)},valueOf:function(){return+this._d},unix:function(){return Math.floor(+this._d/1e3)},toString:function(){return this._d.toString()},toDate:function(){return this._d},toArray:function(){var a=this;return[a.year(),a.month(),a.date(),a.hours(),a.minutes(),a.seconds(),a.milliseconds(),!!this._isUTC]},isValid:function(){return this._a?this._a[8]!=null?!!this._a[8]:!N(this._a,(this._a[7]?b.utc(this._a):b(this._a)).toArray()):!isNaN(this._d.getTime())},utc:function(){return this._isUTC=!0,this},local:function(){return this._isUTC=!1,this},format:function(a){return T(this,a?a:b.defaultFormat)},add:function(a,c){var d=c?b.duration(+c,a):b.duration(a);return L(this,d,1),this},subtract:function(a,c){var d=c?b.duration(+c,a):b.duration(a);return L(this,d,-1),this},diff:function(a,c,e){var f=this._isUTC?b(a).utc():b(a).local(),g=(this.zone()-f.zone())*6e4,h=this._d-f._d-g,i=this.year()-f.year(),j=this.month()-f.month(),k=this.date()-f.date(),l;return c==="months"?l=i*12+j+k/30:c==="years"?l=i+(j+k/30)/12:l=c==="seconds"?h/1e3:c==="minutes"?h/6e4:c==="hours"?h/36e5:c==="days"?h/864e5:c==="weeks"?h/6048e5:h,e?l:d(l)},from:function(a,c){return b.duration(this.diff(a)).lang(this._lang).humanize(!c)},fromNow:function(a){return this.from(b(),a)},calendar:function(){var a=this.diff(b().sod(),"days",!0),c=this.lang().calendar,d=c.sameElse,e=a<-6?d:a<-1?c.lastWeek:a<0?c.lastDay:a<1?c.sameDay:a<2?c.nextDay:a<7?c.nextWeek:d;return this.format(typeof e=="function"?e.apply(this):e)},isLeapYear:function(){var a=this.year();return a%4===0&&a%100!==0||a%400===0},isDST:function(){return this.zone()', 'add stylesheet support (less|stylus) (defaults to plain css)') 24 | .option('-f, --force', 'force on non-empty directory') 25 | .parse(process.argv); 26 | 27 | // Path 28 | 29 | var path = program.args.shift() || '.'; 30 | 31 | // end-of-line code 32 | 33 | var eol = 'win32' == os.platform() ? '\r\n' : '\n' 34 | 35 | // Template engine 36 | 37 | program.template = 'jade'; 38 | if (program.ejs) program.template = 'ejs'; 39 | if (program.jshtml) program.template = 'jshtml'; 40 | if (program.hogan) program.template = 'hjs'; 41 | 42 | /** 43 | * Routes index template. 44 | */ 45 | 46 | var index = [ 47 | '' 48 | , '/*' 49 | , ' * GET home page.' 50 | , ' */' 51 | , '' 52 | , 'exports.index = function(req, res){' 53 | , ' res.render(\'index\', { title: \'Express\' });' 54 | , '};' 55 | ].join(eol); 56 | 57 | /** 58 | * Routes users template. 59 | */ 60 | 61 | var users = [ 62 | '' 63 | , '/*' 64 | , ' * GET users listing.' 65 | , ' */' 66 | , '' 67 | , 'exports.list = function(req, res){' 68 | , ' res.send("respond with a resource");' 69 | , '};' 70 | ].join(eol); 71 | 72 | /** 73 | * Jade layout template. 74 | */ 75 | 76 | var jadeLayout = [ 77 | 'doctype 5' 78 | , 'html' 79 | , ' head' 80 | , ' title= title' 81 | , ' link(rel=\'stylesheet\', href=\'/stylesheets/style.css\')' 82 | , ' body' 83 | , ' block content' 84 | ].join(eol); 85 | 86 | /** 87 | * Jade index template. 88 | */ 89 | 90 | var jadeIndex = [ 91 | 'extends layout' 92 | , '' 93 | , 'block content' 94 | , ' h1= title' 95 | , ' p Welcome to #{title}' 96 | ].join(eol); 97 | 98 | /** 99 | * EJS index template. 100 | */ 101 | 102 | var ejsIndex = [ 103 | '' 104 | , '' 105 | , ' ' 106 | , ' <%= title %>' 107 | , ' ' 108 | , ' ' 109 | , ' ' 110 | , '

<%= title %>

' 111 | , '

Welcome to <%= title %>

' 112 | , ' ' 113 | , '' 114 | ].join(eol); 115 | 116 | /** 117 | * JSHTML layout template. 118 | */ 119 | 120 | var jshtmlLayout = [ 121 | '' 122 | , '' 123 | , ' ' 124 | , ' @write(title) ' 125 | , ' ' 126 | , ' ' 127 | , ' ' 128 | , ' @write(body)' 129 | , ' ' 130 | , '' 131 | ].join(eol); 132 | 133 | /** 134 | * JSHTML index template. 135 | */ 136 | 137 | var jshtmlIndex = [ 138 | '

@write(title)

' 139 | , '

Welcome to @write(title)

' 140 | ].join(eol); 141 | 142 | /** 143 | * Hogan.js index template. 144 | */ 145 | var hoganIndex = [ 146 | '' 147 | , '' 148 | , ' ' 149 | , ' {{ title }}' 150 | , ' ' 151 | , ' ' 152 | , ' ' 153 | , '

{{ title }}

' 154 | , '

Welcome to {{ title }}

' 155 | , ' ' 156 | , '' 157 | ].join(eol); 158 | 159 | /** 160 | * Default css template. 161 | */ 162 | 163 | var css = [ 164 | 'body {' 165 | , ' padding: 50px;' 166 | , ' font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;' 167 | , '}' 168 | , '' 169 | , 'a {' 170 | , ' color: #00B7FF;' 171 | , '}' 172 | ].join(eol); 173 | 174 | /** 175 | * Default less template. 176 | */ 177 | 178 | var less = [ 179 | 'body {' 180 | , ' padding: 50px;' 181 | , ' font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;' 182 | , '}' 183 | , '' 184 | , 'a {' 185 | , ' color: #00B7FF;' 186 | , '}' 187 | ].join(eol); 188 | 189 | /** 190 | * Default stylus template. 191 | */ 192 | 193 | var stylus = [ 194 | 'body' 195 | , ' padding: 50px' 196 | , ' font: 14px "Lucida Grande", Helvetica, Arial, sans-serif' 197 | , 'a' 198 | , ' color: #00B7FF' 199 | ].join(eol); 200 | 201 | /** 202 | * App template. 203 | */ 204 | 205 | var app = [ 206 | '' 207 | , '/**' 208 | , ' * Module dependencies.' 209 | , ' */' 210 | , '' 211 | , 'var express = require(\'express\')' 212 | , ' , routes = require(\'./routes\')' 213 | , ' , user = require(\'./routes/user\')' 214 | , ' , http = require(\'http\')' 215 | , ' , path = require(\'path\');' 216 | , '' 217 | , 'var app = express();' 218 | , '' 219 | , 'app.configure(function(){' 220 | , ' app.set(\'port\', process.env.PORT || 3000);' 221 | , ' app.set(\'views\', __dirname + \'/views\');' 222 | , ' app.set(\'view engine\', \':TEMPLATE\');' 223 | , ' app.use(express.favicon());' 224 | , ' app.use(express.logger(\'dev\'));' 225 | , ' app.use(express.bodyParser());' 226 | , ' app.use(express.methodOverride());{sess}' 227 | , ' app.use(app.router);{css}' 228 | , ' app.use(express.static(path.join(__dirname, \'public\')));' 229 | , '});' 230 | , '' 231 | , 'app.configure(\'development\', function(){' 232 | , ' app.use(express.errorHandler());' 233 | , '});' 234 | , '' 235 | , 'app.get(\'/\', routes.index);' 236 | , 'app.get(\'/users\', user.list);' 237 | , '' 238 | , 'http.createServer(app).listen(app.get(\'port\'), function(){' 239 | , ' console.log("Express server listening on port " + app.get(\'port\'));' 240 | , '});' 241 | , '' 242 | ].join(eol); 243 | 244 | // Generate application 245 | 246 | (function createApplication(path) { 247 | emptyDirectory(path, function(empty){ 248 | if (empty || program.force) { 249 | createApplicationAt(path); 250 | } else { 251 | program.confirm('destination is not empty, continue? ', function(ok){ 252 | if (ok) { 253 | process.stdin.destroy(); 254 | createApplicationAt(path); 255 | } else { 256 | abort('aborting'); 257 | } 258 | }); 259 | } 260 | }); 261 | })(path); 262 | 263 | /** 264 | * Create application at the given directory `path`. 265 | * 266 | * @param {String} path 267 | */ 268 | 269 | function createApplicationAt(path) { 270 | console.log(); 271 | process.on('exit', function(){ 272 | console.log(); 273 | console.log(' install dependencies:'); 274 | console.log(' $ cd %s && npm install', path); 275 | console.log(); 276 | console.log(' run the app:'); 277 | console.log(' $ node app'); 278 | console.log(); 279 | }); 280 | 281 | mkdir(path, function(){ 282 | mkdir(path + '/public'); 283 | mkdir(path + '/public/javascripts'); 284 | mkdir(path + '/public/images'); 285 | mkdir(path + '/public/stylesheets', function(){ 286 | switch (program.css) { 287 | case 'less': 288 | write(path + '/public/stylesheets/style.less', less); 289 | break; 290 | case 'stylus': 291 | write(path + '/public/stylesheets/style.styl', stylus); 292 | break; 293 | default: 294 | write(path + '/public/stylesheets/style.css', css); 295 | } 296 | }); 297 | 298 | mkdir(path + '/routes', function(){ 299 | write(path + '/routes/index.js', index); 300 | write(path + '/routes/user.js', users); 301 | }); 302 | 303 | mkdir(path + '/views', function(){ 304 | switch (program.template) { 305 | case 'ejs': 306 | write(path + '/views/index.ejs', ejsIndex); 307 | break; 308 | case 'jade': 309 | write(path + '/views/layout.jade', jadeLayout); 310 | write(path + '/views/index.jade', jadeIndex); 311 | break; 312 | case 'jshtml': 313 | write(path + '/views/layout.jshtml', jshtmlLayout); 314 | write(path + '/views/index.jshtml', jshtmlIndex); 315 | break; 316 | case 'hjs': 317 | write(path + '/views/index.hjs', hoganIndex); 318 | break; 319 | 320 | } 321 | }); 322 | 323 | // CSS Engine support 324 | switch (program.css) { 325 | case 'less': 326 | app = app.replace('{css}', eol + ' app.use(require(\'less-middleware\')({ src: __dirname + \'/public\' }));'); 327 | break; 328 | case 'stylus': 329 | app = app.replace('{css}', eol + ' app.use(require(\'stylus\').middleware(__dirname + \'/public\'));'); 330 | break; 331 | default: 332 | app = app.replace('{css}', ''); 333 | } 334 | 335 | // Session support 336 | app = app.replace('{sess}', program.sessions 337 | ? eol + ' app.use(express.cookieParser(\'your secret here\'));' + eol + ' app.use(express.session());' 338 | : ''); 339 | 340 | // Template support 341 | app = app.replace(':TEMPLATE', program.template); 342 | 343 | // package.json 344 | var pkg = { 345 | name: 'application-name' 346 | , version: '0.0.1' 347 | , private: true 348 | , scripts: { start: 'node app' } 349 | , dependencies: { 350 | express: version 351 | } 352 | } 353 | 354 | if (program.template) pkg.dependencies[program.template] = '*'; 355 | 356 | // CSS Engine support 357 | switch (program.css) { 358 | case 'less': 359 | pkg.dependencies['less-middleware'] = '*'; 360 | break; 361 | default: 362 | if (program.css) { 363 | pkg.dependencies[program.css] = '*'; 364 | } 365 | } 366 | 367 | write(path + '/package.json', JSON.stringify(pkg, null, 2)); 368 | write(path + '/app.js', app); 369 | }); 370 | } 371 | 372 | /** 373 | * Check if the given directory `path` is empty. 374 | * 375 | * @param {String} path 376 | * @param {Function} fn 377 | */ 378 | 379 | function emptyDirectory(path, fn) { 380 | fs.readdir(path, function(err, files){ 381 | if (err && 'ENOENT' != err.code) throw err; 382 | fn(!files || !files.length); 383 | }); 384 | } 385 | 386 | /** 387 | * echo str > path. 388 | * 389 | * @param {String} path 390 | * @param {String} str 391 | */ 392 | 393 | function write(path, str) { 394 | fs.writeFile(path, str); 395 | console.log(' \x1b[36mcreate\x1b[0m : ' + path); 396 | } 397 | 398 | /** 399 | * Mkdir -p. 400 | * 401 | * @param {String} path 402 | * @param {Function} fn 403 | */ 404 | 405 | function mkdir(path, fn) { 406 | mkdirp(path, 0755, function(err){ 407 | if (err) throw err; 408 | console.log(' \033[36mcreate\033[0m : ' + path); 409 | fn && fn(); 410 | }); 411 | } 412 | 413 | /** 414 | * Exit with the given `str`. 415 | * 416 | * @param {String} str 417 | */ 418 | 419 | function abort(str) { 420 | console.error(str); 421 | process.exit(1); 422 | } 423 | -------------------------------------------------------------------------------- /node_modules/async/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/nodeunit"] 2 | path = deps/nodeunit 3 | url = git://github.com/caolan/nodeunit.git 4 | [submodule "deps/UglifyJS"] 5 | path = deps/UglifyJS 6 | url = https://github.com/mishoo/UglifyJS.git 7 | [submodule "deps/nodelint"] 8 | path = deps/nodelint 9 | url = https://github.com/tav/nodelint.git 10 | -------------------------------------------------------------------------------- /node_modules/async/.npmignore: -------------------------------------------------------------------------------- 1 | deps 2 | dist 3 | test 4 | nodelint.cfg -------------------------------------------------------------------------------- /node_modules/async/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Caolan McMahon 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /node_modules/async/Makefile: -------------------------------------------------------------------------------- 1 | PACKAGE = asyncjs 2 | NODEJS = $(if $(shell test -f /usr/bin/nodejs && echo "true"),nodejs,node) 3 | CWD := $(shell pwd) 4 | NODEUNIT = $(CWD)/node_modules/nodeunit/bin/nodeunit 5 | UGLIFY = $(CWD)/node_modules/uglify-js/bin/uglifyjs 6 | NODELINT = $(CWD)/node_modules/nodelint/nodelint 7 | 8 | BUILDDIR = dist 9 | 10 | all: clean test build 11 | 12 | build: $(wildcard lib/*.js) 13 | mkdir -p $(BUILDDIR) 14 | $(UGLIFY) lib/async.js > $(BUILDDIR)/async.min.js 15 | 16 | test: 17 | $(NODEUNIT) test 18 | 19 | clean: 20 | rm -rf $(BUILDDIR) 21 | 22 | lint: 23 | $(NODELINT) --config nodelint.cfg lib/async.js 24 | 25 | .PHONY: test build all 26 | -------------------------------------------------------------------------------- /node_modules/async/index.js: -------------------------------------------------------------------------------- 1 | // This file is just added for convenience so this repository can be 2 | // directly checked out into a project's deps folder 3 | module.exports = require('./lib/async'); 4 | -------------------------------------------------------------------------------- /node_modules/hiredis/.lock-wscript: -------------------------------------------------------------------------------- 1 | argv = ['/usr/local/bin/node-waf', 'configure', 'build'] 2 | blddir = '/opt/node-pro/webApp/node_modules/hiredis/build' 3 | commands = {'dist': 0, 'configure': True, 'distcheck': 0, 'install': 0, 'build': True, 'clean': 0, 'distclean': 0, 'check': 0, 'uninstall': 0} 4 | cwd = '/opt/node-pro/webApp/node_modules/hiredis' 5 | environ = {'npm_config_git': 'git', 'npm_config_color': 'true', 'npm_config_engine_strict': '', 'npm_config_searchopts': '', 'npm_config_save_bundle': '', 'npm_config_group': '500', 'npm_package_homepage': 'http://github.com/pietern/hiredis-node', 'npm_config_browser': 'google-chrome', 'npm_config_global': '', 'HOME': '/home/tomcat', 'npm_config_production': '', 'npm_config_save_optional': '', 'LANG': 'en_US.UTF-8', 'SHELL': '/bin/bash', 'npm_config_save': '', 'G_BROKEN_FILENAMES': '1', 'npm_config_registry': 'https://registry.npmjs.org/', 'npm_config_unicode': 'true', 'HISTSIZE': '1000', 'npm_config_pre': '', 'npm_config_message': '%s', 'npm_config_always_auth': '', 'npm_config_prefix': '/usr/local', 'LOGNAME': 'tomcat', 'npm_config_searchexclude': '', 'MFLAGS': '', 'npm_config_tmp': '/home/tomcat/tmp', 'npm_package_engines_node': '*', 'npm_config_argv': '{"remain":["hiredis","redis"],"cooked":["install","hiredis","redis"],"original":["install","hiredis","redis"]}', 'npm_config_cache_lock_wait': '10000', 'npm_config_cache_lock_retries': '10', 'npm_package_scripts_test': 'node test/reader.js', 'npm_package_scripts_preinstall': 'make || gmake', 'npm_config_strict_ssl': 'true', 'npm_config_fetch_retry_factor': '10', 'SELINUX_ROLE_REQUESTED': '', 'npm_config_save_dev': '', 'npm_package_main': 'hiredis', 'npm_config_init_version': '0.0.0', 'npm_config_user_agent': 'npm/1.1.46 node/v0.8.14', 'npm_lifecycle_event': 'preinstall', 'npm_config_rollback': 'true', 'npm_config_init_author_name': '', 'npm_config_loglevel': 'http', 'npm_config_username': '', 'HOSTNAME': 'test-appserver-203', 'npm_config_globalignorefile': '/usr/local/etc/npmignore', 'SELINUX_LEVEL_REQUESTED': '', 'MAKELEVEL': '1', 'npm_config_yes': '', 'SELINUX_USE_CURRENT_RANGE': '', 'npm_config_usage': '', 'npm_package_description': 'Wrapper for reply processing code in hiredis', 'npm_config_shell': '/bin/bash', 'npm_config_force': '', 'MAIL': '/var/spool/mail/tomcat', 'SSH_CONNECTION': '172.16.33.254 64996 172.16.33.138 22', 'npm_config_ignore': '', 'npm_config_user': '', 'npm_config_link': '', 'npm_config_ca': '"-----BEGIN CERTIFICATE-----\\nMIIChzCCAfACCQDauvz/KHp8ejANBgkqhkiG9w0BAQUFADCBhzELMAkGA1UEBhMC\\nVVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMQwwCgYDVQQKEwNucG0x\\nIjAgBgNVBAsTGW5wbSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxDjAMBgNVBAMTBW5w\\nbUNBMRcwFQYJKoZIhvcNAQkBFghpQGl6cy5tZTAeFw0xMTA5MDUwMTQ3MTdaFw0y\\nMTA5MDIwMTQ3MTdaMIGHMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNV\\nBAcTB09ha2xhbmQxDDAKBgNVBAoTA25wbTEiMCAGA1UECxMZbnBtIENlcnRpZmlj\\nYXRlIEF1dGhvcml0eTEOMAwGA1UEAxMFbnBtQ0ExFzAVBgkqhkiG9w0BCQEWCGlA\\naXpzLm1lMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLI4tIqPpRW+ACw9GE\\nOgBlJZwK5f8nnKCLK629Pv5yJpQKs3DENExAyOgDcyaF0HD0zk8zTp+ZsLaNdKOz\\nGn2U181KGprGKAXP6DU6ByOJDWmTlY6+Ad1laYT0m64fERSpHw/hjD3D+iX4aMOl\\ny0HdbT5m1ZGh6SJz3ZqxavhHLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAC4ySDbC\\nl7W1WpLmtLGEQ/yuMLUf6Jy/vr+CRp4h+UzL+IQpCv8FfxsYE7dhf/bmWTEupBkv\\nyNL18lipt2jSvR3v6oAHAReotvdjqhxddpe5Holns6EQd1/xEZ7sB1YhQKJtvUrl\\nZNufy1Jf1r0ldEGeA+0ISck7s+xSh9rQD2Op\\n-----END CERTIFICATE-----"', 'npm_config_globalconfig': '/usr/local/etc/npmrc', 'npm_package_name': 'hiredis', 'npm_config_userconfig': '/home/tomcat/.npmrc', 'npm_config_parseable': '', 'npm_config_dev': '', 'LESSOPEN': '|/usr/bin/lesspipe.sh %s', 'npm_config_rebuild_bundle': 'true', 'npm_config_userignorefile': '/home/tomcat/.npmignore', 'SSH_TTY': '/dev/pts/3', 'USER': 'tomcat', 'PATH': '/usr/local/lib/node_modules/npm/bin/node-gyp-bin:/opt/node-pro/webApp/node_modules/hiredis/node_modules/.bin:/opt/node-pro/webApp/node_modules/.bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/tomcat/bin:/opt/redis/bin:/opt/node-pro/mongodb-linux-x86_64-2.2.1/bin', 'npm_package_author_name': 'Pieter Noordhuis', 'MAKEFLAGS': '', 'npm_package_directories_lib': '.', 'HISTCONTROL': 'ignoredups', 'npm_config_proprietary_attribs': 'true', 'npm_config_versions': '', 'npm_config_node_version': '0.8.14', 'npm_config_onload_script': '', 'SHLVL': '2', 'npm_config_description': 'true', 'npm_config_cache_lock_stale': '60000', 'npm_config_sign_git_tag': '', 'npm_config_init_author_url': '', 'npm_config_fetch_retry_maxtimeout': '60000', 'npm_config_cache_max': 'null', 'npm_config_cache': '/home/tomcat/.npm', 'npm_config_coverage': '', 'npm_config_fetch_retry_mintimeout': '10000', 'SSH_CLIENT': '172.16.33.254 64996 22', 'npm_config_viewer': 'man', 'npm_config_proxy': '', 'npm_config_fetch_retries': '2', 'npm_config_unsafe_perm': 'true', 'npm_config_depth': 'null', 'npm_config_umask': '022', 'TERM': 'vt100', 'npm_config_long': '', 'npm_config_editor': 'vi', 'npm_package_version': '0.1.14', 'npm_config_https_proxy': '', '_': '/usr/bin/make', 'npm_config_init_author_email': '', 'npm_config_npat': '', 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:', 'npm_package_readme': 'ERROR: No README.md file found!', 'npm_config_init_module': '/home/tomcat/.npm-init.js', 'npm_config_version': '', 'npm_config_json': '', 'npm_config_searchsort': 'name', 'npm_package_author_email': 'pcnoordhuis@gmail.com', 'npm_lifecycle_script': 'make || gmake', 'PWD': '/opt/node-pro/webApp/node_modules/hiredis', 'npm_config_cache_min': '', 'npm_config_tag': 'latest', 'npm_config_npaturl': 'http://npat.npmjs.org/'} 6 | files = [] 7 | hash = 0 8 | options = {'compile_targets': None, 'force': False, 'verbose': 0, 'nocache': False, 'progress_bar': 0, 'destdir': '', 'keep': False, 'zones': '', 'blddir': '', 'prefix': '/usr/local/', 'jobs': 4, 'srcdir': '', 'check_cxx_compiler': 'g++ icpc sunc++'} 9 | srcdir = '/opt/node-pro/webApp/node_modules/hiredis' 10 | -------------------------------------------------------------------------------- /node_modules/hiredis/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cd deps/hiredis && $(MAKE) static 3 | node-waf configure build 4 | 5 | clean: 6 | cd deps/hiredis && $(MAKE) clean 7 | rm -rf build 8 | 9 | temp: 10 | rm -rf tmp/hiredis 11 | mkdir -p tmp/hiredis 12 | cp -r README *.{cc,h,js*} wscript Makefile deps test tmp/hiredis 13 | cd tmp/hiredis && rm -rf deps/*/.git* deps/*/*.o deps/hiredis/libhiredis.* 14 | 15 | package: temp 16 | cd tmp && tar -czvf hiredis.tgz hiredis 17 | -------------------------------------------------------------------------------- /node_modules/hiredis/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/hiredis/README -------------------------------------------------------------------------------- /node_modules/hiredis/bench.js: -------------------------------------------------------------------------------- 1 | var hiredis = require("./hiredis"), 2 | num_clients = 10, 3 | active_clients = 0, 4 | pipeline = 0, 5 | num_requests = parseInt(process.argv[2]) || 20000, 6 | issued_requests = 0, 7 | test_start; 8 | 9 | var tests = []; 10 | tests.push({ 11 | descr: "PING", 12 | command: ["PING"] 13 | }); 14 | tests.push({ 15 | descr: "SET", 16 | command: ["SET", "foo", "bar"] 17 | }); 18 | tests.push({ 19 | descr: "GET", 20 | command: ["GET", "foo"] 21 | }); 22 | tests.push({ 23 | descr: "LPUSH 8 bytes", 24 | command: ["LPUSH", "mylist-8", new Buffer(Array(8).join("-"))] 25 | }); 26 | tests.push({ 27 | descr: "LPUSH 64 bytes", 28 | command: ["LPUSH", "mylist-64", new Buffer(Array(64).join("-"))] 29 | }); 30 | tests.push({ 31 | descr: "LPUSH 512 bytes", 32 | command: ["LPUSH", "mylist-512", new Buffer(Array(512).join("-"))] 33 | }); 34 | tests.push({ 35 | descr: "LRANGE 10 elements, 8 bytes", 36 | command: ["LRANGE", "mylist-8", "0", "9"] 37 | }); 38 | tests.push({ 39 | descr: "LRANGE 100 elements, 8 bytes", 40 | command: ["LRANGE", "mylist-8", "0", "99"] 41 | }); 42 | tests.push({ 43 | descr: "LRANGE 100 elements, 64 bytes", 44 | command: ["LRANGE", "mylist-64", "0", "99"] 45 | }); 46 | tests.push({ 47 | descr: "LRANGE 100 elements, 512 bytes", 48 | command: ["LRANGE", "mylist-512", "0", "99"] 49 | }); 50 | 51 | function call(client, test) { 52 | client.on("reply", function() { 53 | if (issued_requests < num_requests) { 54 | request(); 55 | } else { 56 | client.end(); 57 | if (--active_clients == 0) 58 | done(test); 59 | } 60 | }); 61 | 62 | function request() { 63 | issued_requests++; 64 | client.write.apply(client,test.command); 65 | }; 66 | 67 | request(); 68 | } 69 | 70 | function done(test) { 71 | var time = (new Date - test_start); 72 | var op_rate = (num_requests/(time/1000.0)).toFixed(2); 73 | console.log(test.descr + ": " + op_rate + " ops/sec"); 74 | next(); 75 | } 76 | 77 | function concurrent_test(test) { 78 | var i = num_clients; 79 | var client; 80 | 81 | issued_requests = 0; 82 | test_start = new Date; 83 | while(i-- && issued_requests < num_requests) { 84 | active_clients++; 85 | client = hiredis.createConnection(); 86 | call(client, test); 87 | } 88 | } 89 | 90 | function pipelined_test(test) { 91 | var client = hiredis.createConnection(); 92 | var received_replies = 0; 93 | 94 | issued_requests = 0; 95 | while (issued_requests < num_requests) { 96 | issued_requests++; 97 | client.write.apply(client,test.command); 98 | } 99 | 100 | test_start = new Date; 101 | client.on("reply", function() { 102 | if (++received_replies == num_requests) { 103 | client.end(); 104 | done(test); 105 | } 106 | }); 107 | } 108 | 109 | function next() { 110 | var test = tests.shift(); 111 | if (test) { 112 | if (pipeline) { 113 | pipelined_test(test); 114 | } else { 115 | concurrent_test(test); 116 | } 117 | } 118 | } 119 | 120 | next(); 121 | 122 | -------------------------------------------------------------------------------- /node_modules/hiredis/build/.wafpickle-7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/hiredis/build/.wafpickle-7 -------------------------------------------------------------------------------- /node_modules/hiredis/build/Release/hiredis.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/hiredis/build/Release/hiredis.node -------------------------------------------------------------------------------- /node_modules/hiredis/build/Release/hiredis_1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/hiredis/build/Release/hiredis_1.o -------------------------------------------------------------------------------- /node_modules/hiredis/build/Release/reader_1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/hiredis/build/Release/reader_1.o -------------------------------------------------------------------------------- /node_modules/hiredis/build/c4che/Release.cache.py: -------------------------------------------------------------------------------- 1 | AR = '/usr/bin/ar' 2 | ARFLAGS = 'rcs' 3 | CCFLAGS = ['-g'] 4 | CCFLAGS_MACBUNDLE = ['-fPIC'] 5 | CCFLAGS_NODE = ['-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] 6 | CC_VERSION = ('4', '4', '6') 7 | COMPILER_CXX = 'g++' 8 | CPP = '/usr/bin/cpp' 9 | CPPFLAGS_NODE = ['-D_GNU_SOURCE'] 10 | CPPPATH_NODE = '/usr/local/include/node' 11 | CPPPATH_ST = '-I%s' 12 | CXX = ['/usr/bin/g++'] 13 | CXXDEFINES_ST = '-D%s' 14 | CXXFLAGS = ['-g', '-Wall', '-O3'] 15 | CXXFLAGS_DEBUG = ['-g'] 16 | CXXFLAGS_NODE = ['-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] 17 | CXXFLAGS_RELEASE = ['-O2'] 18 | CXXLNK_SRC_F = '' 19 | CXXLNK_TGT_F = ['-o', ''] 20 | CXX_NAME = 'gcc' 21 | CXX_SRC_F = '' 22 | CXX_TGT_F = ['-c', '-o', ''] 23 | DEST_BINFMT = 'elf' 24 | DEST_CPU = 'x86_64' 25 | DEST_OS = 'linux' 26 | FULLSTATIC_MARKER = '-static' 27 | LIBDIR = '/home/tomcat/.node_libraries' 28 | LIBPATH_HIREDIS = '../deps/hiredis' 29 | LIBPATH_NODE = '/usr/local/lib' 30 | LIBPATH_ST = '-L%s' 31 | LIB_HIREDIS = 'hiredis' 32 | LIB_ST = '-l%s' 33 | LINKFLAGS_MACBUNDLE = ['-bundle', '-undefined', 'dynamic_lookup'] 34 | LINK_CXX = ['/usr/bin/g++'] 35 | NODE_PATH = '/home/tomcat/.node_libraries' 36 | PREFIX = '/usr/local' 37 | PREFIX_NODE = '/usr/local' 38 | RANLIB = '/usr/bin/ranlib' 39 | RPATH_ST = '-Wl,-rpath,%s' 40 | SHLIB_MARKER = '-Wl,-Bdynamic' 41 | SONAME_ST = '-Wl,-h,%s' 42 | STATICLIBPATH_ST = '-L%s' 43 | STATICLIB_MARKER = '-Wl,-Bstatic' 44 | STATICLIB_ST = '-l%s' 45 | macbundle_PATTERN = '%s.bundle' 46 | program_PATTERN = '%s' 47 | shlib_CXXFLAGS = ['-fPIC', '-DPIC'] 48 | shlib_LINKFLAGS = ['-shared'] 49 | shlib_PATTERN = 'lib%s.so' 50 | staticlib_LINKFLAGS = ['-Wl,-Bstatic'] 51 | staticlib_PATTERN = 'lib%s.a' 52 | -------------------------------------------------------------------------------- /node_modules/hiredis/build/c4che/build.config.py: -------------------------------------------------------------------------------- 1 | version = 0x105016 2 | tools = [{'tool': 'ar', 'tooldir': None, 'funs': None}, {'tool': 'cxx', 'tooldir': None, 'funs': None}, {'tool': 'gxx', 'tooldir': None, 'funs': None}, {'tool': 'compiler_cxx', 'tooldir': None, 'funs': None}, {'tool': 'node_addon', 'tooldir': None, 'funs': None}] 3 | -------------------------------------------------------------------------------- /node_modules/hiredis/build/config.log: -------------------------------------------------------------------------------- 1 | # project noname (1.0) configured on Tue Nov 6 15:00:56 2012 by 2 | # waf 1.5.16 (abi 7, python 20606f0 on linux2) 3 | # using /usr/local/bin/node-waf configure build 4 | # 5 | 6 | ---------------------------------------- 7 | Setting srcdir to 8 | /opt/node-pro/webApp/node_modules/hiredis 9 | 10 | ---------------------------------------- 11 | Setting blddir to 12 | /opt/node-pro/webApp/node_modules/hiredis/build 13 | 14 | ---------------------------------------- 15 | Checking for program g++ or c++ 16 | find program=['g++', 'c++'] paths=[] var='CXX' 17 | -> '/usr/bin/g++' 18 | 19 | ---------------------------------------- 20 | Checking for program cpp 21 | find program=['cpp'] paths=[] var='CPP' 22 | -> '/usr/bin/cpp' 23 | 24 | ---------------------------------------- 25 | Checking for program ar 26 | find program=['ar'] paths=[] var='AR' 27 | -> '/usr/bin/ar' 28 | 29 | ---------------------------------------- 30 | Checking for program ranlib 31 | find program=['ranlib'] paths=[] var='RANLIB' 32 | -> '/usr/bin/ranlib' 33 | 34 | ---------------------------------------- 35 | Checking for g++ 36 | ok 37 | 38 | ---------------------------------------- 39 | Checking for node path 40 | not found 41 | 42 | ---------------------------------------- 43 | Checking for node prefix 44 | ok /usr/local 45 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### 0.10.1 2 | 3 | * Makefile overhaul. Important to check out if you override one or more 4 | variables using environment variables or via arguments to the "make" tool. 5 | 6 | * Issue #45: Fix potential memory leak for a multi bulk reply with 0 elements 7 | being created by the default reply object functions. 8 | 9 | * Issue #43: Don't crash in an asynchronous context when Redis returns an error 10 | reply after the connection has been made (this happens when the maximum 11 | number of connections is reached). 12 | 13 | ### 0.10.0 14 | 15 | * See commit log. 16 | 17 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2011, Salvatore Sanfilippo 2 | Copyright (c) 2010-2011, Pieter Noordhuis 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Redis nor the names of its contributors may be used 17 | to endorse or promote products derived from this software without specific 18 | prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/Makefile: -------------------------------------------------------------------------------- 1 | # Hiredis Makefile 2 | # Copyright (C) 2010-2011 Salvatore Sanfilippo 3 | # Copyright (C) 2010-2011 Pieter Noordhuis 4 | # This file is released under the BSD license, see the COPYING file 5 | 6 | OBJ=net.o hiredis.o sds.o async.o 7 | BINS=hiredis-example hiredis-test 8 | LIBNAME=libhiredis 9 | 10 | HIREDIS_MAJOR=0 11 | HIREDIS_MINOR=10 12 | 13 | # Fallback to gcc when $CC is not in $PATH. 14 | CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc') 15 | OPTIMIZATION?=-O3 16 | WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings 17 | DEBUG?= -g -ggdb 18 | REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG) 19 | REAL_LDFLAGS=$(LDFLAGS) 20 | 21 | DYLIBSUFFIX=so 22 | STLIBSUFFIX=a 23 | DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR).$(HIREDIS_MINOR) 24 | DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR) 25 | DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX) 26 | DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS) 27 | STLIBNAME=$(LIBNAME).$(STLIBSUFFIX) 28 | STLIB_MAKE_CMD=ar rcs $(STLIBNAME) 29 | 30 | # Platform-specific overrides 31 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') 32 | ifeq ($(uname_S),SunOS) 33 | REAL_LDFLAGS+= -ldl -lnsl -lsocket 34 | DYLIB_MAKE_CMD=$(CC) -G -o $(DYLIBNAME) -h $(DYLIB_MINOR_NAME) $(LDFLAGS) 35 | INSTALL= cp -r 36 | endif 37 | ifeq ($(uname_S),Darwin) 38 | DYLIBSUFFIX=dylib 39 | DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(DYLIBSUFFIX) 40 | DYLIB_MAJOR_NAME=$(LIBNAME).$(HIREDIS_MAJOR).$(DYLIBSUFFIX) 41 | DYLIB_MAKE_CMD=$(CC) -shared -Wl,-install_name,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS) 42 | endif 43 | 44 | all: $(DYLIBNAME) $(BINS) 45 | 46 | # Deps (use make dep to generate this) 47 | net.o: net.c fmacros.h net.h hiredis.h 48 | async.o: async.c async.h hiredis.h sds.h dict.c dict.h 49 | example.o: example.c hiredis.h 50 | hiredis.o: hiredis.c fmacros.h hiredis.h net.h sds.h 51 | sds.o: sds.c sds.h 52 | test.o: test.c hiredis.h 53 | 54 | $(DYLIBNAME): $(OBJ) 55 | $(DYLIB_MAKE_CMD) $(OBJ) 56 | 57 | $(STLIBNAME): $(OBJ) 58 | $(STLIB_MAKE_CMD) $(OBJ) 59 | 60 | dynamic: $(DYLIBNAME) 61 | static: $(STLIBNAME) 62 | 63 | # Binaries: 64 | hiredis-example-libevent: example-libevent.c adapters/libevent.h $(STLIBNAME) 65 | $(CC) -o $@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -levent example-libevent.c $(STLIBNAME) 66 | 67 | hiredis-example-libev: example-libev.c adapters/libev.h $(STLIBNAME) 68 | $(CC) -o $@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -lev example-libev.c $(STLIBNAME) 69 | 70 | ifndef AE_DIR 71 | hiredis-example-ae: 72 | @echo "Please specify AE_DIR (e.g. /src)" 73 | @false 74 | else 75 | hiredis-example-ae: example-ae.c adapters/ae.h $(STLIBNAME) 76 | $(CC) -o $@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I$(AE_DIR) $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o example-ae.c $(STLIBNAME) 77 | endif 78 | 79 | hiredis-%: %.o $(STLIBNAME) 80 | $(CC) -o $@ $(REAL_LDFLAGS) $< $(STLIBNAME) 81 | 82 | test: hiredis-test 83 | ./hiredis-test 84 | 85 | check: hiredis-test 86 | echo \ 87 | "daemonize yes\n" \ 88 | "pidfile /tmp/hiredis-test-redis.pid\n" \ 89 | "port 56379\n" \ 90 | "bind 127.0.0.1\n" \ 91 | "unixsocket /tmp/hiredis-test-redis.sock" \ 92 | | redis-server - 93 | ./hiredis-test -h 127.0.0.1 -p 56379 -s /tmp/hiredis-test-redis.sock || \ 94 | ( kill `cat /tmp/hiredis-test-redis.pid` && false ) 95 | kill `cat /tmp/hiredis-test-redis.pid` 96 | 97 | .c.o: 98 | $(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $< 99 | 100 | clean: 101 | rm -rf $(DYLIBNAME) $(STLIBNAME) $(BINS) hiredis-example* *.o *.gcda *.gcno *.gcov 102 | 103 | dep: 104 | $(CC) -MM *.c 105 | 106 | # Installation related variables and target 107 | PREFIX?=/usr/local 108 | INCLUDE_PATH?=include/hiredis 109 | LIBRARY_PATH?=lib 110 | INSTALL_INCLUDE_PATH= $(PREFIX)/$(INCLUDE_PATH) 111 | INSTALL_LIBRARY_PATH= $(PREFIX)/$(LIBRARY_PATH) 112 | 113 | ifeq ($(uname_S),SunOS) 114 | INSTALL?= cp -r 115 | endif 116 | 117 | INSTALL?= cp -a 118 | 119 | install: $(DYLIBNAME) $(STLIBNAME) 120 | mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH) 121 | $(INSTALL) hiredis.h async.h adapters $(INSTALL_INCLUDE_PATH) 122 | $(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME) 123 | cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIB_MAJOR_NAME) 124 | cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MAJOR_NAME) $(DYLIBNAME) 125 | $(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH) 126 | 127 | 32bit: 128 | @echo "" 129 | @echo "WARNING: if this fails under Linux you probably need to install libc6-dev-i386" 130 | @echo "" 131 | $(MAKE) CFLAGS="-m32" LDFLAGS="-m32" 132 | 133 | gprof: 134 | $(MAKE) CFLAGS="-pg" LDFLAGS="-pg" 135 | 136 | gcov: 137 | $(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs" 138 | 139 | coverage: gcov 140 | make check 141 | mkdir -p tmp/lcov 142 | lcov -d . -c -o tmp/lcov/hiredis.info 143 | genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info 144 | 145 | noopt: 146 | $(MAKE) OPTIMIZATION="" 147 | 148 | .PHONY: all test check clean dep install 32bit gprof gcov noopt 149 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/adapters/ae.h: -------------------------------------------------------------------------------- 1 | #ifndef __HIREDIS_AE_H__ 2 | #define __HIREDIS_AE_H__ 3 | #include 4 | #include 5 | #include "../hiredis.h" 6 | #include "../async.h" 7 | 8 | typedef struct redisAeEvents { 9 | redisAsyncContext *context; 10 | aeEventLoop *loop; 11 | int fd; 12 | int reading, writing; 13 | } redisAeEvents; 14 | 15 | static void redisAeReadEvent(aeEventLoop *el, int fd, void *privdata, int mask) { 16 | ((void)el); ((void)fd); ((void)mask); 17 | 18 | redisAeEvents *e = (redisAeEvents*)privdata; 19 | redisAsyncHandleRead(e->context); 20 | } 21 | 22 | static void redisAeWriteEvent(aeEventLoop *el, int fd, void *privdata, int mask) { 23 | ((void)el); ((void)fd); ((void)mask); 24 | 25 | redisAeEvents *e = (redisAeEvents*)privdata; 26 | redisAsyncHandleWrite(e->context); 27 | } 28 | 29 | static void redisAeAddRead(void *privdata) { 30 | redisAeEvents *e = (redisAeEvents*)privdata; 31 | aeEventLoop *loop = e->loop; 32 | if (!e->reading) { 33 | e->reading = 1; 34 | aeCreateFileEvent(loop,e->fd,AE_READABLE,redisAeReadEvent,e); 35 | } 36 | } 37 | 38 | static void redisAeDelRead(void *privdata) { 39 | redisAeEvents *e = (redisAeEvents*)privdata; 40 | aeEventLoop *loop = e->loop; 41 | if (e->reading) { 42 | e->reading = 0; 43 | aeDeleteFileEvent(loop,e->fd,AE_READABLE); 44 | } 45 | } 46 | 47 | static void redisAeAddWrite(void *privdata) { 48 | redisAeEvents *e = (redisAeEvents*)privdata; 49 | aeEventLoop *loop = e->loop; 50 | if (!e->writing) { 51 | e->writing = 1; 52 | aeCreateFileEvent(loop,e->fd,AE_WRITABLE,redisAeWriteEvent,e); 53 | } 54 | } 55 | 56 | static void redisAeDelWrite(void *privdata) { 57 | redisAeEvents *e = (redisAeEvents*)privdata; 58 | aeEventLoop *loop = e->loop; 59 | if (e->writing) { 60 | e->writing = 0; 61 | aeDeleteFileEvent(loop,e->fd,AE_WRITABLE); 62 | } 63 | } 64 | 65 | static void redisAeCleanup(void *privdata) { 66 | redisAeEvents *e = (redisAeEvents*)privdata; 67 | redisAeDelRead(privdata); 68 | redisAeDelWrite(privdata); 69 | free(e); 70 | } 71 | 72 | static int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) { 73 | redisContext *c = &(ac->c); 74 | redisAeEvents *e; 75 | 76 | /* Nothing should be attached when something is already attached */ 77 | if (ac->ev.data != NULL) 78 | return REDIS_ERR; 79 | 80 | /* Create container for context and r/w events */ 81 | e = (redisAeEvents*)malloc(sizeof(*e)); 82 | e->context = ac; 83 | e->loop = loop; 84 | e->fd = c->fd; 85 | e->reading = e->writing = 0; 86 | 87 | /* Register functions to start/stop listening for events */ 88 | ac->ev.addRead = redisAeAddRead; 89 | ac->ev.delRead = redisAeDelRead; 90 | ac->ev.addWrite = redisAeAddWrite; 91 | ac->ev.delWrite = redisAeDelWrite; 92 | ac->ev.cleanup = redisAeCleanup; 93 | ac->ev.data = e; 94 | 95 | return REDIS_OK; 96 | } 97 | #endif 98 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/adapters/libev.h: -------------------------------------------------------------------------------- 1 | #ifndef __HIREDIS_LIBEV_H__ 2 | #define __HIREDIS_LIBEV_H__ 3 | #include 4 | #include 5 | #include 6 | #include "../hiredis.h" 7 | #include "../async.h" 8 | 9 | typedef struct redisLibevEvents { 10 | redisAsyncContext *context; 11 | struct ev_loop *loop; 12 | int reading, writing; 13 | ev_io rev, wev; 14 | } redisLibevEvents; 15 | 16 | static void redisLibevReadEvent(EV_P_ ev_io *watcher, int revents) { 17 | #if EV_MULTIPLICITY 18 | ((void)loop); 19 | #endif 20 | ((void)revents); 21 | 22 | redisLibevEvents *e = (redisLibevEvents*)watcher->data; 23 | redisAsyncHandleRead(e->context); 24 | } 25 | 26 | static void redisLibevWriteEvent(EV_P_ ev_io *watcher, int revents) { 27 | #if EV_MULTIPLICITY 28 | ((void)loop); 29 | #endif 30 | ((void)revents); 31 | 32 | redisLibevEvents *e = (redisLibevEvents*)watcher->data; 33 | redisAsyncHandleWrite(e->context); 34 | } 35 | 36 | static void redisLibevAddRead(void *privdata) { 37 | redisLibevEvents *e = (redisLibevEvents*)privdata; 38 | struct ev_loop *loop = e->loop; 39 | ((void)loop); 40 | if (!e->reading) { 41 | e->reading = 1; 42 | ev_io_start(EV_A_ &e->rev); 43 | } 44 | } 45 | 46 | static void redisLibevDelRead(void *privdata) { 47 | redisLibevEvents *e = (redisLibevEvents*)privdata; 48 | struct ev_loop *loop = e->loop; 49 | ((void)loop); 50 | if (e->reading) { 51 | e->reading = 0; 52 | ev_io_stop(EV_A_ &e->rev); 53 | } 54 | } 55 | 56 | static void redisLibevAddWrite(void *privdata) { 57 | redisLibevEvents *e = (redisLibevEvents*)privdata; 58 | struct ev_loop *loop = e->loop; 59 | ((void)loop); 60 | if (!e->writing) { 61 | e->writing = 1; 62 | ev_io_start(EV_A_ &e->wev); 63 | } 64 | } 65 | 66 | static void redisLibevDelWrite(void *privdata) { 67 | redisLibevEvents *e = (redisLibevEvents*)privdata; 68 | struct ev_loop *loop = e->loop; 69 | ((void)loop); 70 | if (e->writing) { 71 | e->writing = 0; 72 | ev_io_stop(EV_A_ &e->wev); 73 | } 74 | } 75 | 76 | static void redisLibevCleanup(void *privdata) { 77 | redisLibevEvents *e = (redisLibevEvents*)privdata; 78 | redisLibevDelRead(privdata); 79 | redisLibevDelWrite(privdata); 80 | free(e); 81 | } 82 | 83 | static int redisLibevAttach(EV_P_ redisAsyncContext *ac) { 84 | redisContext *c = &(ac->c); 85 | redisLibevEvents *e; 86 | 87 | /* Nothing should be attached when something is already attached */ 88 | if (ac->ev.data != NULL) 89 | return REDIS_ERR; 90 | 91 | /* Create container for context and r/w events */ 92 | e = (redisLibevEvents*)malloc(sizeof(*e)); 93 | e->context = ac; 94 | #if EV_MULTIPLICITY 95 | e->loop = loop; 96 | #else 97 | e->loop = NULL; 98 | #endif 99 | e->reading = e->writing = 0; 100 | e->rev.data = e; 101 | e->wev.data = e; 102 | 103 | /* Register functions to start/stop listening for events */ 104 | ac->ev.addRead = redisLibevAddRead; 105 | ac->ev.delRead = redisLibevDelRead; 106 | ac->ev.addWrite = redisLibevAddWrite; 107 | ac->ev.delWrite = redisLibevDelWrite; 108 | ac->ev.cleanup = redisLibevCleanup; 109 | ac->ev.data = e; 110 | 111 | /* Initialize read/write events */ 112 | ev_io_init(&e->rev,redisLibevReadEvent,c->fd,EV_READ); 113 | ev_io_init(&e->wev,redisLibevWriteEvent,c->fd,EV_WRITE); 114 | return REDIS_OK; 115 | } 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/adapters/libevent.h: -------------------------------------------------------------------------------- 1 | #ifndef __HIREDIS_LIBEVENT_H__ 2 | #define __HIREDIS_LIBEVENT_H__ 3 | #include 4 | #include "../hiredis.h" 5 | #include "../async.h" 6 | 7 | typedef struct redisLibeventEvents { 8 | redisAsyncContext *context; 9 | struct event rev, wev; 10 | } redisLibeventEvents; 11 | 12 | static void redisLibeventReadEvent(int fd, short event, void *arg) { 13 | ((void)fd); ((void)event); 14 | redisLibeventEvents *e = (redisLibeventEvents*)arg; 15 | redisAsyncHandleRead(e->context); 16 | } 17 | 18 | static void redisLibeventWriteEvent(int fd, short event, void *arg) { 19 | ((void)fd); ((void)event); 20 | redisLibeventEvents *e = (redisLibeventEvents*)arg; 21 | redisAsyncHandleWrite(e->context); 22 | } 23 | 24 | static void redisLibeventAddRead(void *privdata) { 25 | redisLibeventEvents *e = (redisLibeventEvents*)privdata; 26 | event_add(&e->rev,NULL); 27 | } 28 | 29 | static void redisLibeventDelRead(void *privdata) { 30 | redisLibeventEvents *e = (redisLibeventEvents*)privdata; 31 | event_del(&e->rev); 32 | } 33 | 34 | static void redisLibeventAddWrite(void *privdata) { 35 | redisLibeventEvents *e = (redisLibeventEvents*)privdata; 36 | event_add(&e->wev,NULL); 37 | } 38 | 39 | static void redisLibeventDelWrite(void *privdata) { 40 | redisLibeventEvents *e = (redisLibeventEvents*)privdata; 41 | event_del(&e->wev); 42 | } 43 | 44 | static void redisLibeventCleanup(void *privdata) { 45 | redisLibeventEvents *e = (redisLibeventEvents*)privdata; 46 | event_del(&e->rev); 47 | event_del(&e->wev); 48 | free(e); 49 | } 50 | 51 | static int redisLibeventAttach(redisAsyncContext *ac, struct event_base *base) { 52 | redisContext *c = &(ac->c); 53 | redisLibeventEvents *e; 54 | 55 | /* Nothing should be attached when something is already attached */ 56 | if (ac->ev.data != NULL) 57 | return REDIS_ERR; 58 | 59 | /* Create container for context and r/w events */ 60 | e = (redisLibeventEvents*)malloc(sizeof(*e)); 61 | e->context = ac; 62 | 63 | /* Register functions to start/stop listening for events */ 64 | ac->ev.addRead = redisLibeventAddRead; 65 | ac->ev.delRead = redisLibeventDelRead; 66 | ac->ev.addWrite = redisLibeventAddWrite; 67 | ac->ev.delWrite = redisLibeventDelWrite; 68 | ac->ev.cleanup = redisLibeventCleanup; 69 | ac->ev.data = e; 70 | 71 | /* Initialize and install read/write events */ 72 | event_set(&e->rev,c->fd,EV_READ,redisLibeventReadEvent,e); 73 | event_set(&e->wev,c->fd,EV_WRITE,redisLibeventWriteEvent,e); 74 | event_base_set(base,&e->rev); 75 | event_base_set(base,&e->wev); 76 | return REDIS_OK; 77 | } 78 | #endif 79 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/async.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2011, Salvatore Sanfilippo 3 | * Copyright (c) 2010-2011, Pieter Noordhuis 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of Redis nor the names of its contributors may be used 16 | * to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef __HIREDIS_ASYNC_H 33 | #define __HIREDIS_ASYNC_H 34 | #include "hiredis.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | struct redisAsyncContext; /* need forward declaration of redisAsyncContext */ 41 | struct dict; /* dictionary header is included in async.c */ 42 | 43 | /* Reply callback prototype and container */ 44 | typedef void (redisCallbackFn)(struct redisAsyncContext*, void*, void*); 45 | typedef struct redisCallback { 46 | struct redisCallback *next; /* simple singly linked list */ 47 | redisCallbackFn *fn; 48 | void *privdata; 49 | } redisCallback; 50 | 51 | /* List of callbacks for either regular replies or pub/sub */ 52 | typedef struct redisCallbackList { 53 | redisCallback *head, *tail; 54 | } redisCallbackList; 55 | 56 | /* Connection callback prototypes */ 57 | typedef void (redisDisconnectCallback)(const struct redisAsyncContext*, int status); 58 | typedef void (redisConnectCallback)(const struct redisAsyncContext*, int status); 59 | 60 | /* Context for an async connection to Redis */ 61 | typedef struct redisAsyncContext { 62 | /* Hold the regular context, so it can be realloc'ed. */ 63 | redisContext c; 64 | 65 | /* Setup error flags so they can be used directly. */ 66 | int err; 67 | char *errstr; 68 | 69 | /* Not used by hiredis */ 70 | void *data; 71 | 72 | /* Event library data and hooks */ 73 | struct { 74 | void *data; 75 | 76 | /* Hooks that are called when the library expects to start 77 | * reading/writing. These functions should be idempotent. */ 78 | void (*addRead)(void *privdata); 79 | void (*delRead)(void *privdata); 80 | void (*addWrite)(void *privdata); 81 | void (*delWrite)(void *privdata); 82 | void (*cleanup)(void *privdata); 83 | } ev; 84 | 85 | /* Called when either the connection is terminated due to an error or per 86 | * user request. The status is set accordingly (REDIS_OK, REDIS_ERR). */ 87 | redisDisconnectCallback *onDisconnect; 88 | 89 | /* Called when the first write event was received. */ 90 | redisConnectCallback *onConnect; 91 | 92 | /* Regular command callbacks */ 93 | redisCallbackList replies; 94 | 95 | /* Subscription callbacks */ 96 | struct { 97 | redisCallbackList invalid; 98 | struct dict *channels; 99 | struct dict *patterns; 100 | } sub; 101 | } redisAsyncContext; 102 | 103 | /* Functions that proxy to hiredis */ 104 | redisAsyncContext *redisAsyncConnect(const char *ip, int port); 105 | redisAsyncContext *redisAsyncConnectUnix(const char *path); 106 | int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn); 107 | int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn); 108 | void redisAsyncDisconnect(redisAsyncContext *ac); 109 | void redisAsyncFree(redisAsyncContext *ac); 110 | 111 | /* Handle read/write events */ 112 | void redisAsyncHandleRead(redisAsyncContext *ac); 113 | void redisAsyncHandleWrite(redisAsyncContext *ac); 114 | 115 | /* Command functions for an async context. Write the command to the 116 | * output buffer and register the provided callback. */ 117 | int redisvAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, va_list ap); 118 | int redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, ...); 119 | int redisAsyncCommandArgv(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen); 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/async.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/hiredis/deps/hiredis/async.o -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/dict.c: -------------------------------------------------------------------------------- 1 | /* Hash table implementation. 2 | * 3 | * This file implements in memory hash tables with insert/del/replace/find/ 4 | * get-random-element operations. Hash tables will auto resize if needed 5 | * tables of power of two in size are used, collisions are handled by 6 | * chaining. See the source code for more information... :) 7 | * 8 | * Copyright (c) 2006-2010, Salvatore Sanfilippo 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * 14 | * * Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * * Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * * Neither the name of Redis nor the names of its contributors may be used 20 | * to endorse or promote products derived from this software without 21 | * specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include "fmacros.h" 37 | #include 38 | #include 39 | #include 40 | #include "dict.h" 41 | 42 | /* -------------------------- private prototypes ---------------------------- */ 43 | 44 | static int _dictExpandIfNeeded(dict *ht); 45 | static unsigned long _dictNextPower(unsigned long size); 46 | static int _dictKeyIndex(dict *ht, const void *key); 47 | static int _dictInit(dict *ht, dictType *type, void *privDataPtr); 48 | 49 | /* -------------------------- hash functions -------------------------------- */ 50 | 51 | /* Generic hash function (a popular one from Bernstein). 52 | * I tested a few and this was the best. */ 53 | static unsigned int dictGenHashFunction(const unsigned char *buf, int len) { 54 | unsigned int hash = 5381; 55 | 56 | while (len--) 57 | hash = ((hash << 5) + hash) + (*buf++); /* hash * 33 + c */ 58 | return hash; 59 | } 60 | 61 | /* ----------------------------- API implementation ------------------------- */ 62 | 63 | /* Reset an hashtable already initialized with ht_init(). 64 | * NOTE: This function should only called by ht_destroy(). */ 65 | static void _dictReset(dict *ht) { 66 | ht->table = NULL; 67 | ht->size = 0; 68 | ht->sizemask = 0; 69 | ht->used = 0; 70 | } 71 | 72 | /* Create a new hash table */ 73 | static dict *dictCreate(dictType *type, void *privDataPtr) { 74 | dict *ht = malloc(sizeof(*ht)); 75 | _dictInit(ht,type,privDataPtr); 76 | return ht; 77 | } 78 | 79 | /* Initialize the hash table */ 80 | static int _dictInit(dict *ht, dictType *type, void *privDataPtr) { 81 | _dictReset(ht); 82 | ht->type = type; 83 | ht->privdata = privDataPtr; 84 | return DICT_OK; 85 | } 86 | 87 | /* Expand or create the hashtable */ 88 | static int dictExpand(dict *ht, unsigned long size) { 89 | dict n; /* the new hashtable */ 90 | unsigned long realsize = _dictNextPower(size), i; 91 | 92 | /* the size is invalid if it is smaller than the number of 93 | * elements already inside the hashtable */ 94 | if (ht->used > size) 95 | return DICT_ERR; 96 | 97 | _dictInit(&n, ht->type, ht->privdata); 98 | n.size = realsize; 99 | n.sizemask = realsize-1; 100 | n.table = calloc(realsize,sizeof(dictEntry*)); 101 | 102 | /* Copy all the elements from the old to the new table: 103 | * note that if the old hash table is empty ht->size is zero, 104 | * so dictExpand just creates an hash table. */ 105 | n.used = ht->used; 106 | for (i = 0; i < ht->size && ht->used > 0; i++) { 107 | dictEntry *he, *nextHe; 108 | 109 | if (ht->table[i] == NULL) continue; 110 | 111 | /* For each hash entry on this slot... */ 112 | he = ht->table[i]; 113 | while(he) { 114 | unsigned int h; 115 | 116 | nextHe = he->next; 117 | /* Get the new element index */ 118 | h = dictHashKey(ht, he->key) & n.sizemask; 119 | he->next = n.table[h]; 120 | n.table[h] = he; 121 | ht->used--; 122 | /* Pass to the next element */ 123 | he = nextHe; 124 | } 125 | } 126 | assert(ht->used == 0); 127 | free(ht->table); 128 | 129 | /* Remap the new hashtable in the old */ 130 | *ht = n; 131 | return DICT_OK; 132 | } 133 | 134 | /* Add an element to the target hash table */ 135 | static int dictAdd(dict *ht, void *key, void *val) { 136 | int index; 137 | dictEntry *entry; 138 | 139 | /* Get the index of the new element, or -1 if 140 | * the element already exists. */ 141 | if ((index = _dictKeyIndex(ht, key)) == -1) 142 | return DICT_ERR; 143 | 144 | /* Allocates the memory and stores key */ 145 | entry = malloc(sizeof(*entry)); 146 | entry->next = ht->table[index]; 147 | ht->table[index] = entry; 148 | 149 | /* Set the hash entry fields. */ 150 | dictSetHashKey(ht, entry, key); 151 | dictSetHashVal(ht, entry, val); 152 | ht->used++; 153 | return DICT_OK; 154 | } 155 | 156 | /* Add an element, discarding the old if the key already exists. 157 | * Return 1 if the key was added from scratch, 0 if there was already an 158 | * element with such key and dictReplace() just performed a value update 159 | * operation. */ 160 | static int dictReplace(dict *ht, void *key, void *val) { 161 | dictEntry *entry, auxentry; 162 | 163 | /* Try to add the element. If the key 164 | * does not exists dictAdd will suceed. */ 165 | if (dictAdd(ht, key, val) == DICT_OK) 166 | return 1; 167 | /* It already exists, get the entry */ 168 | entry = dictFind(ht, key); 169 | /* Free the old value and set the new one */ 170 | /* Set the new value and free the old one. Note that it is important 171 | * to do that in this order, as the value may just be exactly the same 172 | * as the previous one. In this context, think to reference counting, 173 | * you want to increment (set), and then decrement (free), and not the 174 | * reverse. */ 175 | auxentry = *entry; 176 | dictSetHashVal(ht, entry, val); 177 | dictFreeEntryVal(ht, &auxentry); 178 | return 0; 179 | } 180 | 181 | /* Search and remove an element */ 182 | static int dictDelete(dict *ht, const void *key) { 183 | unsigned int h; 184 | dictEntry *de, *prevde; 185 | 186 | if (ht->size == 0) 187 | return DICT_ERR; 188 | h = dictHashKey(ht, key) & ht->sizemask; 189 | de = ht->table[h]; 190 | 191 | prevde = NULL; 192 | while(de) { 193 | if (dictCompareHashKeys(ht,key,de->key)) { 194 | /* Unlink the element from the list */ 195 | if (prevde) 196 | prevde->next = de->next; 197 | else 198 | ht->table[h] = de->next; 199 | 200 | dictFreeEntryKey(ht,de); 201 | dictFreeEntryVal(ht,de); 202 | free(de); 203 | ht->used--; 204 | return DICT_OK; 205 | } 206 | prevde = de; 207 | de = de->next; 208 | } 209 | return DICT_ERR; /* not found */ 210 | } 211 | 212 | /* Destroy an entire hash table */ 213 | static int _dictClear(dict *ht) { 214 | unsigned long i; 215 | 216 | /* Free all the elements */ 217 | for (i = 0; i < ht->size && ht->used > 0; i++) { 218 | dictEntry *he, *nextHe; 219 | 220 | if ((he = ht->table[i]) == NULL) continue; 221 | while(he) { 222 | nextHe = he->next; 223 | dictFreeEntryKey(ht, he); 224 | dictFreeEntryVal(ht, he); 225 | free(he); 226 | ht->used--; 227 | he = nextHe; 228 | } 229 | } 230 | /* Free the table and the allocated cache structure */ 231 | free(ht->table); 232 | /* Re-initialize the table */ 233 | _dictReset(ht); 234 | return DICT_OK; /* never fails */ 235 | } 236 | 237 | /* Clear & Release the hash table */ 238 | static void dictRelease(dict *ht) { 239 | _dictClear(ht); 240 | free(ht); 241 | } 242 | 243 | static dictEntry *dictFind(dict *ht, const void *key) { 244 | dictEntry *he; 245 | unsigned int h; 246 | 247 | if (ht->size == 0) return NULL; 248 | h = dictHashKey(ht, key) & ht->sizemask; 249 | he = ht->table[h]; 250 | while(he) { 251 | if (dictCompareHashKeys(ht, key, he->key)) 252 | return he; 253 | he = he->next; 254 | } 255 | return NULL; 256 | } 257 | 258 | static dictIterator *dictGetIterator(dict *ht) { 259 | dictIterator *iter = malloc(sizeof(*iter)); 260 | 261 | iter->ht = ht; 262 | iter->index = -1; 263 | iter->entry = NULL; 264 | iter->nextEntry = NULL; 265 | return iter; 266 | } 267 | 268 | static dictEntry *dictNext(dictIterator *iter) { 269 | while (1) { 270 | if (iter->entry == NULL) { 271 | iter->index++; 272 | if (iter->index >= 273 | (signed)iter->ht->size) break; 274 | iter->entry = iter->ht->table[iter->index]; 275 | } else { 276 | iter->entry = iter->nextEntry; 277 | } 278 | if (iter->entry) { 279 | /* We need to save the 'next' here, the iterator user 280 | * may delete the entry we are returning. */ 281 | iter->nextEntry = iter->entry->next; 282 | return iter->entry; 283 | } 284 | } 285 | return NULL; 286 | } 287 | 288 | static void dictReleaseIterator(dictIterator *iter) { 289 | free(iter); 290 | } 291 | 292 | /* ------------------------- private functions ------------------------------ */ 293 | 294 | /* Expand the hash table if needed */ 295 | static int _dictExpandIfNeeded(dict *ht) { 296 | /* If the hash table is empty expand it to the intial size, 297 | * if the table is "full" dobule its size. */ 298 | if (ht->size == 0) 299 | return dictExpand(ht, DICT_HT_INITIAL_SIZE); 300 | if (ht->used == ht->size) 301 | return dictExpand(ht, ht->size*2); 302 | return DICT_OK; 303 | } 304 | 305 | /* Our hash table capability is a power of two */ 306 | static unsigned long _dictNextPower(unsigned long size) { 307 | unsigned long i = DICT_HT_INITIAL_SIZE; 308 | 309 | if (size >= LONG_MAX) return LONG_MAX; 310 | while(1) { 311 | if (i >= size) 312 | return i; 313 | i *= 2; 314 | } 315 | } 316 | 317 | /* Returns the index of a free slot that can be populated with 318 | * an hash entry for the given 'key'. 319 | * If the key already exists, -1 is returned. */ 320 | static int _dictKeyIndex(dict *ht, const void *key) { 321 | unsigned int h; 322 | dictEntry *he; 323 | 324 | /* Expand the hashtable if needed */ 325 | if (_dictExpandIfNeeded(ht) == DICT_ERR) 326 | return -1; 327 | /* Compute the key hash value */ 328 | h = dictHashKey(ht, key) & ht->sizemask; 329 | /* Search if this slot does not already contain the given key */ 330 | he = ht->table[h]; 331 | while(he) { 332 | if (dictCompareHashKeys(ht, key, he->key)) 333 | return -1; 334 | he = he->next; 335 | } 336 | return h; 337 | } 338 | 339 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/dict.h: -------------------------------------------------------------------------------- 1 | /* Hash table implementation. 2 | * 3 | * This file implements in memory hash tables with insert/del/replace/find/ 4 | * get-random-element operations. Hash tables will auto resize if needed 5 | * tables of power of two in size are used, collisions are handled by 6 | * chaining. See the source code for more information... :) 7 | * 8 | * Copyright (c) 2006-2010, Salvatore Sanfilippo 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * 14 | * * Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * * Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * * Neither the name of Redis nor the names of its contributors may be used 20 | * to endorse or promote products derived from this software without 21 | * specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef __DICT_H 37 | #define __DICT_H 38 | 39 | #define DICT_OK 0 40 | #define DICT_ERR 1 41 | 42 | /* Unused arguments generate annoying warnings... */ 43 | #define DICT_NOTUSED(V) ((void) V) 44 | 45 | typedef struct dictEntry { 46 | void *key; 47 | void *val; 48 | struct dictEntry *next; 49 | } dictEntry; 50 | 51 | typedef struct dictType { 52 | unsigned int (*hashFunction)(const void *key); 53 | void *(*keyDup)(void *privdata, const void *key); 54 | void *(*valDup)(void *privdata, const void *obj); 55 | int (*keyCompare)(void *privdata, const void *key1, const void *key2); 56 | void (*keyDestructor)(void *privdata, void *key); 57 | void (*valDestructor)(void *privdata, void *obj); 58 | } dictType; 59 | 60 | typedef struct dict { 61 | dictEntry **table; 62 | dictType *type; 63 | unsigned long size; 64 | unsigned long sizemask; 65 | unsigned long used; 66 | void *privdata; 67 | } dict; 68 | 69 | typedef struct dictIterator { 70 | dict *ht; 71 | int index; 72 | dictEntry *entry, *nextEntry; 73 | } dictIterator; 74 | 75 | /* This is the initial size of every hash table */ 76 | #define DICT_HT_INITIAL_SIZE 4 77 | 78 | /* ------------------------------- Macros ------------------------------------*/ 79 | #define dictFreeEntryVal(ht, entry) \ 80 | if ((ht)->type->valDestructor) \ 81 | (ht)->type->valDestructor((ht)->privdata, (entry)->val) 82 | 83 | #define dictSetHashVal(ht, entry, _val_) do { \ 84 | if ((ht)->type->valDup) \ 85 | entry->val = (ht)->type->valDup((ht)->privdata, _val_); \ 86 | else \ 87 | entry->val = (_val_); \ 88 | } while(0) 89 | 90 | #define dictFreeEntryKey(ht, entry) \ 91 | if ((ht)->type->keyDestructor) \ 92 | (ht)->type->keyDestructor((ht)->privdata, (entry)->key) 93 | 94 | #define dictSetHashKey(ht, entry, _key_) do { \ 95 | if ((ht)->type->keyDup) \ 96 | entry->key = (ht)->type->keyDup((ht)->privdata, _key_); \ 97 | else \ 98 | entry->key = (_key_); \ 99 | } while(0) 100 | 101 | #define dictCompareHashKeys(ht, key1, key2) \ 102 | (((ht)->type->keyCompare) ? \ 103 | (ht)->type->keyCompare((ht)->privdata, key1, key2) : \ 104 | (key1) == (key2)) 105 | 106 | #define dictHashKey(ht, key) (ht)->type->hashFunction(key) 107 | 108 | #define dictGetEntryKey(he) ((he)->key) 109 | #define dictGetEntryVal(he) ((he)->val) 110 | #define dictSlots(ht) ((ht)->size) 111 | #define dictSize(ht) ((ht)->used) 112 | 113 | /* API */ 114 | static unsigned int dictGenHashFunction(const unsigned char *buf, int len); 115 | static dict *dictCreate(dictType *type, void *privDataPtr); 116 | static int dictExpand(dict *ht, unsigned long size); 117 | static int dictAdd(dict *ht, void *key, void *val); 118 | static int dictReplace(dict *ht, void *key, void *val); 119 | static int dictDelete(dict *ht, const void *key); 120 | static void dictRelease(dict *ht); 121 | static dictEntry * dictFind(dict *ht, const void *key); 122 | static dictIterator *dictGetIterator(dict *ht); 123 | static dictEntry *dictNext(dictIterator *iter); 124 | static void dictReleaseIterator(dictIterator *iter); 125 | 126 | #endif /* __DICT_H */ 127 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/example-ae.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "hiredis.h" 6 | #include "async.h" 7 | #include "adapters/ae.h" 8 | 9 | /* Put event loop in the global scope, so it can be explicitly stopped */ 10 | static aeEventLoop *loop; 11 | 12 | void getCallback(redisAsyncContext *c, void *r, void *privdata) { 13 | redisReply *reply = r; 14 | if (reply == NULL) return; 15 | printf("argv[%s]: %s\n", (char*)privdata, reply->str); 16 | 17 | /* Disconnect after receiving the reply to GET */ 18 | redisAsyncDisconnect(c); 19 | } 20 | 21 | void connectCallback(const redisAsyncContext *c, int status) { 22 | if (status != REDIS_OK) { 23 | printf("Error: %s\n", c->errstr); 24 | return; 25 | } 26 | printf("Connected...\n"); 27 | } 28 | 29 | void disconnectCallback(const redisAsyncContext *c, int status) { 30 | if (status != REDIS_OK) { 31 | printf("Error: %s\n", c->errstr); 32 | return; 33 | } 34 | printf("Disconnected...\n"); 35 | } 36 | 37 | int main (int argc, char **argv) { 38 | signal(SIGPIPE, SIG_IGN); 39 | 40 | redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); 41 | if (c->err) { 42 | /* Let *c leak for now... */ 43 | printf("Error: %s\n", c->errstr); 44 | return 1; 45 | } 46 | 47 | loop = aeCreateEventLoop(); 48 | redisAeAttach(loop, c); 49 | redisAsyncSetConnectCallback(c,connectCallback); 50 | redisAsyncSetDisconnectCallback(c,disconnectCallback); 51 | redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); 52 | redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); 53 | aeMain(loop); 54 | return 0; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/example-libev.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "hiredis.h" 6 | #include "async.h" 7 | #include "adapters/libev.h" 8 | 9 | void getCallback(redisAsyncContext *c, void *r, void *privdata) { 10 | redisReply *reply = r; 11 | if (reply == NULL) return; 12 | printf("argv[%s]: %s\n", (char*)privdata, reply->str); 13 | 14 | /* Disconnect after receiving the reply to GET */ 15 | redisAsyncDisconnect(c); 16 | } 17 | 18 | void connectCallback(const redisAsyncContext *c, int status) { 19 | if (status != REDIS_OK) { 20 | printf("Error: %s\n", c->errstr); 21 | return; 22 | } 23 | printf("Connected...\n"); 24 | } 25 | 26 | void disconnectCallback(const redisAsyncContext *c, int status) { 27 | if (status != REDIS_OK) { 28 | printf("Error: %s\n", c->errstr); 29 | return; 30 | } 31 | printf("Disconnected...\n"); 32 | } 33 | 34 | int main (int argc, char **argv) { 35 | signal(SIGPIPE, SIG_IGN); 36 | 37 | redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); 38 | if (c->err) { 39 | /* Let *c leak for now... */ 40 | printf("Error: %s\n", c->errstr); 41 | return 1; 42 | } 43 | 44 | redisLibevAttach(EV_DEFAULT_ c); 45 | redisAsyncSetConnectCallback(c,connectCallback); 46 | redisAsyncSetDisconnectCallback(c,disconnectCallback); 47 | redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); 48 | redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); 49 | ev_loop(EV_DEFAULT_ 0); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/example-libevent.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "hiredis.h" 6 | #include "async.h" 7 | #include "adapters/libevent.h" 8 | 9 | void getCallback(redisAsyncContext *c, void *r, void *privdata) { 10 | redisReply *reply = r; 11 | if (reply == NULL) return; 12 | printf("argv[%s]: %s\n", (char*)privdata, reply->str); 13 | 14 | /* Disconnect after receiving the reply to GET */ 15 | redisAsyncDisconnect(c); 16 | } 17 | 18 | void connectCallback(const redisAsyncContext *c, int status) { 19 | if (status != REDIS_OK) { 20 | printf("Error: %s\n", c->errstr); 21 | return; 22 | } 23 | printf("Connected...\n"); 24 | } 25 | 26 | void disconnectCallback(const redisAsyncContext *c, int status) { 27 | if (status != REDIS_OK) { 28 | printf("Error: %s\n", c->errstr); 29 | return; 30 | } 31 | printf("Disconnected...\n"); 32 | } 33 | 34 | int main (int argc, char **argv) { 35 | signal(SIGPIPE, SIG_IGN); 36 | struct event_base *base = event_base_new(); 37 | 38 | redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); 39 | if (c->err) { 40 | /* Let *c leak for now... */ 41 | printf("Error: %s\n", c->errstr); 42 | return 1; 43 | } 44 | 45 | redisLibeventAttach(c,base); 46 | redisAsyncSetConnectCallback(c,connectCallback); 47 | redisAsyncSetDisconnectCallback(c,disconnectCallback); 48 | redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); 49 | redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); 50 | event_base_dispatch(base); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "hiredis.h" 6 | 7 | int main(void) { 8 | unsigned int j; 9 | redisContext *c; 10 | redisReply *reply; 11 | 12 | struct timeval timeout = { 1, 500000 }; // 1.5 seconds 13 | c = redisConnectWithTimeout((char*)"127.0.0.2", 6379, timeout); 14 | if (c->err) { 15 | printf("Connection error: %s\n", c->errstr); 16 | exit(1); 17 | } 18 | 19 | /* PING server */ 20 | reply = redisCommand(c,"PING"); 21 | printf("PING: %s\n", reply->str); 22 | freeReplyObject(reply); 23 | 24 | /* Set a key */ 25 | reply = redisCommand(c,"SET %s %s", "foo", "hello world"); 26 | printf("SET: %s\n", reply->str); 27 | freeReplyObject(reply); 28 | 29 | /* Set a key using binary safe API */ 30 | reply = redisCommand(c,"SET %b %b", "bar", 3, "hello", 5); 31 | printf("SET (binary API): %s\n", reply->str); 32 | freeReplyObject(reply); 33 | 34 | /* Try a GET and two INCR */ 35 | reply = redisCommand(c,"GET foo"); 36 | printf("GET foo: %s\n", reply->str); 37 | freeReplyObject(reply); 38 | 39 | reply = redisCommand(c,"INCR counter"); 40 | printf("INCR counter: %lld\n", reply->integer); 41 | freeReplyObject(reply); 42 | /* again ... */ 43 | reply = redisCommand(c,"INCR counter"); 44 | printf("INCR counter: %lld\n", reply->integer); 45 | freeReplyObject(reply); 46 | 47 | /* Create a list of numbers, from 0 to 9 */ 48 | reply = redisCommand(c,"DEL mylist"); 49 | freeReplyObject(reply); 50 | for (j = 0; j < 10; j++) { 51 | char buf[64]; 52 | 53 | snprintf(buf,64,"%d",j); 54 | reply = redisCommand(c,"LPUSH mylist element-%s", buf); 55 | freeReplyObject(reply); 56 | } 57 | 58 | /* Let's check what we have inside the list */ 59 | reply = redisCommand(c,"LRANGE mylist 0 -1"); 60 | if (reply->type == REDIS_REPLY_ARRAY) { 61 | for (j = 0; j < reply->elements; j++) { 62 | printf("%u) %s\n", j, reply->element[j]->str); 63 | } 64 | } 65 | freeReplyObject(reply); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/fmacros.h: -------------------------------------------------------------------------------- 1 | #ifndef __HIREDIS_FMACRO_H 2 | #define __HIREDIS_FMACRO_H 3 | 4 | #if !defined(_BSD_SOURCE) 5 | #define _BSD_SOURCE 6 | #endif 7 | 8 | #if defined(__sun__) 9 | #define _POSIX_C_SOURCE 200112L 10 | #elif defined(__linux__) 11 | #define _XOPEN_SOURCE 600 12 | #else 13 | #define _XOPEN_SOURCE 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/hiredis.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2011, Salvatore Sanfilippo 3 | * Copyright (c) 2010-2011, Pieter Noordhuis 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of Redis nor the names of its contributors may be used 16 | * to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef __HIREDIS_H 33 | #define __HIREDIS_H 34 | #include /* for size_t */ 35 | #include /* for va_list */ 36 | #include /* for struct timeval */ 37 | 38 | #define HIREDIS_MAJOR 0 39 | #define HIREDIS_MINOR 10 40 | #define HIREDIS_PATCH 1 41 | 42 | #define REDIS_ERR -1 43 | #define REDIS_OK 0 44 | 45 | /* When an error occurs, the err flag in a context is set to hold the type of 46 | * error that occured. REDIS_ERR_IO means there was an I/O error and you 47 | * should use the "errno" variable to find out what is wrong. 48 | * For other values, the "errstr" field will hold a description. */ 49 | #define REDIS_ERR_IO 1 /* Error in read or write */ 50 | #define REDIS_ERR_EOF 3 /* End of file */ 51 | #define REDIS_ERR_PROTOCOL 4 /* Protocol error */ 52 | #define REDIS_ERR_OOM 5 /* Out of memory */ 53 | #define REDIS_ERR_OTHER 2 /* Everything else... */ 54 | 55 | /* Connection type can be blocking or non-blocking and is set in the 56 | * least significant bit of the flags field in redisContext. */ 57 | #define REDIS_BLOCK 0x1 58 | 59 | /* Connection may be disconnected before being free'd. The second bit 60 | * in the flags field is set when the context is connected. */ 61 | #define REDIS_CONNECTED 0x2 62 | 63 | /* The async API might try to disconnect cleanly and flush the output 64 | * buffer and read all subsequent replies before disconnecting. 65 | * This flag means no new commands can come in and the connection 66 | * should be terminated once all replies have been read. */ 67 | #define REDIS_DISCONNECTING 0x4 68 | 69 | /* Flag specific to the async API which means that the context should be clean 70 | * up as soon as possible. */ 71 | #define REDIS_FREEING 0x8 72 | 73 | /* Flag that is set when an async callback is executed. */ 74 | #define REDIS_IN_CALLBACK 0x10 75 | 76 | /* Flag that is set when the async context has one or more subscriptions. */ 77 | #define REDIS_SUBSCRIBED 0x20 78 | 79 | #define REDIS_REPLY_STRING 1 80 | #define REDIS_REPLY_ARRAY 2 81 | #define REDIS_REPLY_INTEGER 3 82 | #define REDIS_REPLY_NIL 4 83 | #define REDIS_REPLY_STATUS 5 84 | #define REDIS_REPLY_ERROR 6 85 | 86 | #ifdef __cplusplus 87 | extern "C" { 88 | #endif 89 | 90 | /* This is the reply object returned by redisCommand() */ 91 | typedef struct redisReply { 92 | int type; /* REDIS_REPLY_* */ 93 | long long integer; /* The integer when type is REDIS_REPLY_INTEGER */ 94 | int len; /* Length of string */ 95 | char *str; /* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */ 96 | size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */ 97 | struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */ 98 | } redisReply; 99 | 100 | typedef struct redisReadTask { 101 | int type; 102 | int elements; /* number of elements in multibulk container */ 103 | int idx; /* index in parent (array) object */ 104 | void *obj; /* holds user-generated value for a read task */ 105 | struct redisReadTask *parent; /* parent task */ 106 | void *privdata; /* user-settable arbitrary field */ 107 | } redisReadTask; 108 | 109 | typedef struct redisReplyObjectFunctions { 110 | void *(*createString)(const redisReadTask*, char*, size_t); 111 | void *(*createArray)(const redisReadTask*, int); 112 | void *(*createInteger)(const redisReadTask*, long long); 113 | void *(*createNil)(const redisReadTask*); 114 | void (*freeObject)(void*); 115 | } redisReplyObjectFunctions; 116 | 117 | /* State for the protocol parser */ 118 | typedef struct redisReader { 119 | int err; /* Error flags, 0 when there is no error */ 120 | char errstr[128]; /* String representation of error when applicable */ 121 | 122 | char *buf; /* Read buffer */ 123 | size_t pos; /* Buffer cursor */ 124 | size_t len; /* Buffer length */ 125 | 126 | redisReadTask rstack[4]; 127 | int ridx; /* Index of current read task */ 128 | void *reply; /* Temporary reply pointer */ 129 | 130 | redisReplyObjectFunctions *fn; 131 | void *privdata; 132 | } redisReader; 133 | 134 | /* Public API for the protocol parser. */ 135 | redisReader *redisReaderCreate(void); 136 | void redisReaderFree(redisReader *r); 137 | int redisReaderFeed(redisReader *r, const char *buf, size_t len); 138 | int redisReaderGetReply(redisReader *r, void **reply); 139 | 140 | /* Backwards compatibility, can be removed on big version bump. */ 141 | #define redisReplyReaderCreate redisReaderCreate 142 | #define redisReplyReaderFree redisReaderFree 143 | #define redisReplyReaderFeed redisReaderFeed 144 | #define redisReplyReaderGetReply redisReaderGetReply 145 | #define redisReplyReaderSetPrivdata(_r, _p) (int)(((redisReader*)(_r))->privdata = (_p)) 146 | #define redisReplyReaderGetObject(_r) (((redisReader*)(_r))->reply) 147 | #define redisReplyReaderGetError(_r) (((redisReader*)(_r))->errstr) 148 | 149 | /* Function to free the reply objects hiredis returns by default. */ 150 | void freeReplyObject(void *reply); 151 | 152 | /* Functions to format a command according to the protocol. */ 153 | int redisvFormatCommand(char **target, const char *format, va_list ap); 154 | int redisFormatCommand(char **target, const char *format, ...); 155 | int redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen); 156 | 157 | /* Context for a connection to Redis */ 158 | typedef struct redisContext { 159 | int err; /* Error flags, 0 when there is no error */ 160 | char errstr[128]; /* String representation of error when applicable */ 161 | int fd; 162 | int flags; 163 | char *obuf; /* Write buffer */ 164 | redisReader *reader; /* Protocol reader */ 165 | } redisContext; 166 | 167 | redisContext *redisConnect(const char *ip, int port); 168 | redisContext *redisConnectWithTimeout(const char *ip, int port, struct timeval tv); 169 | redisContext *redisConnectNonBlock(const char *ip, int port); 170 | redisContext *redisConnectUnix(const char *path); 171 | redisContext *redisConnectUnixWithTimeout(const char *path, struct timeval tv); 172 | redisContext *redisConnectUnixNonBlock(const char *path); 173 | int redisSetTimeout(redisContext *c, struct timeval tv); 174 | void redisFree(redisContext *c); 175 | int redisBufferRead(redisContext *c); 176 | int redisBufferWrite(redisContext *c, int *done); 177 | 178 | /* In a blocking context, this function first checks if there are unconsumed 179 | * replies to return and returns one if so. Otherwise, it flushes the output 180 | * buffer to the socket and reads until it has a reply. In a non-blocking 181 | * context, it will return unconsumed replies until there are no more. */ 182 | int redisGetReply(redisContext *c, void **reply); 183 | int redisGetReplyFromReader(redisContext *c, void **reply); 184 | 185 | /* Write a command to the output buffer. Use these functions in blocking mode 186 | * to get a pipeline of commands. */ 187 | int redisvAppendCommand(redisContext *c, const char *format, va_list ap); 188 | int redisAppendCommand(redisContext *c, const char *format, ...); 189 | int redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen); 190 | 191 | /* Issue a command to Redis. In a blocking context, it is identical to calling 192 | * redisAppendCommand, followed by redisGetReply. The function will return 193 | * NULL if there was an error in performing the request, otherwise it will 194 | * return the reply. In a non-blocking context, it is identical to calling 195 | * only redisAppendCommand and will always return NULL. */ 196 | void *redisvCommand(redisContext *c, const char *format, va_list ap); 197 | void *redisCommand(redisContext *c, const char *format, ...); 198 | void *redisCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen); 199 | 200 | #ifdef __cplusplus 201 | } 202 | #endif 203 | 204 | #endif 205 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/hiredis.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/hiredis/deps/hiredis/hiredis.o -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/libhiredis.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/hiredis/deps/hiredis/libhiredis.a -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/net.c: -------------------------------------------------------------------------------- 1 | /* Extracted from anet.c to work properly with Hiredis error reporting. 2 | * 3 | * Copyright (c) 2006-2011, Salvatore Sanfilippo 4 | * Copyright (c) 2010-2011, Pieter Noordhuis 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * * Neither the name of Redis nor the names of its contributors may be used 17 | * to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include "fmacros.h" 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include "net.h" 50 | #include "sds.h" 51 | 52 | /* Defined in hiredis.c */ 53 | void __redisSetError(redisContext *c, int type, const char *str); 54 | 55 | static void __redisSetErrorFromErrno(redisContext *c, int type, const char *prefix) { 56 | char buf[128]; 57 | size_t len = 0; 58 | 59 | if (prefix != NULL) 60 | len = snprintf(buf,sizeof(buf),"%s: ",prefix); 61 | strerror_r(errno,buf+len,sizeof(buf)-len); 62 | __redisSetError(c,type,buf); 63 | } 64 | 65 | static int redisSetReuseAddr(redisContext *c, int fd) { 66 | int on = 1; 67 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) { 68 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL); 69 | close(fd); 70 | return REDIS_ERR; 71 | } 72 | return REDIS_OK; 73 | } 74 | 75 | static int redisCreateSocket(redisContext *c, int type) { 76 | int s; 77 | if ((s = socket(type, SOCK_STREAM, 0)) == -1) { 78 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL); 79 | return REDIS_ERR; 80 | } 81 | if (type == AF_INET) { 82 | if (redisSetReuseAddr(c,s) == REDIS_ERR) { 83 | return REDIS_ERR; 84 | } 85 | } 86 | return s; 87 | } 88 | 89 | static int redisSetBlocking(redisContext *c, int fd, int blocking) { 90 | int flags; 91 | 92 | /* Set the socket nonblocking. 93 | * Note that fcntl(2) for F_GETFL and F_SETFL can't be 94 | * interrupted by a signal. */ 95 | if ((flags = fcntl(fd, F_GETFL)) == -1) { 96 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(F_GETFL)"); 97 | close(fd); 98 | return REDIS_ERR; 99 | } 100 | 101 | if (blocking) 102 | flags &= ~O_NONBLOCK; 103 | else 104 | flags |= O_NONBLOCK; 105 | 106 | if (fcntl(fd, F_SETFL, flags) == -1) { 107 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(F_SETFL)"); 108 | close(fd); 109 | return REDIS_ERR; 110 | } 111 | return REDIS_OK; 112 | } 113 | 114 | static int redisSetTcpNoDelay(redisContext *c, int fd) { 115 | int yes = 1; 116 | if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) == -1) { 117 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(TCP_NODELAY)"); 118 | close(fd); 119 | return REDIS_ERR; 120 | } 121 | return REDIS_OK; 122 | } 123 | 124 | static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *timeout) { 125 | struct timeval to; 126 | struct timeval *toptr = NULL; 127 | fd_set wfd; 128 | 129 | /* Only use timeout when not NULL. */ 130 | if (timeout != NULL) { 131 | to = *timeout; 132 | toptr = &to; 133 | } 134 | 135 | if (errno == EINPROGRESS) { 136 | FD_ZERO(&wfd); 137 | FD_SET(fd, &wfd); 138 | 139 | if (select(FD_SETSIZE, NULL, &wfd, NULL, toptr) == -1) { 140 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,"select(2)"); 141 | close(fd); 142 | return REDIS_ERR; 143 | } 144 | 145 | if (!FD_ISSET(fd, &wfd)) { 146 | errno = ETIMEDOUT; 147 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL); 148 | close(fd); 149 | return REDIS_ERR; 150 | } 151 | 152 | if (redisCheckSocketError(c, fd) != REDIS_OK) 153 | return REDIS_ERR; 154 | 155 | return REDIS_OK; 156 | } 157 | 158 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL); 159 | close(fd); 160 | return REDIS_ERR; 161 | } 162 | 163 | int redisCheckSocketError(redisContext *c, int fd) { 164 | int err = 0; 165 | socklen_t errlen = sizeof(err); 166 | 167 | if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errlen) == -1) { 168 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,"getsockopt(SO_ERROR)"); 169 | close(fd); 170 | return REDIS_ERR; 171 | } 172 | 173 | if (err) { 174 | errno = err; 175 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL); 176 | close(fd); 177 | return REDIS_ERR; 178 | } 179 | 180 | return REDIS_OK; 181 | } 182 | 183 | int redisContextSetTimeout(redisContext *c, struct timeval tv) { 184 | if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof(tv)) == -1) { 185 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_RCVTIMEO)"); 186 | return REDIS_ERR; 187 | } 188 | if (setsockopt(c->fd,SOL_SOCKET,SO_SNDTIMEO,&tv,sizeof(tv)) == -1) { 189 | __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_SNDTIMEO)"); 190 | return REDIS_ERR; 191 | } 192 | return REDIS_OK; 193 | } 194 | 195 | int redisContextConnectTcp(redisContext *c, const char *addr, int port, struct timeval *timeout) { 196 | int s, rv; 197 | char _port[6]; /* strlen("65535"); */ 198 | struct addrinfo hints, *servinfo, *p; 199 | int blocking = (c->flags & REDIS_BLOCK); 200 | 201 | snprintf(_port, 6, "%d", port); 202 | memset(&hints,0,sizeof(hints)); 203 | hints.ai_family = AF_INET; 204 | hints.ai_socktype = SOCK_STREAM; 205 | 206 | if ((rv = getaddrinfo(addr,_port,&hints,&servinfo)) != 0) { 207 | __redisSetError(c,REDIS_ERR_OTHER,gai_strerror(rv)); 208 | return REDIS_ERR; 209 | } 210 | for (p = servinfo; p != NULL; p = p->ai_next) { 211 | if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == -1) 212 | continue; 213 | 214 | if (redisSetBlocking(c,s,0) != REDIS_OK) 215 | goto error; 216 | if (connect(s,p->ai_addr,p->ai_addrlen) == -1) { 217 | if (errno == EHOSTUNREACH) { 218 | close(s); 219 | continue; 220 | } else if (errno == EINPROGRESS && !blocking) { 221 | /* This is ok. */ 222 | } else { 223 | if (redisContextWaitReady(c,s,timeout) != REDIS_OK) 224 | goto error; 225 | } 226 | } 227 | if (blocking && redisSetBlocking(c,s,1) != REDIS_OK) 228 | goto error; 229 | if (redisSetTcpNoDelay(c,s) != REDIS_OK) 230 | goto error; 231 | 232 | c->fd = s; 233 | c->flags |= REDIS_CONNECTED; 234 | rv = REDIS_OK; 235 | goto end; 236 | } 237 | if (p == NULL) { 238 | char buf[128]; 239 | snprintf(buf,sizeof(buf),"Can't create socket: %s",strerror(errno)); 240 | __redisSetError(c,REDIS_ERR_OTHER,buf); 241 | goto error; 242 | } 243 | 244 | error: 245 | rv = REDIS_ERR; 246 | end: 247 | freeaddrinfo(servinfo); 248 | return rv; // Need to return REDIS_OK if alright 249 | } 250 | 251 | int redisContextConnectUnix(redisContext *c, const char *path, struct timeval *timeout) { 252 | int s; 253 | int blocking = (c->flags & REDIS_BLOCK); 254 | struct sockaddr_un sa; 255 | 256 | if ((s = redisCreateSocket(c,AF_LOCAL)) < 0) 257 | return REDIS_ERR; 258 | if (redisSetBlocking(c,s,0) != REDIS_OK) 259 | return REDIS_ERR; 260 | 261 | sa.sun_family = AF_LOCAL; 262 | strncpy(sa.sun_path,path,sizeof(sa.sun_path)-1); 263 | if (connect(s, (struct sockaddr*)&sa, sizeof(sa)) == -1) { 264 | if (errno == EINPROGRESS && !blocking) { 265 | /* This is ok. */ 266 | } else { 267 | if (redisContextWaitReady(c,s,timeout) != REDIS_OK) 268 | return REDIS_ERR; 269 | } 270 | } 271 | 272 | /* Reset socket to be blocking after connect(2). */ 273 | if (blocking && redisSetBlocking(c,s,1) != REDIS_OK) 274 | return REDIS_ERR; 275 | 276 | c->fd = s; 277 | c->flags |= REDIS_CONNECTED; 278 | return REDIS_OK; 279 | } 280 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/net.h: -------------------------------------------------------------------------------- 1 | /* Extracted from anet.c to work properly with Hiredis error reporting. 2 | * 3 | * Copyright (c) 2006-2011, Salvatore Sanfilippo 4 | * Copyright (c) 2010-2011, Pieter Noordhuis 5 | * 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * * Neither the name of Redis nor the names of its contributors may be used 17 | * to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __NET_H 34 | #define __NET_H 35 | 36 | #include "hiredis.h" 37 | 38 | #if defined(__sun) 39 | #define AF_LOCAL AF_UNIX 40 | #endif 41 | 42 | int redisCheckSocketError(redisContext *c, int fd); 43 | int redisContextSetTimeout(redisContext *c, struct timeval tv); 44 | int redisContextConnectTcp(redisContext *c, const char *addr, int port, struct timeval *timeout); 45 | int redisContextConnectUnix(redisContext *c, const char *path, struct timeval *timeout); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/net.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/hiredis/deps/hiredis/net.o -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/sds.h: -------------------------------------------------------------------------------- 1 | /* SDSLib, A C dynamic strings library 2 | * 3 | * Copyright (c) 2006-2010, Salvatore Sanfilippo 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef __SDS_H 32 | #define __SDS_H 33 | 34 | #include 35 | #include 36 | 37 | typedef char *sds; 38 | 39 | struct sdshdr { 40 | int len; 41 | int free; 42 | char buf[]; 43 | }; 44 | 45 | static inline size_t sdslen(const sds s) { 46 | struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); 47 | return sh->len; 48 | } 49 | 50 | static inline size_t sdsavail(const sds s) { 51 | struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); 52 | return sh->free; 53 | } 54 | 55 | sds sdsnewlen(const void *init, size_t initlen); 56 | sds sdsnew(const char *init); 57 | sds sdsempty(void); 58 | size_t sdslen(const sds s); 59 | sds sdsdup(const sds s); 60 | void sdsfree(sds s); 61 | size_t sdsavail(sds s); 62 | sds sdsgrowzero(sds s, size_t len); 63 | sds sdscatlen(sds s, const void *t, size_t len); 64 | sds sdscat(sds s, const char *t); 65 | sds sdscpylen(sds s, char *t, size_t len); 66 | sds sdscpy(sds s, char *t); 67 | 68 | sds sdscatvprintf(sds s, const char *fmt, va_list ap); 69 | #ifdef __GNUC__ 70 | sds sdscatprintf(sds s, const char *fmt, ...) 71 | __attribute__((format(printf, 2, 3))); 72 | #else 73 | sds sdscatprintf(sds s, const char *fmt, ...); 74 | #endif 75 | 76 | sds sdstrim(sds s, const char *cset); 77 | sds sdsrange(sds s, int start, int end); 78 | void sdsupdatelen(sds s); 79 | int sdscmp(sds s1, sds s2); 80 | sds *sdssplitlen(char *s, int len, char *sep, int seplen, int *count); 81 | void sdsfreesplitres(sds *tokens, int count); 82 | void sdstolower(sds s); 83 | void sdstoupper(sds s); 84 | sds sdsfromlonglong(long long value); 85 | sds sdscatrepr(sds s, char *p, size_t len); 86 | sds *sdssplitargs(char *line, int *argc); 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /node_modules/hiredis/deps/hiredis/sds.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/hiredis/deps/hiredis/sds.o -------------------------------------------------------------------------------- /node_modules/hiredis/hiredis.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "reader.h" 4 | 5 | using namespace v8; 6 | 7 | extern "C" { 8 | static void init (Handle target) { 9 | HandleScope scope; 10 | hiredis::Reader::Initialize(target); 11 | } 12 | NODE_MODULE(hiredis,init); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /node_modules/hiredis/hiredis.js: -------------------------------------------------------------------------------- 1 | var hiredis, net = require("net"); 2 | 3 | try { 4 | hiredis = require('./build/Release/hiredis'); 5 | } catch (e) { 6 | hiredis = require('./build/default/hiredis'); 7 | } 8 | 9 | exports.Reader = hiredis.Reader; 10 | exports.createConnection = function(port, host) { 11 | var s = net.createConnection(port || 6379, host); 12 | var r = new hiredis.Reader(); 13 | var _write = s.write; 14 | 15 | s.write = function() { 16 | var i, args = arguments; 17 | _write.call(s, "*" + args.length + "\r\n"); 18 | for (i = 0; i < args.length; i++) { 19 | var arg = args[i]; 20 | _write.call(s, "$" + arg.length + "\r\n" + arg + "\r\n"); 21 | } 22 | } 23 | 24 | s.on("data", function(data) { 25 | var reply; 26 | r.feed(data); 27 | try { 28 | while((reply = r.get()) !== undefined) 29 | s.emit("reply", reply); 30 | } catch(err) { 31 | r = null; 32 | s.emit("error", err); 33 | s.destroy(); 34 | } 35 | }); 36 | 37 | return s; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /node_modules/hiredis/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hiredis", 3 | "description": "Wrapper for reply processing code in hiredis", 4 | "version": "0.1.14", 5 | "homepage": "http://github.com/pietern/hiredis-node", 6 | "author": { 7 | "name": "Pieter Noordhuis", 8 | "email": "pcnoordhuis@gmail.com" 9 | }, 10 | "main": "hiredis", 11 | "directories": { 12 | "lib": "." 13 | }, 14 | "scripts": { 15 | "preinstall": "make || gmake", 16 | "test": "node test/reader.js" 17 | }, 18 | "engines": { 19 | "node": "*" 20 | }, 21 | "readme": "ERROR: No README.md file found!", 22 | "_id": "hiredis@0.1.14", 23 | "_from": "hiredis" 24 | } 25 | -------------------------------------------------------------------------------- /node_modules/hiredis/parser_bench.js: -------------------------------------------------------------------------------- 1 | var hiredis = require("./hiredis"); 2 | 3 | 4 | function go(num) { 5 | var parser = new hiredis.Reader(); 6 | 7 | var i, j; 8 | var n = 10, m = 0; 9 | 10 | var feed = "*" + n + "\r\n"; 11 | for (i = 0; i < n; i++) { 12 | if (m > 1) { 13 | feed += "*" + m + "\r\n"; 14 | for (j = 0; j < m; j++) { 15 | feed += "$10\r\nxxxxxxxxxx\r\n"; 16 | } 17 | } else { 18 | feed += "$10\r\nxxxxxxxxxx\r\n"; 19 | } 20 | } 21 | 22 | var t1 = new Date, t2; 23 | for (i = 0; i < num; i++) { 24 | parser.feed(feed); 25 | parser.get(); 26 | } 27 | 28 | t2 = new Date; 29 | console.log("" + num + " took: " + (t2-t1) + "ms"); 30 | } 31 | 32 | 33 | var stdin = process.openStdin(); 34 | stdin.on('data', function(chunk) { 35 | go(parseInt(chunk)); 36 | }); 37 | 38 | -------------------------------------------------------------------------------- /node_modules/hiredis/reader.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "reader.h" 7 | 8 | using namespace hiredis; 9 | 10 | static void *tryParentize(const redisReadTask *task, const Local &v) { 11 | Reader *r = reinterpret_cast(task->privdata); 12 | size_t pidx, vidx; 13 | 14 | if (task->parent != NULL) { 15 | pidx = (size_t)task->parent->obj; 16 | assert(pidx > 0 && pidx < 3); 17 | 18 | /* When there is a parent, it should be an array. */ 19 | assert(r->handle[pidx]->IsArray()); 20 | Local parent = Local::Cast(r->handle[pidx]->ToObject()); 21 | parent->Set(task->idx,v); 22 | 23 | /* Store the handle when this is an inner array. Otherwise, hiredis 24 | * doesn't care about the return value as long as the value is set in 25 | * its parent array. */ 26 | vidx = pidx+1; 27 | if (v->IsArray()) { 28 | r->handle[vidx].Dispose(); 29 | r->handle[vidx].Clear(); 30 | r->handle[vidx] = Persistent::New(v); 31 | return (void*)vidx; 32 | } else { 33 | /* Return value doesn't matter for inner value, as long as it is 34 | * not NULL (which means OOM for hiredis). */ 35 | return (void*)0xcafef00d; 36 | } 37 | } else { 38 | /* There is no parent, so this value is the root object. */ 39 | r->handle[1] = Persistent::New(v); 40 | return (void*)1; 41 | } 42 | } 43 | 44 | static void *createArray(const redisReadTask *task, int size) { 45 | Local v(Array::New(size)); 46 | return tryParentize(task,v); 47 | } 48 | 49 | static void *createString(const redisReadTask *task, char *str, size_t len) { 50 | Reader *r = reinterpret_cast(task->privdata); 51 | Local v(r->createString(str,len)); 52 | 53 | if (task->type == REDIS_REPLY_ERROR) 54 | v = Exception::Error(v->ToString()); 55 | return tryParentize(task,v); 56 | } 57 | 58 | static void *createInteger(const redisReadTask *task, long long value) { 59 | Local v(Number::New(value)); 60 | return tryParentize(task,v); 61 | } 62 | 63 | static void *createNil(const redisReadTask *task) { 64 | Local v(Local::New(Null())); 65 | return tryParentize(task,v); 66 | } 67 | 68 | static redisReplyObjectFunctions v8ReplyFunctions = { 69 | createString, 70 | createArray, 71 | createInteger, 72 | createNil, 73 | NULL /* No free function: cleanup is done in Reader::Get. */ 74 | }; 75 | 76 | Reader::Reader(bool return_buffers) : 77 | return_buffers(return_buffers) 78 | { 79 | reader = redisReaderCreate(); 80 | reader->fn = &v8ReplyFunctions; 81 | reader->privdata = this; 82 | 83 | #if NODE_VERSION_AT_LEAST(0,3,0) 84 | if (return_buffers) { 85 | Local global = Context::GetCurrent()->Global(); 86 | Local bv = global->Get(String::NewSymbol("Buffer")); 87 | assert(bv->IsFunction()); 88 | Local bf = Local::Cast(bv); 89 | buffer_fn = Persistent::New(bf); 90 | 91 | buffer_pool_length = 8*1024; /* Same as node */ 92 | buffer_pool_offset = 0; 93 | 94 | Buffer *b = Buffer::New(buffer_pool_length); 95 | buffer_pool = Persistent::New(b->handle_); 96 | } 97 | #endif 98 | } 99 | 100 | Reader::~Reader() { 101 | redisReaderFree(reader); 102 | } 103 | 104 | /* Don't use a HandleScope here, so the objects are created within the scope of 105 | * the caller (Reader::Get) and we don't have to the pay the overhead. */ 106 | Local Reader::createString(char *str, size_t len) { 107 | if (return_buffers) { 108 | #if NODE_VERSION_AT_LEAST(0,3,0) 109 | if (len > buffer_pool_length) { 110 | Buffer *b = Buffer::New(str,len); 111 | return Local::New(b->handle_); 112 | } else { 113 | return createBufferFromPool(str,len); 114 | } 115 | #else 116 | Buffer *b = Buffer::New(len); 117 | memcpy(b->data(),str,len); 118 | return Local::New(b->handle_); 119 | #endif 120 | } else { 121 | return String::New(str,len); 122 | } 123 | } 124 | 125 | #if NODE_VERSION_AT_LEAST(0,3,0) 126 | Local Reader::createBufferFromPool(char *str, size_t len) { 127 | HandleScope scope; 128 | Local argv[3]; 129 | Local instance; 130 | 131 | assert(len <= buffer_pool_length); 132 | if (buffer_pool_length - buffer_pool_offset < len) { 133 | Buffer *b = Buffer::New(buffer_pool_length); 134 | buffer_pool.Dispose(); 135 | buffer_pool = Persistent::New(b->handle_); 136 | buffer_pool_offset = 0; 137 | } 138 | 139 | memcpy(Buffer::Data(buffer_pool)+buffer_pool_offset,str,len); 140 | 141 | argv[0] = Local::New(buffer_pool); 142 | argv[1] = Integer::New(len); 143 | argv[2] = Integer::New(buffer_pool_offset); 144 | instance = buffer_fn->NewInstance(3,argv); 145 | buffer_pool_offset += len; 146 | return scope.Close(instance); 147 | } 148 | #endif 149 | 150 | Handle Reader::New(const Arguments& args) { 151 | HandleScope scope; 152 | bool return_buffers = false; 153 | 154 | if (args.Length() > 0 && args[0]->IsObject()) { 155 | Local bv = args[0]->ToObject()->Get(String::New("return_buffers")); 156 | if (bv->IsBoolean()) 157 | return_buffers = bv->ToBoolean()->Value(); 158 | } 159 | 160 | Reader *r = new Reader(return_buffers); 161 | r->Wrap(args.This()); 162 | return scope.Close(args.This()); 163 | } 164 | 165 | void Reader::Initialize(Handle target) { 166 | HandleScope scope; 167 | 168 | Local t = FunctionTemplate::New(New); 169 | t->InstanceTemplate()->SetInternalFieldCount(1); 170 | NODE_SET_PROTOTYPE_METHOD(t, "feed", Feed); 171 | NODE_SET_PROTOTYPE_METHOD(t, "get", Get); 172 | target->Set(String::NewSymbol("Reader"), t->GetFunction()); 173 | } 174 | 175 | Handle Reader::Feed(const Arguments &args) { 176 | HandleScope scope; 177 | Reader *r = ObjectWrap::Unwrap(args.This()); 178 | 179 | if (args.Length() == 0) { 180 | return ThrowException(Exception::Error( 181 | String::New("First argument must be a string or buffer"))); 182 | } else { 183 | if (Buffer::HasInstance(args[0])) { 184 | Local buffer_object = args[0]->ToObject(); 185 | char *data; 186 | size_t length; 187 | 188 | #if NODE_VERSION_AT_LEAST(0,3,0) 189 | data = Buffer::Data(buffer_object); 190 | length = Buffer::Length(buffer_object); 191 | #else 192 | Buffer *buffer = ObjectWrap::Unwrap(buffer_object); 193 | data = buffer->data(); 194 | length = buffer->length(); 195 | #endif 196 | 197 | /* Can't handle OOM for now. */ 198 | assert(redisReaderFeed(r->reader, data, length) == REDIS_OK); 199 | } else if (args[0]->IsString()) { 200 | String::Utf8Value str(args[0]->ToString()); 201 | redisReplyReaderFeed(r->reader, *str, str.length()); 202 | } else { 203 | return ThrowException(Exception::Error( 204 | String::New("Invalid argument"))); 205 | } 206 | } 207 | 208 | return args.This(); 209 | } 210 | 211 | Handle Reader::Get(const Arguments &args) { 212 | HandleScope scope; 213 | Reader *r = ObjectWrap::Unwrap(args.This()); 214 | void *index = NULL; 215 | Local reply; 216 | int i; 217 | 218 | if (redisReaderGetReply(r->reader,&index) == REDIS_OK) { 219 | if (index == 0) { 220 | return Undefined(); 221 | } else { 222 | /* Complete replies should always have a root object at index 1. */ 223 | assert((unsigned size_t)index == 1); 224 | reply = Local::New(r->handle[1]); 225 | 226 | /* Dispose and clear used handles. */ 227 | for (i = 1; i < 3; i++) { 228 | r->handle[i].Dispose(); 229 | r->handle[i].Clear(); 230 | } 231 | } 232 | } else { 233 | return ThrowException(Exception::Error(String::New(r->reader->errstr))); 234 | } 235 | 236 | return scope.Close(reply); 237 | } 238 | 239 | -------------------------------------------------------------------------------- /node_modules/hiredis/reader.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | namespace hiredis { 7 | 8 | using namespace v8; 9 | using namespace node; 10 | 11 | class Reader : ObjectWrap { 12 | public: 13 | Reader(bool); 14 | ~Reader(); 15 | 16 | static void Initialize(Handle target); 17 | static Handle New(const Arguments& args); 18 | static Handle Feed(const Arguments &args); 19 | static Handle Get(const Arguments &args); 20 | 21 | /* Objects created by the reply object functions need to get back to the 22 | * reader when the reply is requested via Reader::Get(). Keep temporary 23 | * objects in this handle. Use an array of handles because replies may 24 | * include nested multi bulks and child-elements need to be added to the 25 | * right respective parent. handle[0] will be unused, so the real index of 26 | * an object in this array can be returned from the reply object functions. 27 | * The returned value needs to be non-zero to distinguish complete replies 28 | * from incomplete replies. These are persistent handles because 29 | * Reader::Get might not return a full reply and the objects need to be 30 | * kept around for subsequent calls. */ 31 | Persistent handle[3]; 32 | 33 | /* Helper function to create string/buffer objects. */ 34 | Local createString(char *str, size_t len); 35 | 36 | private: 37 | redisReader *reader; 38 | 39 | /* Determines whether to return strings or buffers for single line and bulk 40 | * replies. This defaults to false, so strings are returned by default. */ 41 | bool return_buffers; 42 | 43 | #if NODE_VERSION_AT_LEAST(0,3,0) 44 | /* Use a buffer pool like the fast buffers. */ 45 | Local createBufferFromPool(char *str, size_t len); 46 | Persistent buffer_fn; 47 | Persistent buffer_pool; 48 | size_t buffer_pool_length; 49 | size_t buffer_pool_offset; 50 | #endif 51 | 52 | }; 53 | 54 | }; 55 | 56 | -------------------------------------------------------------------------------- /node_modules/hiredis/test/reader.js: -------------------------------------------------------------------------------- 1 | var assert = require("assert"), 2 | hiredis = require("../hiredis"); 3 | 4 | /* Monkey-patch Buffer.isBuffer on 0.3.1 */ 5 | if (process.versions.node == "0.3.1") { 6 | var SlowBuffer = process.binding('buffer').SlowBuffer; 7 | Buffer.isBuffer = function isBuffer(b) { 8 | return b instanceof Buffer || b instanceof SlowBuffer; 9 | }; 10 | } 11 | 12 | var passed = 0; 13 | var failed = 0; 14 | 15 | function test(str, fn) { 16 | try { 17 | fn(); 18 | passed++; 19 | } catch (err) { 20 | console.log("\x1B[1;31m" + str + " failed!\x1B[0m"); 21 | console.log(err.stack + "\n"); 22 | failed++; 23 | } 24 | } 25 | 26 | test("CreateReader", function() { 27 | var reader = new hiredis.Reader(); 28 | assert.notEqual(reader, null); 29 | }); 30 | 31 | test("StatusReply", function() { 32 | var reader = new hiredis.Reader(); 33 | reader.feed("+OK\r\n"); 34 | assert.equal("OK", reader.get()); 35 | }); 36 | 37 | test("StatusReplyAsBuffer", function() { 38 | var reader = new hiredis.Reader({ return_buffers: true }); 39 | reader.feed("+OK\r\n"); 40 | var reply = reader.get(); 41 | assert.ok(Buffer.isBuffer(reply)); 42 | assert.equal("OK", reply.toString()); 43 | }); 44 | 45 | test("IntegerReply", function() { 46 | var reader = new hiredis.Reader(); 47 | reader.feed(":1\r\n"); 48 | assert.equal(1, reader.get()); 49 | }); 50 | 51 | // This test fails since v8 doesn't to 64-bit integers... 52 | test("LargeIntegerReply", function() { 53 | var reader = new hiredis.Reader(); 54 | reader.feed(":9223372036854775807\r\n"); 55 | assert.equal("9223372036854775807", String(reader.get())); 56 | }); 57 | 58 | test("ErrorReply", function() { 59 | var reader = new hiredis.Reader(); 60 | reader.feed("-ERR foo\r\n"); 61 | var reply = reader.get(); 62 | assert.equal(Error, reply.constructor); 63 | assert.equal("ERR foo", reply.message); 64 | }); 65 | 66 | test("ErrorReplyWithReturnBuffers", function() { 67 | var reader = new hiredis.Reader({ return_buffers: true }); 68 | reader.feed("-ERR foo\r\n"); 69 | var reply = reader.get(); 70 | assert.equal(Error, reply.constructor); 71 | assert.equal("ERR foo", reply.message); 72 | }); 73 | 74 | test("NullBulkReply", function() { 75 | var reader = new hiredis.Reader(); 76 | reader.feed("$-1\r\n"); 77 | assert.equal(null, reader.get()); 78 | }); 79 | 80 | test("EmptyBulkReply", function() { 81 | var reader = new hiredis.Reader(); 82 | reader.feed("$0\r\n\r\n"); 83 | assert.equal("", reader.get()); 84 | }); 85 | 86 | test("BulkReply", function() { 87 | var reader = new hiredis.Reader(); 88 | reader.feed("$3\r\nfoo\r\n"); 89 | assert.equal("foo", reader.get()); 90 | }); 91 | 92 | test("BulkReplyAsBuffer", function() { 93 | var reader = new hiredis.Reader({ return_buffers: true }); 94 | reader.feed("$3\r\nfoo\r\n"); 95 | var reply = reader.get(); 96 | assert.ok(Buffer.isBuffer(reply)); 97 | assert.equal("foo", reply.toString()); 98 | }); 99 | 100 | test("BulkReplyWithEncoding", function() { 101 | var reader = new hiredis.Reader(); 102 | reader.feed("$" + Buffer.byteLength("☃") + "\r\n☃\r\n"); 103 | assert.equal("☃", reader.get()); 104 | }); 105 | 106 | test("NullMultiBulkReply", function() { 107 | var reader = new hiredis.Reader(); 108 | reader.feed("*-1\r\n"); 109 | assert.equal(null, reader.get()); 110 | }); 111 | 112 | test("EmptyMultiBulkReply", function() { 113 | var reader = new hiredis.Reader(); 114 | reader.feed("*0\r\n"); 115 | assert.deepEqual([], reader.get()); 116 | }); 117 | 118 | test("MultiBulkReply", function() { 119 | var reader = new hiredis.Reader(); 120 | reader.feed("*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n"); 121 | assert.deepEqual(["foo", "bar"], reader.get()); 122 | }); 123 | 124 | test("NestedMultiBulkReply", function() { 125 | var reader = new hiredis.Reader(); 126 | reader.feed("*2\r\n*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$3\r\nqux\r\n"); 127 | assert.deepEqual([["foo", "bar"], "qux"], reader.get()); 128 | }); 129 | 130 | test("MultiBulkReplyWithNonStringValues", function() { 131 | var reader = new hiredis.Reader(); 132 | reader.feed("*3\r\n:1\r\n+OK\r\n$-1\r\n"); 133 | assert.deepEqual([1, "OK", null], reader.get()); 134 | }); 135 | 136 | test("FeedWithBuffer", function() { 137 | var reader = new hiredis.Reader(); 138 | reader.feed(new Buffer("$3\r\nfoo\r\n")); 139 | assert.deepEqual("foo", reader.get()); 140 | }); 141 | 142 | test("UndefinedReplyOnIncompleteFeed", function() { 143 | var reader = new hiredis.Reader(); 144 | reader.feed("$3\r\nfoo"); 145 | assert.deepEqual(undefined, reader.get()); 146 | reader.feed("\r\n"); 147 | assert.deepEqual("foo", reader.get()); 148 | }); 149 | 150 | test("Leaks", function(beforeExit) { 151 | /* The "leaks" utility is only available on OSX. */ 152 | if (process.platform != "darwin") return; 153 | 154 | var done = 0; 155 | var leaks = require('child_process').spawn("leaks", [process.pid]); 156 | leaks.stdout.on("data", function(data) { 157 | var str = data.toString(); 158 | var notice = "Node 0.2.5 always leaks 16 bytes (this is " + process.versions.node + ")"; 159 | var matches; 160 | if ((matches = /(\d+) leaks?/i.exec(str)) != null) { 161 | if (parseInt(matches[1]) > 0) { 162 | console.log(str); 163 | console.log('\x1B[31mNotice: ' + notice + '\x1B[0m'); 164 | } 165 | } 166 | done = 1; 167 | }); 168 | 169 | process.on('exit', function() { 170 | assert.ok(done, "Leaks test should have completed"); 171 | }); 172 | }); 173 | -------------------------------------------------------------------------------- /node_modules/hiredis/wscript: -------------------------------------------------------------------------------- 1 | def set_options(opt): 2 | opt.tool_options("compiler_cxx") 3 | 4 | def configure(conf): 5 | conf.check_tool("compiler_cxx") 6 | conf.check_tool("node_addon") 7 | conf.env.append_unique('CXXFLAGS', ['-Wall', '-O3']) 8 | conf.env['LIBPATH_HIREDIS'] = '../deps/hiredis' 9 | conf.env['LIB_HIREDIS'] = 'hiredis' 10 | 11 | def build(bld): 12 | ext = bld.new_task_gen("cxx", "shlib", "node_addon", uselib="HIREDIS") 13 | ext.cxxflags = ["-I../deps", "-g", "-Wall"] 14 | ext.source = "hiredis.cc reader.cc" 15 | ext.target = "hiredis" 16 | -------------------------------------------------------------------------------- /node_modules/redis/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /node_modules/redis/benches/buffer_bench.js: -------------------------------------------------------------------------------- 1 | var source = new Buffer(100), 2 | dest = new Buffer(100), i, j, k, tmp, count = 1000000, bytes = 100; 3 | 4 | for (i = 99 ; i >= 0 ; i--) { 5 | source[i] = 120; 6 | } 7 | 8 | var str = "This is a nice String.", 9 | buf = new Buffer("This is a lovely Buffer."); 10 | 11 | var start = new Date(); 12 | for (i = count * 100; i > 0 ; i--) { 13 | if (Buffer.isBuffer(str)) {} 14 | } 15 | var end = new Date(); 16 | console.log("Buffer.isBuffer(str) " + (end - start) + " ms"); 17 | 18 | var start = new Date(); 19 | for (i = count * 100; i > 0 ; i--) { 20 | if (Buffer.isBuffer(buf)) {} 21 | } 22 | var end = new Date(); 23 | console.log("Buffer.isBuffer(buf) " + (end - start) + " ms"); 24 | 25 | var start = new Date(); 26 | for (i = count * 100; i > 0 ; i--) { 27 | if (str instanceof Buffer) {} 28 | } 29 | var end = new Date(); 30 | console.log("str instanceof Buffer " + (end - start) + " ms"); 31 | 32 | var start = new Date(); 33 | for (i = count * 100; i > 0 ; i--) { 34 | if (buf instanceof Buffer) {} 35 | } 36 | var end = new Date(); 37 | console.log("buf instanceof Buffer " + (end - start) + " ms"); 38 | 39 | for (i = bytes ; i > 0 ; i --) { 40 | var start = new Date(); 41 | for (j = count ; j > 0; j--) { 42 | tmp = source.toString("ascii", 0, bytes); 43 | } 44 | var end = new Date(); 45 | console.log("toString() " + i + " bytes " + (end - start) + " ms"); 46 | } 47 | 48 | for (i = bytes ; i > 0 ; i --) { 49 | var start = new Date(); 50 | for (j = count ; j > 0; j--) { 51 | tmp = ""; 52 | for (k = 0; k <= i ; k++) { 53 | tmp += String.fromCharCode(source[k]); 54 | } 55 | } 56 | var end = new Date(); 57 | console.log("manual string " + i + " bytes " + (end - start) + " ms"); 58 | } 59 | 60 | for (i = bytes ; i > 0 ; i--) { 61 | var start = new Date(); 62 | for (j = count ; j > 0 ; j--) { 63 | for (k = i ; k > 0 ; k--) { 64 | dest[k] = source[k]; 65 | } 66 | } 67 | var end = new Date(); 68 | console.log("Manual copy " + i + " bytes " + (end - start) + " ms"); 69 | } 70 | 71 | for (i = bytes ; i > 0 ; i--) { 72 | var start = new Date(); 73 | for (j = count ; j > 0 ; j--) { 74 | for (k = i ; k > 0 ; k--) { 75 | dest[k] = 120; 76 | } 77 | } 78 | var end = new Date(); 79 | console.log("Direct assignment " + i + " bytes " + (end - start) + " ms"); 80 | } 81 | 82 | for (i = bytes ; i > 0 ; i--) { 83 | var start = new Date(); 84 | for (j = count ; j > 0 ; j--) { 85 | source.copy(dest, 0, 0, i); 86 | } 87 | var end = new Date(); 88 | console.log("Buffer.copy() " + i + " bytes " + (end - start) + " ms"); 89 | } 90 | -------------------------------------------------------------------------------- /node_modules/redis/benches/hiredis_parser.js: -------------------------------------------------------------------------------- 1 | var Parser = require('../lib/parser/hiredis').Parser; 2 | var assert = require('assert'); 3 | 4 | /* 5 | This test makes sure that exceptions thrown inside of "reply" event handlers 6 | are not trapped and mistakenly emitted as parse errors. 7 | */ 8 | (function testExecuteDoesNotCatchReplyCallbackExceptions() { 9 | var parser = new Parser(); 10 | var replies = [{}]; 11 | 12 | parser.reader = { 13 | feed: function() {}, 14 | get: function() { 15 | return replies.shift(); 16 | } 17 | }; 18 | 19 | var emittedError = false; 20 | var caughtException = false; 21 | 22 | parser 23 | .on('error', function() { 24 | emittedError = true; 25 | }) 26 | .on('reply', function() { 27 | throw new Error('bad'); 28 | }); 29 | 30 | try { 31 | parser.execute(); 32 | } catch (err) { 33 | caughtException = true; 34 | } 35 | 36 | assert.equal(caughtException, true); 37 | assert.equal(emittedError, false); 38 | })(); 39 | -------------------------------------------------------------------------------- /node_modules/redis/benches/re_sub_test.js: -------------------------------------------------------------------------------- 1 | var client = require('../index').createClient() 2 | , client2 = require('../index').createClient() 3 | , assert = require('assert'); 4 | 5 | client.once('subscribe', function (channel, count) { 6 | client.unsubscribe('x'); 7 | client.subscribe('x', function () { 8 | client.quit(); 9 | client2.quit(); 10 | }); 11 | client2.publish('x', 'hi'); 12 | }); 13 | 14 | client.subscribe('x'); 15 | -------------------------------------------------------------------------------- /node_modules/redis/benches/reconnect_test.js: -------------------------------------------------------------------------------- 1 | var redis = require("../index").createClient(null, null, { 2 | // max_attempts: 4 3 | }); 4 | 5 | redis.on("error", function (err) { 6 | console.log("Redis says: " + err); 7 | }); 8 | 9 | redis.on("ready", function () { 10 | console.log("Redis ready."); 11 | }); 12 | 13 | redis.on("reconnecting", function (arg) { 14 | console.log("Redis reconnecting: " + JSON.stringify(arg)); 15 | }); 16 | redis.on("connect", function () { 17 | console.log("Redis connected."); 18 | }); 19 | 20 | setInterval(function () { 21 | var now = Date.now(); 22 | redis.set("now", now, function (err, res) { 23 | if (err) { 24 | console.log(now + " Redis reply error: " + err); 25 | } else { 26 | console.log(now + " Redis reply: " + res); 27 | } 28 | }); 29 | }, 100); 30 | -------------------------------------------------------------------------------- /node_modules/redis/benches/stress/codec.js: -------------------------------------------------------------------------------- 1 | var json = { 2 | encode: JSON.stringify, 3 | decode: JSON.parse 4 | }; 5 | 6 | var MsgPack = require('node-msgpack'); 7 | msgpack = { 8 | encode: MsgPack.pack, 9 | decode: function(str) { return MsgPack.unpack(new Buffer(str)); } 10 | }; 11 | 12 | bison = require('bison'); 13 | 14 | module.exports = json; 15 | //module.exports = msgpack; 16 | //module.exports = bison; 17 | -------------------------------------------------------------------------------- /node_modules/redis/benches/stress/pubsub/pub.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var freemem = require('os').freemem; 4 | var profiler = require('v8-profiler'); 5 | var codec = require('../codec'); 6 | 7 | var sent = 0; 8 | 9 | var pub = require('redis').createClient(null, null, { 10 | //command_queue_high_water: 5, 11 | //command_queue_low_water: 1 12 | }) 13 | .on('ready', function() { 14 | this.emit('drain'); 15 | }) 16 | .on('drain', function() { 17 | process.nextTick(exec); 18 | }); 19 | 20 | var payload = '1'; for (var i = 0; i < 12; ++i) payload += payload; 21 | console.log('Message payload length', payload.length); 22 | 23 | function exec() { 24 | pub.publish('timeline', codec.encode({ foo: payload })); 25 | ++sent; 26 | if (!pub.should_buffer) { 27 | process.nextTick(exec); 28 | } 29 | } 30 | 31 | profiler.takeSnapshot('s_0'); 32 | 33 | exec(); 34 | 35 | setInterval(function() { 36 | profiler.takeSnapshot('s_' + sent); 37 | console.error('sent', sent, 'free', freemem(), 'cmdqlen', pub.command_queue.length, 'offqlen', pub.offline_queue.length); 38 | }, 2000); 39 | -------------------------------------------------------------------------------- /node_modules/redis/benches/stress/pubsub/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | node server.js & 3 | node server.js & 4 | node server.js & 5 | node server.js & 6 | node server.js & 7 | node server.js & 8 | node server.js & 9 | node server.js & 10 | node --debug pub.js 11 | -------------------------------------------------------------------------------- /node_modules/redis/benches/stress/pubsub/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var freemem = require('os').freemem; 4 | var codec = require('../codec'); 5 | 6 | var id = Math.random(); 7 | var recv = 0; 8 | 9 | var sub = require('redis').createClient() 10 | .on('ready', function() { 11 | this.subscribe('timeline'); 12 | }) 13 | .on('message', function(channel, message) { 14 | var self = this; 15 | if (message) { 16 | message = codec.decode(message); 17 | ++recv; 18 | } 19 | }); 20 | 21 | setInterval(function() { 22 | console.error('id', id, 'received', recv, 'free', freemem()); 23 | }, 2000); 24 | -------------------------------------------------------------------------------- /node_modules/redis/benches/stress/rpushblpop/pub.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var freemem = require('os').freemem; 4 | //var profiler = require('v8-profiler'); 5 | var codec = require('../codec'); 6 | 7 | var sent = 0; 8 | 9 | var pub = require('redis').createClient(null, null, { 10 | //command_queue_high_water: 5, 11 | //command_queue_low_water: 1 12 | }) 13 | .on('ready', function() { 14 | this.del('timeline'); 15 | this.emit('drain'); 16 | }) 17 | .on('drain', function() { 18 | process.nextTick(exec); 19 | }); 20 | 21 | var payload = '1'; for (var i = 0; i < 12; ++i) payload += payload; 22 | console.log('Message payload length', payload.length); 23 | 24 | function exec() { 25 | pub.rpush('timeline', codec.encode({ foo: payload })); 26 | ++sent; 27 | if (!pub.should_buffer) { 28 | process.nextTick(exec); 29 | } 30 | } 31 | 32 | //profiler.takeSnapshot('s_0'); 33 | 34 | exec(); 35 | 36 | setInterval(function() { 37 | //var ss = profiler.takeSnapshot('s_' + sent); 38 | //console.error(ss.stringify()); 39 | pub.llen('timeline', function(err, result) { 40 | console.error('sent', sent, 'free', freemem(), 41 | 'cmdqlen', pub.command_queue.length, 'offqlen', pub.offline_queue.length, 42 | 'llen', result 43 | ); 44 | }); 45 | }, 2000); 46 | 47 | /*setTimeout(function() { 48 | process.exit(); 49 | }, 30000);*/ 50 | -------------------------------------------------------------------------------- /node_modules/redis/benches/stress/rpushblpop/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | node server.js & 3 | #node server.js & 4 | #node server.js & 5 | #node server.js & 6 | node --debug pub.js 7 | -------------------------------------------------------------------------------- /node_modules/redis/benches/stress/rpushblpop/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var freemem = require('os').freemem; 4 | var codec = require('../codec'); 5 | 6 | var id = Math.random(); 7 | var recv = 0; 8 | 9 | var cmd = require('redis').createClient(); 10 | var sub = require('redis').createClient() 11 | .on('ready', function() { 12 | this.emit('timeline'); 13 | }) 14 | .on('timeline', function() { 15 | var self = this; 16 | this.blpop('timeline', 0, function(err, result) { 17 | var message = result[1]; 18 | if (message) { 19 | message = codec.decode(message); 20 | ++recv; 21 | } 22 | self.emit('timeline'); 23 | }); 24 | }); 25 | 26 | setInterval(function() { 27 | cmd.llen('timeline', function(err, result) { 28 | console.error('id', id, 'received', recv, 'free', freemem(), 'llen', result); 29 | }); 30 | }, 2000); 31 | -------------------------------------------------------------------------------- /node_modules/redis/benches/stress/speed/00: -------------------------------------------------------------------------------- 1 | # size JSON msgpack bison 2 | 26602 2151.0170848180414 3 | 25542 ? 2842.589272665782 4 | 24835 ? ? 7280.4538397469805 5 | 6104 6985.234528557929 6 | 5045 ? 7217.461392841478 7 | 4341 ? ? 14261.406335354604 8 | 4180 15864.633685636572 9 | 4143 ? 12954.806235781925 10 | 4141 ? ? 44650.70733912719 11 | 75 114227.07313350472 12 | 40 ? 30162.440062810834 13 | 39 ? ? 119815.66013519121 14 | -------------------------------------------------------------------------------- /node_modules/redis/benches/stress/speed/plot: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | gnuplot >size-rate.jpg << _EOF_ 4 | 5 | set terminal png nocrop enhanced font verdana 12 size 640,480 6 | set logscale x 7 | set logscale y 8 | set grid 9 | set xlabel 'Serialized object size, octets' 10 | set ylabel 'decode(encode(obj)) rate, 1/sec' 11 | plot '00' using 1:2 title 'json' smooth bezier, '00' using 1:3 title 'msgpack' smooth bezier, '00' using 1:4 title 'bison' smooth bezier 12 | 13 | _EOF_ 14 | -------------------------------------------------------------------------------- /node_modules/redis/benches/stress/speed/size-rate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/redis/benches/stress/speed/size-rate.png -------------------------------------------------------------------------------- /node_modules/redis/benches/stress/speed/speed.js: -------------------------------------------------------------------------------- 1 | var msgpack = require('node-msgpack'); 2 | var bison = require('bison'); 3 | var codec = { 4 | JSON: { 5 | encode: JSON.stringify, 6 | decode: JSON.parse 7 | }, 8 | msgpack: { 9 | encode: msgpack.pack, 10 | decode: msgpack.unpack 11 | }, 12 | bison: bison 13 | }; 14 | 15 | var obj, l; 16 | 17 | var s = '0'; 18 | for (var i = 0; i < 12; ++i) s += s; 19 | 20 | obj = { 21 | foo: s, 22 | arrrrrr: [{a:1,b:false,c:null,d:1.0}, 1111, 2222, 33333333], 23 | rand: [], 24 | a: s, 25 | ccc: s, 26 | b: s + s + s 27 | }; 28 | for (i = 0; i < 100; ++i) obj.rand.push(Math.random()); 29 | forObj(obj); 30 | 31 | obj = { 32 | foo: s, 33 | arrrrrr: [{a:1,b:false,c:null,d:1.0}, 1111, 2222, 33333333], 34 | rand: [] 35 | }; 36 | for (i = 0; i < 100; ++i) obj.rand.push(Math.random()); 37 | forObj(obj); 38 | 39 | obj = { 40 | foo: s, 41 | arrrrrr: [{a:1,b:false,c:null,d:1.0}, 1111, 2222, 33333333], 42 | rand: [] 43 | }; 44 | forObj(obj); 45 | 46 | obj = { 47 | arrrrrr: [{a:1,b:false,c:null,d:1.0}, 1111, 2222, 33333333], 48 | rand: [] 49 | }; 50 | forObj(obj); 51 | 52 | function run(obj, codec) { 53 | var t1 = Date.now(); 54 | var n = 10000; 55 | for (var i = 0; i < n; ++i) { 56 | codec.decode(l = codec.encode(obj)); 57 | } 58 | var t2 = Date.now(); 59 | //console.log('DONE', n*1000/(t2-t1), 'codecs/sec, length=', l.length); 60 | return [n*1000/(t2-t1), l.length]; 61 | } 62 | 63 | function series(obj, cname, n) { 64 | var rate = 0; 65 | var len = 0; 66 | for (var i = 0; i < n; ++i) { 67 | var r = run(obj, codec[cname]); 68 | rate += r[0]; 69 | len += r[1]; 70 | } 71 | rate /= n; 72 | len /= n; 73 | console.log(cname + ' ' + rate + ' ' + len); 74 | return [rate, len]; 75 | } 76 | 77 | function forObj(obj) { 78 | var r = { 79 | JSON: series(obj, 'JSON', 20), 80 | msgpack: series(obj, 'msgpack', 20), 81 | bison: series(obj, 'bison', 20) 82 | }; 83 | return r; 84 | } 85 | -------------------------------------------------------------------------------- /node_modules/redis/benches/sub_quit_test.js: -------------------------------------------------------------------------------- 1 | var client = require("redis").createClient(), 2 | client2 = require("redis").createClient(); 3 | 4 | client.subscribe("something"); 5 | client.on("subscribe", function (channel, count) { 6 | console.log("Got sub: " + channel); 7 | client.unsubscribe("something"); 8 | }); 9 | 10 | client.on("unsubscribe", function (channel, count) { 11 | console.log("Got unsub: " + channel + ", quitting"); 12 | client.quit(); 13 | }); 14 | 15 | // exercise unsub before sub 16 | client2.unsubscribe("something"); 17 | client2.subscribe("another thing"); 18 | client2.quit(); 19 | -------------------------------------------------------------------------------- /node_modules/redis/changelog.md: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | ## v0.8.2 - November 11, 2012 5 | 6 | Another version bump because 0.8.1 didn't get applied properly for some mysterious reason. 7 | Sorry about that. 8 | 9 | Changed name of "faster" parser to "javascript". 10 | 11 | ## v0.8.1 - September 11, 2012 12 | 13 | Important bug fix for null responses (Jerry Sievert) 14 | 15 | ## v0.8.0 - September 10, 2012 16 | 17 | Many contributed features and fixes, including: 18 | 19 | * Pure JavaScript reply parser that is usually faster than hiredis (Jerry Sievert) 20 | * Remove hiredis as optionalDependency from package.json. It still works if you want it. 21 | * Restore client state on reconnect, including select, subscribe, and monitor. (Ignacio Burgueño) 22 | * Fix idle event (Trae Robrock) 23 | * Many documentation improvements and bug fixes (David Trejo) 24 | 25 | ## v0.7.2 - April 29, 2012 26 | 27 | Many contributed fixes. Thank you, contributors. 28 | 29 | * [GH-190] - pub/sub mode fix (Brian Noguchi) 30 | * [GH-165] - parser selection fix (TEHEK) 31 | * numerous documentation and examples updates 32 | * auth errors emit Errors instead of Strings (David Trejo) 33 | 34 | ## v0.7.1 - November 15, 2011 35 | 36 | Fix regression in reconnect logic. 37 | 38 | Very much need automated tests for reconnection and queue logic. 39 | 40 | ## v0.7.0 - November 14, 2011 41 | 42 | Many contributed fixes. Thanks everybody. 43 | 44 | * [GH-127] - properly re-initialize parser on reconnect 45 | * [GH-136] - handle passing undefined as callback (Ian Babrou) 46 | * [GH-139] - properly handle exceptions thrown in pub/sub event handlers (Felix Geisendörfer) 47 | * [GH-141] - detect closing state on stream error (Felix Geisendörfer) 48 | * [GH-142] - re-select database on reconnection (Jean-Hugues Pinson) 49 | * [GH-146] - add sort example (Maksim Lin) 50 | 51 | Some more goodies: 52 | 53 | * Fix bugs with node 0.6 54 | * Performance improvements 55 | * New version of `multi_bench.js` that tests more realistic scenarios 56 | * [GH-140] - support optional callback for subscribe commands 57 | * Properly flush and error out command queue when connection fails 58 | * Initial work on reconnection thresholds 59 | 60 | ## v0.6.7 - July 30, 2011 61 | 62 | (accidentally skipped v0.6.6) 63 | 64 | Fix and test for [GH-123] 65 | 66 | Passing an Array as as the last argument should expand as users 67 | expect. The old behavior was to coerce the arguments into Strings, 68 | which did surprising things with Arrays. 69 | 70 | ## v0.6.5 - July 6, 2011 71 | 72 | Contributed changes: 73 | 74 | * Support SlowBuffers (Umair Siddique) 75 | * Add Multi to exports (Louis-Philippe Perron) 76 | * Fix for drain event calculation (Vladimir Dronnikov) 77 | 78 | Thanks! 79 | 80 | ## v0.6.4 - June 30, 2011 81 | 82 | Fix bug with optional callbacks for hmset. 83 | 84 | ## v0.6.2 - June 30, 2011 85 | 86 | Bugs fixed: 87 | 88 | * authentication retry while server is loading db (danmaz74) [GH-101] 89 | * command arguments processing issue with arrays 90 | 91 | New features: 92 | 93 | * Auto update of new commands from redis.io (Dave Hoover) 94 | * Performance improvements and backpressure controls. 95 | * Commands now return the true/false value from the underlying socket write(s). 96 | * Implement command_queue high water and low water for more better control of queueing. 97 | 98 | See `examples/backpressure_drain.js` for more information. 99 | 100 | ## v0.6.1 - June 29, 2011 101 | 102 | Add support and tests for Redis scripting through EXEC command. 103 | 104 | Bug fix for monitor mode. (forddg) 105 | 106 | Auto update of new commands from redis.io (Dave Hoover) 107 | 108 | ## v0.6.0 - April 21, 2011 109 | 110 | Lots of bugs fixed. 111 | 112 | * connection error did not properly trigger reconnection logic [GH-85] 113 | * client.hmget(key, [val1, val2]) was not expanding properly [GH-66] 114 | * client.quit() while in pub/sub mode would throw an error [GH-87] 115 | * client.multi(['hmset', 'key', {foo: 'bar'}]) fails [GH-92] 116 | * unsubscribe before subscribe would make things very confused [GH-88] 117 | * Add BRPOPLPUSH [GH-79] 118 | 119 | ## v0.5.11 - April 7, 2011 120 | 121 | Added DISCARD 122 | 123 | I originally didn't think DISCARD would do anything here because of the clever MULTI interface, but somebody 124 | pointed out to me that DISCARD can be used to flush the WATCH set. 125 | 126 | ## v0.5.10 - April 6, 2011 127 | 128 | Added HVALS 129 | 130 | ## v0.5.9 - March 14, 2011 131 | 132 | Fix bug with empty Array arguments - Andy Ray 133 | 134 | ## v0.5.8 - March 14, 2011 135 | 136 | Add `MONITOR` command and special monitor command reply parsing. 137 | 138 | ## v0.5.7 - February 27, 2011 139 | 140 | Add magical auth command. 141 | 142 | Authentication is now remembered by the client and will be automatically sent to the server 143 | on every connection, including any reconnections. 144 | 145 | ## v0.5.6 - February 22, 2011 146 | 147 | Fix bug in ready check with `return_buffers` set to `true`. 148 | 149 | Thanks to Dean Mao and Austin Chau. 150 | 151 | ## v0.5.5 - February 16, 2011 152 | 153 | Add probe for server readiness. 154 | 155 | When a Redis server starts up, it might take a while to load the dataset into memory. 156 | During this time, the server will accept connections, but will return errors for all non-INFO 157 | commands. Now node_redis will send an INFO command whenever it connects to a server. 158 | If the info command indicates that the server is not ready, the client will keep trying until 159 | the server is ready. Once it is ready, the client will emit a "ready" event as well as the 160 | "connect" event. The client will queue up all commands sent before the server is ready, just 161 | like it did before. When the server is ready, all offline/non-ready commands will be replayed. 162 | This should be backward compatible with previous versions. 163 | 164 | To disable this ready check behavior, set `options.no_ready_check` when creating the client. 165 | 166 | As a side effect of this change, the key/val params from the info command are available as 167 | `client.server_options`. Further, the version string is decomposed into individual elements 168 | in `client.server_options.versions`. 169 | 170 | ## v0.5.4 - February 11, 2011 171 | 172 | Fix excess memory consumption from Queue backing store. 173 | 174 | Thanks to Gustaf Sjöberg. 175 | 176 | ## v0.5.3 - February 5, 2011 177 | 178 | Fix multi/exec error reply callback logic. 179 | 180 | Thanks to Stella Laurenzo. 181 | 182 | ## v0.5.2 - January 18, 2011 183 | 184 | Fix bug where unhandled error replies confuse the parser. 185 | 186 | ## v0.5.1 - January 18, 2011 187 | 188 | Fix bug where subscribe commands would not handle redis-server startup error properly. 189 | 190 | ## v0.5.0 - December 29, 2010 191 | 192 | Some bug fixes: 193 | 194 | * An important bug fix in reconnection logic. Previously, reply callbacks would be invoked twice after 195 | a reconnect. 196 | * Changed error callback argument to be an actual Error object. 197 | 198 | New feature: 199 | 200 | * Add friendly syntax for HMSET using an object. 201 | 202 | ## v0.4.1 - December 8, 2010 203 | 204 | Remove warning about missing hiredis. You probably do want it though. 205 | 206 | ## v0.4.0 - December 5, 2010 207 | 208 | Support for multiple response parsers and hiredis C library from Pieter Noordhuis. 209 | Return Strings instead of Buffers by default. 210 | Empty nested mb reply bug fix. 211 | 212 | ## v0.3.9 - November 30, 2010 213 | 214 | Fix parser bug on failed EXECs. 215 | 216 | ## v0.3.8 - November 10, 2010 217 | 218 | Fix for null MULTI response when WATCH condition fails. 219 | 220 | ## v0.3.7 - November 9, 2010 221 | 222 | Add "drain" and "idle" events. 223 | 224 | ## v0.3.6 - November 3, 2010 225 | 226 | Add all known Redis commands from Redis master, even ones that are coming in 2.2 and beyond. 227 | 228 | Send a friendlier "error" event message on stream errors like connection refused / reset. 229 | 230 | ## v0.3.5 - October 21, 2010 231 | 232 | A few bug fixes. 233 | 234 | * Fixed bug with `nil` multi-bulk reply lengths that showed up with `BLPOP` timeouts. 235 | * Only emit `end` once when connection goes away. 236 | * Fixed bug in `test.js` where driver finished before all tests completed. 237 | 238 | ## unversioned wasteland 239 | 240 | See the git history for what happened before. 241 | -------------------------------------------------------------------------------- /node_modules/redis/diff_multi_bench_output.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var colors = require('colors'), 4 | fs = require('fs'), 5 | _ = require('underscore'), 6 | metrics = require('metrics'), 7 | 8 | // `node diff_multi_bench_output.js before.txt after.txt` 9 | before = process.argv[2], 10 | after = process.argv[3]; 11 | 12 | if (!before || !after) { 13 | console.log('Please supply two file arguments:'); 14 | var n = __filename; 15 | n = n.substring(n.lastIndexOf('/', n.length)); 16 | console.log(' ./' + n + ' multiBenchBefore.txt multiBenchAfter.txt'); 17 | console.log('To generate multiBenchBefore.txt, run'); 18 | console.log(' node multi_bench.js > multiBenchBefore.txt'); 19 | console.log('Thank you for benchmarking responsibly.'); 20 | return; 21 | } 22 | 23 | var before_lines = fs.readFileSync(before, 'utf8').split('\n'), 24 | after_lines = fs.readFileSync(after, 'utf8').split('\n'); 25 | 26 | console.log('Comparing before,', before.green, '(', before_lines.length, 27 | 'lines)', 'to after,', after.green, '(', after_lines.length, 'lines)'); 28 | 29 | var total_ops = new metrics.Histogram.createUniformHistogram(); 30 | 31 | before_lines.forEach(function(b, i) { 32 | var a = after_lines[i]; 33 | if (!a || !b || !b.trim() || !a.trim()) { 34 | // console.log('#ignored#', '>'+a+'<', '>'+b+'<'); 35 | return; 36 | } 37 | 38 | b_words = b.split(' ').filter(is_whitespace); 39 | a_words = a.split(' ').filter(is_whitespace); 40 | 41 | var ops = 42 | [b_words, a_words] 43 | .map(function(words) { 44 | // console.log(words); 45 | return parseInt10(words.slice(-2, -1)); 46 | }).filter(function(num) { 47 | var isNaN = !num && num !== 0; 48 | return !isNaN; 49 | }); 50 | if (ops.length != 2) return 51 | 52 | var delta = ops[1] - ops[0]; 53 | 54 | total_ops.update(delta); 55 | 56 | delta = humanize_diff(delta); 57 | console.log( 58 | // name of test 59 | command_name(a_words) == command_name(b_words) 60 | ? command_name(a_words) + ':' 61 | : '404:', 62 | // results of test 63 | ops.join(' -> '), 'ops/sec (∆', delta, ')'); 64 | }); 65 | 66 | console.log('Mean difference in ops/sec:', humanize_diff(total_ops.mean())); 67 | 68 | function is_whitespace(s) { 69 | return !!s.trim(); 70 | } 71 | 72 | function parseInt10(s) { 73 | return parseInt(s, 10); 74 | } 75 | 76 | // green if greater than 0, red otherwise 77 | function humanize_diff(num) { 78 | if (num > 0) { 79 | return ('+' + num).green; 80 | } 81 | return ('' + num).red; 82 | } 83 | 84 | function command_name(words) { 85 | var line = words.join(' '); 86 | return line.substr(0, line.indexOf(',')); 87 | } 88 | -------------------------------------------------------------------------------- /node_modules/redis/examples/auth.js: -------------------------------------------------------------------------------- 1 | var redis = require("redis"), 2 | client = redis.createClient(); 3 | 4 | // This command is magical. Client stashes the password and will issue on every connect. 5 | client.auth("somepass"); 6 | -------------------------------------------------------------------------------- /node_modules/redis/examples/backpressure_drain.js: -------------------------------------------------------------------------------- 1 | var redis = require("../index"), 2 | client = redis.createClient(null, null, { 3 | command_queue_high_water: 5, 4 | command_queue_low_water: 1 5 | }), 6 | remaining_ops = 100000, paused = false; 7 | 8 | function op() { 9 | if (remaining_ops <= 0) { 10 | console.error("Finished."); 11 | process.exit(0); 12 | } 13 | 14 | remaining_ops--; 15 | if (client.hset("test hash", "val " + remaining_ops, remaining_ops) === false) { 16 | console.log("Pausing at " + remaining_ops); 17 | paused = true; 18 | } else { 19 | process.nextTick(op); 20 | } 21 | } 22 | 23 | client.on("drain", function () { 24 | if (paused) { 25 | console.log("Resuming at " + remaining_ops); 26 | paused = false; 27 | process.nextTick(op); 28 | } else { 29 | console.log("Got drain while not paused at " + remaining_ops); 30 | } 31 | }); 32 | 33 | op(); 34 | -------------------------------------------------------------------------------- /node_modules/redis/examples/eval.js: -------------------------------------------------------------------------------- 1 | var redis = require("./index"), 2 | client = redis.createClient(); 3 | 4 | redis.debug_mode = true; 5 | 6 | client.eval("return 100.5", 0, function (err, res) { 7 | console.dir(err); 8 | console.dir(res); 9 | }); 10 | -------------------------------------------------------------------------------- /node_modules/redis/examples/extend.js: -------------------------------------------------------------------------------- 1 | var redis = require("redis"), 2 | client = redis.createClient(); 3 | 4 | // Extend the RedisClient prototype to add a custom method 5 | // This one converts the results from "INFO" into a JavaScript Object 6 | 7 | redis.RedisClient.prototype.parse_info = function (callback) { 8 | this.info(function (err, res) { 9 | var lines = res.toString().split("\r\n").sort(); 10 | var obj = {}; 11 | lines.forEach(function (line) { 12 | var parts = line.split(':'); 13 | if (parts[1]) { 14 | obj[parts[0]] = parts[1]; 15 | } 16 | }); 17 | callback(obj) 18 | }); 19 | }; 20 | 21 | client.parse_info(function (info) { 22 | console.dir(info); 23 | client.quit(); 24 | }); 25 | -------------------------------------------------------------------------------- /node_modules/redis/examples/file.js: -------------------------------------------------------------------------------- 1 | // Read a file from disk, store it in Redis, then read it back from Redis. 2 | 3 | var redis = require("redis"), 4 | client = redis.createClient(), 5 | fs = require("fs"), 6 | filename = "kids_in_cart.jpg"; 7 | 8 | // Get the file I use for testing like this: 9 | // curl http://ranney.com/kids_in_cart.jpg -o kids_in_cart.jpg 10 | // or just use your own file. 11 | 12 | // Read a file from fs, store it in Redis, get it back from Redis, write it back to fs. 13 | fs.readFile(filename, function (err, data) { 14 | if (err) throw err 15 | console.log("Read " + data.length + " bytes from filesystem."); 16 | 17 | client.set(filename, data, redis.print); // set entire file 18 | client.get(filename, function (err, reply) { // get entire file 19 | if (err) { 20 | console.log("Get error: " + err); 21 | } else { 22 | fs.writeFile("duplicate_" + filename, reply, function (err) { 23 | if (err) { 24 | console.log("Error on write: " + err) 25 | } else { 26 | console.log("File written."); 27 | } 28 | client.end(); 29 | }); 30 | } 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /node_modules/redis/examples/mget.js: -------------------------------------------------------------------------------- 1 | var client = require("redis").createClient(); 2 | 3 | client.mget(["sessions started", "sessions started", "foo"], function (err, res) { 4 | console.dir(res); 5 | }); -------------------------------------------------------------------------------- /node_modules/redis/examples/monitor.js: -------------------------------------------------------------------------------- 1 | var client = require("../index").createClient(), 2 | util = require("util"); 3 | 4 | client.monitor(function (err, res) { 5 | console.log("Entering monitoring mode."); 6 | }); 7 | 8 | client.on("monitor", function (time, args) { 9 | console.log(time + ": " + util.inspect(args)); 10 | }); 11 | -------------------------------------------------------------------------------- /node_modules/redis/examples/multi.js: -------------------------------------------------------------------------------- 1 | var redis = require("redis"), 2 | client = redis.createClient(), set_size = 20; 3 | 4 | client.sadd("bigset", "a member"); 5 | client.sadd("bigset", "another member"); 6 | 7 | while (set_size > 0) { 8 | client.sadd("bigset", "member " + set_size); 9 | set_size -= 1; 10 | } 11 | 12 | // multi chain with an individual callback 13 | client.multi() 14 | .scard("bigset") 15 | .smembers("bigset") 16 | .keys("*", function (err, replies) { 17 | client.mget(replies, redis.print); 18 | }) 19 | .dbsize() 20 | .exec(function (err, replies) { 21 | console.log("MULTI got " + replies.length + " replies"); 22 | replies.forEach(function (reply, index) { 23 | console.log("Reply " + index + ": " + reply.toString()); 24 | }); 25 | }); 26 | 27 | client.mset("incr thing", 100, "incr other thing", 1, redis.print); 28 | 29 | // start a separate multi command queue 30 | var multi = client.multi(); 31 | multi.incr("incr thing", redis.print); 32 | multi.incr("incr other thing", redis.print); 33 | 34 | // runs immediately 35 | client.get("incr thing", redis.print); // 100 36 | 37 | // drains multi queue and runs atomically 38 | multi.exec(function (err, replies) { 39 | console.log(replies); // 101, 2 40 | }); 41 | 42 | // you can re-run the same transaction if you like 43 | multi.exec(function (err, replies) { 44 | console.log(replies); // 102, 3 45 | client.quit(); 46 | }); 47 | -------------------------------------------------------------------------------- /node_modules/redis/examples/multi2.js: -------------------------------------------------------------------------------- 1 | var redis = require("redis"), 2 | client = redis.createClient(), multi; 3 | 4 | // start a separate command queue for multi 5 | multi = client.multi(); 6 | multi.incr("incr thing", redis.print); 7 | multi.incr("incr other thing", redis.print); 8 | 9 | // runs immediately 10 | client.mset("incr thing", 100, "incr other thing", 1, redis.print); 11 | 12 | // drains multi queue and runs atomically 13 | multi.exec(function (err, replies) { 14 | console.log(replies); // 101, 2 15 | }); 16 | 17 | // you can re-run the same transaction if you like 18 | multi.exec(function (err, replies) { 19 | console.log(replies); // 102, 3 20 | client.quit(); 21 | }); 22 | 23 | client.multi([ 24 | ["mget", "multifoo", "multibar", redis.print], 25 | ["incr", "multifoo"], 26 | ["incr", "multibar"] 27 | ]).exec(function (err, replies) { 28 | console.log(replies.toString()); 29 | }); 30 | -------------------------------------------------------------------------------- /node_modules/redis/examples/psubscribe.js: -------------------------------------------------------------------------------- 1 | var redis = require("redis"), 2 | client1 = redis.createClient(), 3 | client2 = redis.createClient(), 4 | client3 = redis.createClient(), 5 | client4 = redis.createClient(), 6 | msg_count = 0; 7 | 8 | redis.debug_mode = false; 9 | 10 | client1.on("psubscribe", function (pattern, count) { 11 | console.log("client1 psubscribed to " + pattern + ", " + count + " total subscriptions"); 12 | client2.publish("channeltwo", "Me!"); 13 | client3.publish("channelthree", "Me too!"); 14 | client4.publish("channelfour", "And me too!"); 15 | }); 16 | 17 | client1.on("punsubscribe", function (pattern, count) { 18 | console.log("client1 punsubscribed from " + pattern + ", " + count + " total subscriptions"); 19 | client4.end(); 20 | client3.end(); 21 | client2.end(); 22 | client1.end(); 23 | }); 24 | 25 | client1.on("pmessage", function (pattern, channel, message) { 26 | console.log("("+ pattern +")" + " client1 received message on " + channel + ": " + message); 27 | msg_count += 1; 28 | if (msg_count === 3) { 29 | client1.punsubscribe(); 30 | } 31 | }); 32 | 33 | client1.psubscribe("channel*"); 34 | -------------------------------------------------------------------------------- /node_modules/redis/examples/pub_sub.js: -------------------------------------------------------------------------------- 1 | var redis = require("redis"), 2 | client1 = redis.createClient(), msg_count = 0, 3 | client2 = redis.createClient(); 4 | 5 | redis.debug_mode = false; 6 | 7 | // Most clients probably don't do much on "subscribe". This example uses it to coordinate things within one program. 8 | client1.on("subscribe", function (channel, count) { 9 | console.log("client1 subscribed to " + channel + ", " + count + " total subscriptions"); 10 | if (count === 2) { 11 | client2.publish("a nice channel", "I am sending a message."); 12 | client2.publish("another one", "I am sending a second message."); 13 | client2.publish("a nice channel", "I am sending my last message."); 14 | } 15 | }); 16 | 17 | client1.on("unsubscribe", function (channel, count) { 18 | console.log("client1 unsubscribed from " + channel + ", " + count + " total subscriptions"); 19 | if (count === 0) { 20 | client2.end(); 21 | client1.end(); 22 | } 23 | }); 24 | 25 | client1.on("message", function (channel, message) { 26 | console.log("client1 channel " + channel + ": " + message); 27 | msg_count += 1; 28 | if (msg_count === 3) { 29 | client1.unsubscribe(); 30 | } 31 | }); 32 | 33 | client1.on("ready", function () { 34 | // if you need auth, do it here 35 | client1.incr("did a thing"); 36 | client1.subscribe("a nice channel", "another one"); 37 | }); 38 | 39 | client2.on("ready", function () { 40 | // if you need auth, do it here 41 | }); 42 | -------------------------------------------------------------------------------- /node_modules/redis/examples/simple.js: -------------------------------------------------------------------------------- 1 | var redis = require("redis"), 2 | client = redis.createClient(); 3 | 4 | client.on("error", function (err) { 5 | console.log("error event - " + client.host + ":" + client.port + " - " + err); 6 | }); 7 | 8 | client.set("string key", "string val", redis.print); 9 | client.hset("hash key", "hashtest 1", "some value", redis.print); 10 | client.hset(["hash key", "hashtest 2", "some other value"], redis.print); 11 | client.hkeys("hash key", function (err, replies) { 12 | if (err) { 13 | return console.error("error response - " + err); 14 | } 15 | 16 | console.log(replies.length + " replies:"); 17 | replies.forEach(function (reply, i) { 18 | console.log(" " + i + ": " + reply); 19 | }); 20 | }); 21 | 22 | client.quit(function (err, res) { 23 | console.log("Exiting from quit command."); 24 | }); 25 | -------------------------------------------------------------------------------- /node_modules/redis/examples/sort.js: -------------------------------------------------------------------------------- 1 | var redis = require("redis"), 2 | client = redis.createClient(); 3 | 4 | client.sadd("mylist", 1); 5 | client.sadd("mylist", 2); 6 | client.sadd("mylist", 3); 7 | 8 | client.set("weight_1", 5); 9 | client.set("weight_2", 500); 10 | client.set("weight_3", 1); 11 | 12 | client.set("object_1", "foo"); 13 | client.set("object_2", "bar"); 14 | client.set("object_3", "qux"); 15 | 16 | client.sort("mylist", "by", "weight_*", "get", "object_*", redis.print); 17 | // Prints Reply: qux,foo,bar -------------------------------------------------------------------------------- /node_modules/redis/examples/subqueries.js: -------------------------------------------------------------------------------- 1 | // Sending commands in response to other commands. 2 | // This example runs "type" against every key in the database 3 | // 4 | var client = require("redis").createClient(); 5 | 6 | client.keys("*", function (err, keys) { 7 | keys.forEach(function (key, pos) { 8 | client.type(key, function (err, keytype) { 9 | console.log(key + " is " + keytype); 10 | if (pos === (keys.length - 1)) { 11 | client.quit(); 12 | } 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /node_modules/redis/examples/subquery.js: -------------------------------------------------------------------------------- 1 | var client = require("redis").createClient(); 2 | 3 | function print_results(obj) { 4 | console.dir(obj); 5 | } 6 | 7 | // build a map of all keys and their types 8 | client.keys("*", function (err, all_keys) { 9 | var key_types = {}; 10 | 11 | all_keys.forEach(function (key, pos) { // use second arg of forEach to get pos 12 | client.type(key, function (err, type) { 13 | key_types[key] = type; 14 | if (pos === all_keys.length - 1) { // callbacks all run in order 15 | print_results(key_types); 16 | } 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /node_modules/redis/examples/unix_socket.js: -------------------------------------------------------------------------------- 1 | var redis = require("redis"), 2 | client = redis.createClient("/tmp/redis.sock"), 3 | profiler = require("v8-profiler"); 4 | 5 | client.on("connect", function () { 6 | console.log("Got Unix socket connection.") 7 | }); 8 | 9 | client.on("error", function (err) { 10 | console.log(err.message); 11 | }); 12 | 13 | client.set("space chars", "space value"); 14 | 15 | setInterval(function () { 16 | client.get("space chars"); 17 | }, 100); 18 | 19 | function done() { 20 | client.info(function (err, reply) { 21 | console.log(reply.toString()); 22 | client.quit(); 23 | }); 24 | } 25 | 26 | setTimeout(function () { 27 | console.log("Taking snapshot."); 28 | var snap = profiler.takeSnapshot(); 29 | }, 5000); 30 | -------------------------------------------------------------------------------- /node_modules/redis/examples/web_server.js: -------------------------------------------------------------------------------- 1 | // A simple web server that generates dyanmic content based on responses from Redis 2 | 3 | var http = require("http"), server, 4 | redis_client = require("redis").createClient(); 5 | 6 | server = http.createServer(function (request, response) { 7 | response.writeHead(200, { 8 | "Content-Type": "text/plain" 9 | }); 10 | 11 | var redis_info, total_requests; 12 | 13 | redis_client.info(function (err, reply) { 14 | redis_info = reply; // stash response in outer scope 15 | }); 16 | redis_client.incr("requests", function (err, reply) { 17 | total_requests = reply; // stash response in outer scope 18 | }); 19 | redis_client.hincrby("ip", request.connection.remoteAddress, 1); 20 | redis_client.hgetall("ip", function (err, reply) { 21 | // This is the last reply, so all of the previous replies must have completed already 22 | response.write("This page was generated after talking to redis.\n\n" + 23 | "Redis info:\n" + redis_info + "\n" + 24 | "Total requests: " + total_requests + "\n\n" + 25 | "IP count: \n"); 26 | Object.keys(reply).forEach(function (ip) { 27 | response.write(" " + ip + ": " + reply[ip] + "\n"); 28 | }); 29 | response.end(); 30 | }); 31 | }).listen(80); 32 | -------------------------------------------------------------------------------- /node_modules/redis/generate_commands.js: -------------------------------------------------------------------------------- 1 | var http = require("http"), 2 | fs = require("fs"); 3 | 4 | function prettyCurrentTime() { 5 | var date = new Date(); 6 | return date.toLocaleString(); 7 | } 8 | 9 | function write_file(commands, path) { 10 | var file_contents, out_commands; 11 | 12 | console.log("Writing " + Object.keys(commands).length + " commands to " + path); 13 | 14 | file_contents = "// This file was generated by ./generate_commands.js on " + prettyCurrentTime() + "\n"; 15 | 16 | out_commands = Object.keys(commands).map(function (key) { 17 | return key.toLowerCase(); 18 | }); 19 | 20 | file_contents += "module.exports = " + JSON.stringify(out_commands, null, " ") + ";\n"; 21 | 22 | fs.writeFile(path, file_contents); 23 | } 24 | 25 | http.get({host: "redis.io", path: "/commands.json"}, function (res) { 26 | var body = ""; 27 | 28 | console.log("Response from redis.io/commands.json: " + res.statusCode); 29 | 30 | res.on('data', function (chunk) { 31 | body += chunk; 32 | }); 33 | 34 | res.on('end', function () { 35 | write_file(JSON.parse(body), "lib/commands.js"); 36 | }); 37 | }).on('error', function (e) { 38 | console.log("Error fetching command list from redis.io: " + e.message); 39 | }); 40 | -------------------------------------------------------------------------------- /node_modules/redis/lib/commands.js: -------------------------------------------------------------------------------- 1 | // This file was generated by ./generate_commands.js on Mon Aug 06 2012 15:04:06 GMT-0700 (PDT) 2 | module.exports = [ 3 | "append", 4 | "auth", 5 | "bgrewriteaof", 6 | "bgsave", 7 | "bitcount", 8 | "bitop", 9 | "blpop", 10 | "brpop", 11 | "brpoplpush", 12 | "client kill", 13 | "client list", 14 | "config get", 15 | "config set", 16 | "config resetstat", 17 | "dbsize", 18 | "debug object", 19 | "debug segfault", 20 | "decr", 21 | "decrby", 22 | "del", 23 | "discard", 24 | "dump", 25 | "echo", 26 | "eval", 27 | "evalsha", 28 | "exec", 29 | "exists", 30 | "expire", 31 | "expireat", 32 | "flushall", 33 | "flushdb", 34 | "get", 35 | "getbit", 36 | "getrange", 37 | "getset", 38 | "hdel", 39 | "hexists", 40 | "hget", 41 | "hgetall", 42 | "hincrby", 43 | "hincrbyfloat", 44 | "hkeys", 45 | "hlen", 46 | "hmget", 47 | "hmset", 48 | "hset", 49 | "hsetnx", 50 | "hvals", 51 | "incr", 52 | "incrby", 53 | "incrbyfloat", 54 | "info", 55 | "keys", 56 | "lastsave", 57 | "lindex", 58 | "linsert", 59 | "llen", 60 | "lpop", 61 | "lpush", 62 | "lpushx", 63 | "lrange", 64 | "lrem", 65 | "lset", 66 | "ltrim", 67 | "mget", 68 | "migrate", 69 | "monitor", 70 | "move", 71 | "mset", 72 | "msetnx", 73 | "multi", 74 | "object", 75 | "persist", 76 | "pexpire", 77 | "pexpireat", 78 | "ping", 79 | "psetex", 80 | "psubscribe", 81 | "pttl", 82 | "publish", 83 | "punsubscribe", 84 | "quit", 85 | "randomkey", 86 | "rename", 87 | "renamenx", 88 | "restore", 89 | "rpop", 90 | "rpoplpush", 91 | "rpush", 92 | "rpushx", 93 | "sadd", 94 | "save", 95 | "scard", 96 | "script exists", 97 | "script flush", 98 | "script kill", 99 | "script load", 100 | "sdiff", 101 | "sdiffstore", 102 | "select", 103 | "set", 104 | "setbit", 105 | "setex", 106 | "setnx", 107 | "setrange", 108 | "shutdown", 109 | "sinter", 110 | "sinterstore", 111 | "sismember", 112 | "slaveof", 113 | "slowlog", 114 | "smembers", 115 | "smove", 116 | "sort", 117 | "spop", 118 | "srandmember", 119 | "srem", 120 | "strlen", 121 | "subscribe", 122 | "sunion", 123 | "sunionstore", 124 | "sync", 125 | "time", 126 | "ttl", 127 | "type", 128 | "unsubscribe", 129 | "unwatch", 130 | "watch", 131 | "zadd", 132 | "zcard", 133 | "zcount", 134 | "zincrby", 135 | "zinterstore", 136 | "zrange", 137 | "zrangebyscore", 138 | "zrank", 139 | "zrem", 140 | "zremrangebyrank", 141 | "zremrangebyscore", 142 | "zrevrange", 143 | "zrevrangebyscore", 144 | "zrevrank", 145 | "zscore", 146 | "zunionstore" 147 | ]; 148 | -------------------------------------------------------------------------------- /node_modules/redis/lib/parser/hiredis.js: -------------------------------------------------------------------------------- 1 | var events = require("events"), 2 | util = require("../util"), 3 | hiredis = require("hiredis"); 4 | 5 | exports.debug_mode = false; 6 | exports.name = "hiredis"; 7 | 8 | function HiredisReplyParser(options) { 9 | this.name = exports.name; 10 | this.options = options || {}; 11 | this.reset(); 12 | events.EventEmitter.call(this); 13 | } 14 | 15 | util.inherits(HiredisReplyParser, events.EventEmitter); 16 | 17 | exports.Parser = HiredisReplyParser; 18 | 19 | HiredisReplyParser.prototype.reset = function () { 20 | this.reader = new hiredis.Reader({ 21 | return_buffers: this.options.return_buffers || false 22 | }); 23 | }; 24 | 25 | HiredisReplyParser.prototype.execute = function (data) { 26 | var reply; 27 | this.reader.feed(data); 28 | while (true) { 29 | try { 30 | reply = this.reader.get(); 31 | } catch (err) { 32 | this.emit("error", err); 33 | break; 34 | } 35 | 36 | if (reply === undefined) { 37 | break; 38 | } 39 | 40 | if (reply && reply.constructor === Error) { 41 | this.emit("reply error", reply); 42 | } else { 43 | this.emit("reply", reply); 44 | } 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /node_modules/redis/lib/parser/javascript.js: -------------------------------------------------------------------------------- 1 | var events = require("events"), 2 | util = require("../util"); 3 | 4 | function Packet(type, size) { 5 | this.type = type; 6 | this.size = +size; 7 | } 8 | 9 | exports.name = "javascript"; 10 | exports.debug_mode = false; 11 | 12 | function ReplyParser(options) { 13 | this.name = exports.name; 14 | this.options = options || { }; 15 | 16 | this._buffer = null; 17 | this._offset = 0; 18 | this._encoding = "utf-8"; 19 | this._debug_mode = options.debug_mode; 20 | this._reply_type = null; 21 | } 22 | 23 | util.inherits(ReplyParser, events.EventEmitter); 24 | 25 | exports.Parser = ReplyParser; 26 | 27 | // Buffer.toString() is quite slow for small strings 28 | function small_toString(buf, start, end) { 29 | var tmp = "", i; 30 | 31 | for (i = start; i < end; i++) { 32 | tmp += String.fromCharCode(buf[i]); 33 | } 34 | 35 | return tmp; 36 | } 37 | 38 | ReplyParser.prototype._parseResult = function (type) { 39 | var start, end, offset, packetHeader; 40 | 41 | if (type === 43 || type === 45) { // + or - 42 | // up to the delimiter 43 | end = this._packetEndOffset() - 1; 44 | start = this._offset; 45 | 46 | // include the delimiter 47 | this._offset = end + 2; 48 | 49 | if (end > this._buffer.length) { 50 | this._offset = start; 51 | throw new Error("too far"); 52 | } 53 | 54 | if (this.options.return_buffers) { 55 | return this._buffer.slice(start, end); 56 | } else { 57 | if (end - start < 65536) { // completely arbitrary 58 | return small_toString(this._buffer, start, end); 59 | } else { 60 | return this._buffer.toString(this._encoding, start, end); 61 | } 62 | } 63 | } else if (type === 58) { // : 64 | // up to the delimiter 65 | end = this._packetEndOffset() - 1; 66 | start = this._offset; 67 | 68 | // include the delimiter 69 | this._offset = end + 2; 70 | 71 | if (end > this._buffer.length) { 72 | this._offset = start; 73 | throw new Error("too far"); 74 | } 75 | 76 | if (this.options.return_buffers) { 77 | return this._buffer.slice(start, end); 78 | } 79 | 80 | // return the coerced numeric value 81 | return +small_toString(this._buffer, start, end); 82 | } else if (type === 36) { // $ 83 | // set a rewind point, as the packet could be larger than the 84 | // buffer in memory 85 | offset = this._offset - 1; 86 | 87 | packetHeader = new Packet(type, this.parseHeader()); 88 | 89 | // packets with a size of -1 are considered null 90 | if (packetHeader.size === -1) { 91 | return undefined; 92 | } 93 | 94 | end = this._offset + packetHeader.size; 95 | start = this._offset; 96 | 97 | // set the offset to after the delimiter 98 | this._offset = end + 2; 99 | 100 | if (end > this._buffer.length) { 101 | this._offset = offset; 102 | throw new Error("too far"); 103 | } 104 | 105 | if (this.options.return_buffers) { 106 | return this._buffer.slice(start, end); 107 | } else { 108 | return this._buffer.toString(this._encoding, start, end); 109 | } 110 | } else if (type === 42) { // * 111 | offset = this._offset; 112 | packetHeader = new Packet(type, this.parseHeader()); 113 | 114 | if (packetHeader.size > this._bytesRemaining()) { 115 | this._offset = offset - 1; 116 | return -1; 117 | } 118 | 119 | if (packetHeader.size < 0) { 120 | this._offset += 2; 121 | return null; 122 | } 123 | 124 | var reply = [ ]; 125 | var ntype, i, res; 126 | 127 | offset = this._offset - 1; 128 | 129 | for (i = 0; i < packetHeader.size; i++) { 130 | ntype = this._buffer[this._offset++]; 131 | 132 | if (this._offset > this._buffer.length) { 133 | throw new Error("too far"); 134 | } 135 | res = this._parseResult(ntype); 136 | if (res === undefined) { 137 | res = null; 138 | } 139 | reply.push(res); 140 | } 141 | 142 | return reply; 143 | } 144 | }; 145 | 146 | ReplyParser.prototype.execute = function (buffer) { 147 | this.append(buffer); 148 | 149 | var type, ret, offset; 150 | 151 | while (true) { 152 | offset = this._offset; 153 | try { 154 | // at least 4 bytes: :1\r\n 155 | if (this._bytesRemaining() < 4) { 156 | break; 157 | } 158 | 159 | type = this._buffer[this._offset++]; 160 | 161 | if (type === 43) { // + 162 | ret = this._parseResult(type); 163 | 164 | if (ret === null) { 165 | break; 166 | } 167 | 168 | this.send_reply(ret); 169 | } else if (type === 45) { // - 170 | ret = this._parseResult(type); 171 | 172 | if (ret === null) { 173 | break; 174 | } 175 | 176 | this.send_error(ret); 177 | } else if (type === 58) { // : 178 | ret = this._parseResult(type); 179 | 180 | if (ret === null) { 181 | break; 182 | } 183 | 184 | this.send_reply(ret); 185 | } else if (type === 36) { // $ 186 | ret = this._parseResult(type); 187 | 188 | if (ret === null) { 189 | break; 190 | } 191 | 192 | // check the state for what is the result of 193 | // a -1, set it back up for a null reply 194 | if (ret === undefined) { 195 | ret = null; 196 | } 197 | 198 | this.send_reply(ret); 199 | } else if (type === 42) { // * 200 | // set a rewind point. if a failure occurs, 201 | // wait for the next execute()/append() and try again 202 | offset = this._offset - 1; 203 | 204 | ret = this._parseResult(type); 205 | 206 | if (ret === -1) { 207 | this._offset = offset; 208 | break; 209 | } 210 | 211 | this.send_reply(ret); 212 | } 213 | } catch (err) { 214 | // catch the error (not enough data), rewind, and wait 215 | // for the next packet to appear 216 | this._offset = offset; 217 | break; 218 | } 219 | } 220 | }; 221 | 222 | ReplyParser.prototype.append = function (newBuffer) { 223 | if (!newBuffer) { 224 | return; 225 | } 226 | 227 | // first run 228 | if (this._buffer === null) { 229 | this._buffer = newBuffer; 230 | 231 | return; 232 | } 233 | 234 | // out of data 235 | if (this._offset >= this._buffer.length) { 236 | this._buffer = newBuffer; 237 | this._offset = 0; 238 | 239 | return; 240 | } 241 | 242 | // very large packet 243 | // check for concat, if we have it, use it 244 | if (Buffer.concat !== undefined) { 245 | this._buffer = Buffer.concat([this._buffer.slice(this._offset), newBuffer]); 246 | } else { 247 | var remaining = this._bytesRemaining(), 248 | newLength = remaining + newBuffer.length, 249 | tmpBuffer = new Buffer(newLength); 250 | 251 | this._buffer.copy(tmpBuffer, 0, this._offset); 252 | newBuffer.copy(tmpBuffer, remaining, 0); 253 | 254 | this._buffer = tmpBuffer; 255 | } 256 | 257 | this._offset = 0; 258 | }; 259 | 260 | ReplyParser.prototype.parseHeader = function () { 261 | var end = this._packetEndOffset(), 262 | value = small_toString(this._buffer, this._offset, end - 1); 263 | 264 | this._offset = end + 1; 265 | 266 | return value; 267 | }; 268 | 269 | ReplyParser.prototype._packetEndOffset = function () { 270 | var offset = this._offset; 271 | 272 | while (this._buffer[offset] !== 0x0d && this._buffer[offset + 1] !== 0x0a) { 273 | offset++; 274 | 275 | if (offset >= this._buffer.length) { 276 | throw new Error("didn't see LF after NL reading multi bulk count (" + offset + " => " + this._buffer.length + ", " + this._offset + ")"); 277 | } 278 | } 279 | 280 | offset++; 281 | return offset; 282 | }; 283 | 284 | ReplyParser.prototype._bytesRemaining = function () { 285 | return (this._buffer.length - this._offset) < 0 ? 0 : (this._buffer.length - this._offset); 286 | }; 287 | 288 | ReplyParser.prototype.parser_error = function (message) { 289 | this.emit("error", message); 290 | }; 291 | 292 | ReplyParser.prototype.send_error = function (reply) { 293 | this.emit("reply error", reply); 294 | }; 295 | 296 | ReplyParser.prototype.send_reply = function (reply) { 297 | this.emit("reply", reply); 298 | }; -------------------------------------------------------------------------------- /node_modules/redis/lib/queue.js: -------------------------------------------------------------------------------- 1 | // Queue class adapted from Tim Caswell's pattern library 2 | // http://github.com/creationix/pattern/blob/master/lib/pattern/queue.js 3 | 4 | function Queue() { 5 | this.tail = []; 6 | this.head = []; 7 | this.offset = 0; 8 | } 9 | 10 | Queue.prototype.shift = function () { 11 | if (this.offset === this.head.length) { 12 | var tmp = this.head; 13 | tmp.length = 0; 14 | this.head = this.tail; 15 | this.tail = tmp; 16 | this.offset = 0; 17 | if (this.head.length === 0) { 18 | return; 19 | } 20 | } 21 | return this.head[this.offset++]; // sorry, JSLint 22 | }; 23 | 24 | Queue.prototype.push = function (item) { 25 | return this.tail.push(item); 26 | }; 27 | 28 | Queue.prototype.forEach = function (fn, thisv) { 29 | var array = this.head.slice(this.offset), i, il; 30 | 31 | array.push.apply(array, this.tail); 32 | 33 | if (thisv) { 34 | for (i = 0, il = array.length; i < il; i += 1) { 35 | fn.call(thisv, array[i], i, array); 36 | } 37 | } else { 38 | for (i = 0, il = array.length; i < il; i += 1) { 39 | fn(array[i], i, array); 40 | } 41 | } 42 | 43 | return array; 44 | }; 45 | 46 | Queue.prototype.getLength = function () { 47 | return this.head.length - this.offset + this.tail.length; 48 | }; 49 | 50 | Object.defineProperty(Queue.prototype, "length", { 51 | get: function () { 52 | return this.getLength(); 53 | } 54 | }); 55 | 56 | 57 | if (typeof module !== "undefined" && module.exports) { 58 | module.exports = Queue; 59 | } 60 | -------------------------------------------------------------------------------- /node_modules/redis/lib/to_array.js: -------------------------------------------------------------------------------- 1 | function to_array(args) { 2 | var len = args.length, 3 | arr = new Array(len), i; 4 | 5 | for (i = 0; i < len; i += 1) { 6 | arr[i] = args[i]; 7 | } 8 | 9 | return arr; 10 | } 11 | 12 | module.exports = to_array; 13 | -------------------------------------------------------------------------------- /node_modules/redis/lib/util.js: -------------------------------------------------------------------------------- 1 | // Support for very old versions of node where the module was called "sys". At some point, we should abandon this. 2 | 3 | var util; 4 | 5 | try { 6 | util = require("util"); 7 | } catch (err) { 8 | util = require("sys"); 9 | } 10 | 11 | module.exports = util; 12 | -------------------------------------------------------------------------------- /node_modules/redis/multi_bench.js: -------------------------------------------------------------------------------- 1 | var redis = require("./index"), 2 | metrics = require("metrics"), 3 | num_clients = parseInt(process.argv[2], 10) || 5, 4 | num_requests = 20000, 5 | tests = [], 6 | versions_logged = false, 7 | client_options = { 8 | return_buffers: false 9 | }, 10 | small_str, large_str, small_buf, large_buf; 11 | 12 | redis.debug_mode = false; 13 | 14 | function lpad(input, len, chr) { 15 | var str = input.toString(); 16 | chr = chr || " "; 17 | 18 | while (str.length < len) { 19 | str = chr + str; 20 | } 21 | return str; 22 | } 23 | 24 | metrics.Histogram.prototype.print_line = function () { 25 | var obj = this.printObj(); 26 | 27 | return lpad(obj.min, 4) + "/" + lpad(obj.max, 4) + "/" + lpad(obj.mean.toFixed(2), 7) + "/" + lpad(obj.p95.toFixed(2), 7); 28 | }; 29 | 30 | function Test(args) { 31 | this.args = args; 32 | 33 | this.callback = null; 34 | this.clients = []; 35 | this.clients_ready = 0; 36 | this.commands_sent = 0; 37 | this.commands_completed = 0; 38 | this.max_pipeline = this.args.pipeline || num_requests; 39 | this.client_options = args.client_options || client_options; 40 | 41 | this.connect_latency = new metrics.Histogram(); 42 | this.ready_latency = new metrics.Histogram(); 43 | this.command_latency = new metrics.Histogram(); 44 | } 45 | 46 | Test.prototype.run = function (callback) { 47 | var i; 48 | 49 | this.callback = callback; 50 | 51 | for (i = 0; i < num_clients ; i++) { 52 | this.new_client(i); 53 | } 54 | }; 55 | 56 | Test.prototype.new_client = function (id) { 57 | var self = this, new_client; 58 | 59 | new_client = redis.createClient(6379, "127.0.0.1", this.client_options); 60 | new_client.create_time = Date.now(); 61 | 62 | new_client.on("connect", function () { 63 | self.connect_latency.update(Date.now() - new_client.create_time); 64 | }); 65 | 66 | new_client.on("ready", function () { 67 | if (! versions_logged) { 68 | console.log("Client count: " + num_clients + ", node version: " + process.versions.node + ", server version: " + 69 | new_client.server_info.redis_version + ", parser: " + new_client.reply_parser.name); 70 | versions_logged = true; 71 | } 72 | self.ready_latency.update(Date.now() - new_client.create_time); 73 | self.clients_ready++; 74 | if (self.clients_ready === self.clients.length) { 75 | self.on_clients_ready(); 76 | } 77 | }); 78 | 79 | self.clients[id] = new_client; 80 | }; 81 | 82 | Test.prototype.on_clients_ready = function () { 83 | process.stdout.write(lpad(this.args.descr, 13) + ", " + lpad(this.args.pipeline, 5) + "/" + this.clients_ready + " "); 84 | this.test_start = Date.now(); 85 | 86 | this.fill_pipeline(); 87 | }; 88 | 89 | Test.prototype.fill_pipeline = function () { 90 | var pipeline = this.commands_sent - this.commands_completed; 91 | 92 | while (this.commands_sent < num_requests && pipeline < this.max_pipeline) { 93 | this.commands_sent++; 94 | pipeline++; 95 | this.send_next(); 96 | } 97 | 98 | if (this.commands_completed === num_requests) { 99 | this.print_stats(); 100 | this.stop_clients(); 101 | } 102 | }; 103 | 104 | Test.prototype.stop_clients = function () { 105 | var self = this; 106 | 107 | this.clients.forEach(function (client, pos) { 108 | if (pos === self.clients.length - 1) { 109 | client.quit(function (err, res) { 110 | self.callback(); 111 | }); 112 | } else { 113 | client.quit(); 114 | } 115 | }); 116 | }; 117 | 118 | Test.prototype.send_next = function () { 119 | var self = this, 120 | cur_client = this.commands_sent % this.clients.length, 121 | start = Date.now(); 122 | 123 | this.clients[cur_client][this.args.command](this.args.args, function (err, res) { 124 | if (err) { 125 | throw err; 126 | } 127 | self.commands_completed++; 128 | self.command_latency.update(Date.now() - start); 129 | self.fill_pipeline(); 130 | }); 131 | }; 132 | 133 | Test.prototype.print_stats = function () { 134 | var duration = Date.now() - this.test_start; 135 | 136 | console.log("min/max/avg/p95: " + this.command_latency.print_line() + " " + lpad(duration, 6) + "ms total, " + 137 | lpad((num_requests / (duration / 1000)).toFixed(2), 8) + " ops/sec"); 138 | }; 139 | 140 | small_str = "1234"; 141 | small_buf = new Buffer(small_str); 142 | large_str = (new Array(4097).join("-")); 143 | large_buf = new Buffer(large_str); 144 | 145 | tests.push(new Test({descr: "PING", command: "ping", args: [], pipeline: 1})); 146 | tests.push(new Test({descr: "PING", command: "ping", args: [], pipeline: 50})); 147 | tests.push(new Test({descr: "PING", command: "ping", args: [], pipeline: 200})); 148 | tests.push(new Test({descr: "PING", command: "ping", args: [], pipeline: 20000})); 149 | 150 | tests.push(new Test({descr: "SET small str", command: "set", args: ["foo_rand000000000000", small_str], pipeline: 1})); 151 | tests.push(new Test({descr: "SET small str", command: "set", args: ["foo_rand000000000000", small_str], pipeline: 50})); 152 | tests.push(new Test({descr: "SET small str", command: "set", args: ["foo_rand000000000000", small_str], pipeline: 200})); 153 | tests.push(new Test({descr: "SET small str", command: "set", args: ["foo_rand000000000000", small_str], pipeline: 20000})); 154 | 155 | tests.push(new Test({descr: "SET small buf", command: "set", args: ["foo_rand000000000000", small_buf], pipeline: 1})); 156 | tests.push(new Test({descr: "SET small buf", command: "set", args: ["foo_rand000000000000", small_buf], pipeline: 50})); 157 | tests.push(new Test({descr: "SET small buf", command: "set", args: ["foo_rand000000000000", small_buf], pipeline: 200})); 158 | tests.push(new Test({descr: "SET small buf", command: "set", args: ["foo_rand000000000000", small_buf], pipeline: 20000})); 159 | 160 | tests.push(new Test({descr: "GET small str", command: "get", args: ["foo_rand000000000000"], pipeline: 1})); 161 | tests.push(new Test({descr: "GET small str", command: "get", args: ["foo_rand000000000000"], pipeline: 50})); 162 | tests.push(new Test({descr: "GET small str", command: "get", args: ["foo_rand000000000000"], pipeline: 200})); 163 | tests.push(new Test({descr: "GET small str", command: "get", args: ["foo_rand000000000000"], pipeline: 20000})); 164 | 165 | tests.push(new Test({descr: "GET small buf", command: "get", args: ["foo_rand000000000000"], pipeline: 1, client_opts: { return_buffers: true} })); 166 | tests.push(new Test({descr: "GET small buf", command: "get", args: ["foo_rand000000000000"], pipeline: 50, client_opts: { return_buffers: true} })); 167 | tests.push(new Test({descr: "GET small buf", command: "get", args: ["foo_rand000000000000"], pipeline: 200, client_opts: { return_buffers: true} })); 168 | tests.push(new Test({descr: "GET small buf", command: "get", args: ["foo_rand000000000000"], pipeline: 20000, client_opts: { return_buffers: true} })); 169 | 170 | tests.push(new Test({descr: "SET large str", command: "set", args: ["foo_rand000000000001", large_str], pipeline: 1})); 171 | tests.push(new Test({descr: "SET large str", command: "set", args: ["foo_rand000000000001", large_str], pipeline: 50})); 172 | tests.push(new Test({descr: "SET large str", command: "set", args: ["foo_rand000000000001", large_str], pipeline: 200})); 173 | tests.push(new Test({descr: "SET large str", command: "set", args: ["foo_rand000000000001", large_str], pipeline: 20000})); 174 | 175 | tests.push(new Test({descr: "SET large buf", command: "set", args: ["foo_rand000000000001", large_buf], pipeline: 1})); 176 | tests.push(new Test({descr: "SET large buf", command: "set", args: ["foo_rand000000000001", large_buf], pipeline: 50})); 177 | tests.push(new Test({descr: "SET large buf", command: "set", args: ["foo_rand000000000001", large_buf], pipeline: 200})); 178 | tests.push(new Test({descr: "SET large buf", command: "set", args: ["foo_rand000000000001", large_buf], pipeline: 20000})); 179 | 180 | tests.push(new Test({descr: "GET large str", command: "get", args: ["foo_rand000000000001"], pipeline: 1})); 181 | tests.push(new Test({descr: "GET large str", command: "get", args: ["foo_rand000000000001"], pipeline: 50})); 182 | tests.push(new Test({descr: "GET large str", command: "get", args: ["foo_rand000000000001"], pipeline: 200})); 183 | tests.push(new Test({descr: "GET large str", command: "get", args: ["foo_rand000000000001"], pipeline: 20000})); 184 | 185 | tests.push(new Test({descr: "GET large buf", command: "get", args: ["foo_rand000000000001"], pipeline: 1, client_opts: { return_buffers: true} })); 186 | tests.push(new Test({descr: "GET large buf", command: "get", args: ["foo_rand000000000001"], pipeline: 50, client_opts: { return_buffers: true} })); 187 | tests.push(new Test({descr: "GET large buf", command: "get", args: ["foo_rand000000000001"], pipeline: 200, client_opts: { return_buffers: true} })); 188 | tests.push(new Test({descr: "GET large buf", command: "get", args: ["foo_rand000000000001"], pipeline: 20000, client_opts: { return_buffers: true} })); 189 | 190 | tests.push(new Test({descr: "INCR", command: "incr", args: ["counter_rand000000000000"], pipeline: 1})); 191 | tests.push(new Test({descr: "INCR", command: "incr", args: ["counter_rand000000000000"], pipeline: 50})); 192 | tests.push(new Test({descr: "INCR", command: "incr", args: ["counter_rand000000000000"], pipeline: 200})); 193 | tests.push(new Test({descr: "INCR", command: "incr", args: ["counter_rand000000000000"], pipeline: 20000})); 194 | 195 | tests.push(new Test({descr: "LPUSH", command: "lpush", args: ["mylist", small_str], pipeline: 1})); 196 | tests.push(new Test({descr: "LPUSH", command: "lpush", args: ["mylist", small_str], pipeline: 50})); 197 | tests.push(new Test({descr: "LPUSH", command: "lpush", args: ["mylist", small_str], pipeline: 200})); 198 | tests.push(new Test({descr: "LPUSH", command: "lpush", args: ["mylist", small_str], pipeline: 20000})); 199 | 200 | tests.push(new Test({descr: "LRANGE 10", command: "lrange", args: ["mylist", "0", "9"], pipeline: 1})); 201 | tests.push(new Test({descr: "LRANGE 10", command: "lrange", args: ["mylist", "0", "9"], pipeline: 50})); 202 | tests.push(new Test({descr: "LRANGE 10", command: "lrange", args: ["mylist", "0", "9"], pipeline: 200})); 203 | tests.push(new Test({descr: "LRANGE 10", command: "lrange", args: ["mylist", "0", "9"], pipeline: 20000})); 204 | 205 | tests.push(new Test({descr: "LRANGE 100", command: "lrange", args: ["mylist", "0", "99"], pipeline: 1})); 206 | tests.push(new Test({descr: "LRANGE 100", command: "lrange", args: ["mylist", "0", "99"], pipeline: 50})); 207 | tests.push(new Test({descr: "LRANGE 100", command: "lrange", args: ["mylist", "0", "99"], pipeline: 200})); 208 | tests.push(new Test({descr: "LRANGE 100", command: "lrange", args: ["mylist", "0", "99"], pipeline: 20000})); 209 | 210 | function next() { 211 | var test = tests.shift(); 212 | if (test) { 213 | test.run(function () { 214 | next(); 215 | }); 216 | } else { 217 | console.log("End of tests."); 218 | process.exit(0); 219 | } 220 | } 221 | 222 | next(); 223 | -------------------------------------------------------------------------------- /node_modules/redis/test3.js: -------------------------------------------------------------------------------- 1 | var redis = require('redis'); 2 | 3 | rc = redis.createClient(); 4 | 5 | rc.on('error', function (err) { 6 | console.log('Redis error ' + err); 7 | }); 8 | 9 | var jsonStr = '{\"glossary\":{\"title\":\"example glossary\",\"GlossDiv\":{\"title\":\"S\",\"GlossList\":{\"GlossEntry\":{\"ID\":\"SGML\",\"SortAs\":\"SGML\",\"GlossTerm\":\"Standard Generalized Markup Language\",\"Acronym\":\"SGML\",\"Abbrev\":\"ISO 8879:1986\",\"GlossDef\":{\"para\":\"A meta-markup language, used to create markup languages such as DocBook.\",\"GlossSeeAlso\":[\"GML\",\"XML\"]},\"GlossSee\":\"markup\"}}}}}'; 10 | 11 | for (var i = 0, len = 100; i < len; i++) { 12 | rc.rpush('test:case', jsonStr); 13 | } 14 | 15 | rc.lrange('test:case', 0, -1, function (err, data) { 16 | console.log(data); // it will return 100 elements, but the last ones will be null's instead of the actual value 17 | rc.end(); 18 | }); 19 | -------------------------------------------------------------------------------- /node_modules/underscore/.npmignore: -------------------------------------------------------------------------------- 1 | test/ 2 | Rakefile 3 | docs/ -------------------------------------------------------------------------------- /node_modules/underscore/CNAME: -------------------------------------------------------------------------------- 1 | underscorejs.org 2 | -------------------------------------------------------------------------------- /node_modules/underscore/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2012 Jeremy Ashkenas, DocumentCloud 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /node_modules/underscore/README.md: -------------------------------------------------------------------------------- 1 | __ 2 | /\ \ __ 3 | __ __ ___ \_\ \ __ _ __ ____ ___ ___ _ __ __ /\_\ ____ 4 | /\ \/\ \ /' _ `\ /'_ \ /'__`\/\ __\/ ,__\ / ___\ / __`\/\ __\/'__`\ \/\ \ /',__\ 5 | \ \ \_\ \/\ \/\ \/\ \ \ \/\ __/\ \ \//\__, `\/\ \__//\ \ \ \ \ \//\ __/ __ \ \ \/\__, `\ 6 | \ \____/\ \_\ \_\ \___,_\ \____\\ \_\\/\____/\ \____\ \____/\ \_\\ \____\/\_\ _\ \ \/\____/ 7 | \/___/ \/_/\/_/\/__,_ /\/____/ \/_/ \/___/ \/____/\/___/ \/_/ \/____/\/_//\ \_\ \/___/ 8 | \ \____/ 9 | \/___/ 10 | 11 | Underscore.js is a utility-belt library for JavaScript that provides 12 | support for the usual functional suspects (each, map, reduce, filter...) 13 | without extending any core JavaScript objects. 14 | 15 | For Docs, License, Tests, and pre-packed downloads, see: 16 | http://documentcloud.github.com/underscore/ 17 | 18 | Many thanks to our contributors: 19 | https://github.com/documentcloud/underscore/contributors 20 | -------------------------------------------------------------------------------- /node_modules/underscore/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/underscore/favicon.ico -------------------------------------------------------------------------------- /node_modules/underscore/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./underscore'); 2 | -------------------------------------------------------------------------------- /node_modules/underscore/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "underscore", 3 | "description": "JavaScript's functional programming helper library.", 4 | "homepage": "http://documentcloud.github.com/underscore/", 5 | "keywords": [ 6 | "util", 7 | "functional", 8 | "server", 9 | "client", 10 | "browser" 11 | ], 12 | "author": { 13 | "name": "Jeremy Ashkenas", 14 | "email": "jeremy@documentcloud.org" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git://github.com/documentcloud/underscore.git" 19 | }, 20 | "main": "underscore.js", 21 | "version": "1.3.3", 22 | "readme": " __ \n /\\ \\ __ \n __ __ ___ \\_\\ \\ __ _ __ ____ ___ ___ _ __ __ /\\_\\ ____ \n /\\ \\/\\ \\ /' _ `\\ /'_ \\ /'__`\\/\\ __\\/ ,__\\ / ___\\ / __`\\/\\ __\\/'__`\\ \\/\\ \\ /',__\\ \n \\ \\ \\_\\ \\/\\ \\/\\ \\/\\ \\ \\ \\/\\ __/\\ \\ \\//\\__, `\\/\\ \\__//\\ \\ \\ \\ \\ \\//\\ __/ __ \\ \\ \\/\\__, `\\\n \\ \\____/\\ \\_\\ \\_\\ \\___,_\\ \\____\\\\ \\_\\\\/\\____/\\ \\____\\ \\____/\\ \\_\\\\ \\____\\/\\_\\ _\\ \\ \\/\\____/\n \\/___/ \\/_/\\/_/\\/__,_ /\\/____/ \\/_/ \\/___/ \\/____/\\/___/ \\/_/ \\/____/\\/_//\\ \\_\\ \\/___/ \n \\ \\____/ \n \\/___/\n \nUnderscore.js is a utility-belt library for JavaScript that provides \nsupport for the usual functional suspects (each, map, reduce, filter...) \nwithout extending any core JavaScript objects.\n\nFor Docs, License, Tests, and pre-packed downloads, see:\nhttp://documentcloud.github.com/underscore/\n\nMany thanks to our contributors:\nhttps://github.com/documentcloud/underscore/contributors\n", 23 | "_id": "underscore@1.3.3", 24 | "_from": "underscore" 25 | } 26 | -------------------------------------------------------------------------------- /node_modules/underscore/raw/underscore.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuyanfei/tdx_fetchKlineData/dbd736a6d20326836fb482d3210b260bc0edc152/node_modules/underscore/raw/underscore.psd -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tdx_fetchKlineData", 3 | "version": "0.1.0", 4 | "description": "tdx_fetchKlineData", 5 | "author": "wuyanfei", 6 | "dependencies": { 7 | "underscore": ">= 1.2.3", 8 | "async":">= 0.1.18", 9 | "redis": ">= 0.7.2", 10 | "hiredis":">=0.1.14", 11 | "commander":">=1.1.1" 12 | }, 13 | "engines": { 14 | "node": "0.8.x" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var buf = new Buffer(32); 2 | 3 | buf[0] = 0xCD; 4 | buf[1] = 0x00; 5 | buf[2] = 0x3F; 6 | buf[3] = 0x02; 7 | console.log(0xC); 8 | console.log(buf.readUInt16LE(0)); -------------------------------------------------------------------------------- /unpacker.js: -------------------------------------------------------------------------------- 1 | /* 2 | struct TDX_DAY 3 | { 4 | int date; 5 | int open; //元 6 | int high; 7 | int low; 8 | int close; 9 | float amount; //元 10 | int vol; //股 1手=100股 11 | int reservation; 12 | } ; 13 | */ 14 | 15 | function readKLineUnit(buff, offset) { 16 | var step = 0, date, open, high, low, close, amount, vol, reservation; 17 | date = buff.readInt32LE(offset + step); 18 | step += 4; 19 | open = buff.readInt32LE(offset + step) / 100; 20 | step += 4; 21 | high = buff.readInt32LE(offset + step) / 100; 22 | step += 4; 23 | low = buff.readInt32LE(offset + step) / 100; 24 | step += 4; 25 | close = buff.readInt32LE(offset + step) / 100; 26 | step += 4; 27 | amount = buff.readFloatLE(offset + step); 28 | step += 4; 29 | vol = buff.readInt32LE(offset + step); 30 | step += 4; 31 | reservation = buff.readInt32LE(offset + step); 32 | return [ date, high.toFixed(3), open.toFixed(3), low.toFixed(3), close.toFixed(3), vol, amount, reservation ]; 33 | } 34 | exports.unpackDayKline = function(data) { 35 | var totalLength = data.length, unitLength = 32, dayCount = totalLength 36 | / unitLength, i = 0, offset = 0, results = []; 37 | 38 | for (i = 0; i < dayCount; i++) { 39 | results.push(readKLineUnit(data, i * 32)); 40 | } 41 | return results; 42 | } 43 | 44 | /* 45 | * 46 | * struct TDX_5MIN { unsigned short nianyue; unsigned short xiaoshifenzhong; 47 | * float open; float high; float low; float close; float chengjiaoe; int 48 | * chengjiaoliang; int reservation; }; 49 | */ 50 | /* 51 | * function getLc5DateOld(dayMonth) { var date = new Date('2012-11-14'); date2 = 52 | * date.addDays(dayMonth - 17497); return Date.format(date2,'Ymd'); } 53 | */ 54 | 55 | function getLc5Date(dayMonth) { 56 | var timeString = '2012-11-13'; 57 | var timeCount = 17497; 58 | if(dayMonth < 17485) { 59 | timeCount = 17415; 60 | timeString = '2012-10-31'; 61 | } 62 | var date = new Date(timeString); 63 | date.setDate(date.getDate() + dayMonth - timeCount); 64 | return date.getFullYear() + '' + (date.getMonth() + 1) + '' + date.getDate(); 65 | } 66 | 67 | function read5MinuteKLineUnit(buff, offset) { 68 | var step = 0, nianyue, xiaoshifenzhong, open, high, low, close, amount, vol, reservation; 69 | nianyue= buff.readUInt16LE(offset + step); 70 | var xxx = nianyue; 71 | //console.log(xxx); 72 | nianyue = getLc5Date(nianyue) + ' '; 73 | var t = ''; 74 | if (nianyue.length == 6) { 75 | t = nianyue.substring(0, 4); 76 | t = t + '0' + nianyue.substring(4, 5); 77 | t = t + '0' + nianyue.substring(5, 6); 78 | } else if (nianyue.length == 7) { 79 | t = nianyue.substring(0, 4); 80 | var m = nianyue.substring(4, 6); 81 | if (parseFloat(m) > 12) { 82 | m = '0' + nianyue.substring(4, 5); 83 | t = t + '' + m + '' + nianyue.substring(5, 7); 84 | } else { 85 | t = t +m+ '0' + nianyue.substring(6, 7); 86 | } 87 | }else{ 88 | t = nianyue; 89 | } 90 | nianyue = t; 91 | //console.log(nianyue); 92 | step += 2; 93 | xiaoshifenzhong = buff.readUInt16LE(offset + step); 94 | //console.log(xiaoshifenzhong); 95 | var xiaoshi = Math.floor(xiaoshifenzhong / 60); 96 | if (xiaoshi < 10) { 97 | xiaoshi = '0' + xiaoshi; 98 | } 99 | var minute = xiaoshifenzhong % 60; 100 | if (minute < 10) { 101 | minute = '0' + minute; 102 | } 103 | xiaoshifenzhong = xiaoshi + '' + minute; 104 | step += 2; 105 | open = buff.readFloatLE(offset + step); 106 | step += 4; 107 | high = buff.readFloatLE(offset + step); 108 | step += 4; 109 | low = buff.readFloatLE(offset + step); 110 | step += 4; 111 | close = buff.readFloatLE(offset + step); 112 | step += 4; 113 | amount = buff.readFloatLE(offset + step); 114 | step += 4; 115 | vol = buff.readInt32LE(offset + step); 116 | step += 4; 117 | reservation = buff.readInt32LE(offset + step); 118 | var time = nianyue+''+xiaoshifenzhong; 119 | //console.log(xxx,time); 120 | return [time, high.toFixed(3),open.toFixed(3), low.toFixed(3), close.toFixed(3), vol,amount ]; 121 | } 122 | exports.unpackMinuteKLine = function(data) { 123 | var totalLength = data.length, unitLength = 32, dayCount = totalLength 124 | / unitLength, i = 0, results = []; 125 | for (i = 0; i < dayCount; i++) { 126 | results.push(read5MinuteKLineUnit(data, i * 32)); 127 | } 128 | var tempArray = []; 129 | for ( var j = 0; j < results.length; j++) { 130 | var temp = results[j]; 131 | for ( var t = 2; t < temp.length - 1; t++) { 132 | temp[t] = parseFloat(temp[t]).toFixed(3); 133 | } 134 | //console.log(temp[0]); 135 | tempArray.push(temp); 136 | } 137 | return tempArray; 138 | }; 139 | --------------------------------------------------------------------------------