Yes, that's why I ask this question. After application restart, I need 
query Mysql only once, but how to combine query code with http server code.

在 2013年7月26日星期五UTC+8下午7时46分33秒,Alan Hoffmeister写道:
>
> Well, you need to try to connect to Redis, if it fails throw an error 
> and restart the app (using forever[1] or supervisor[2]), then you need 
> to query MySQL for the last ID and set the value inside Redis, then 
> run the server, it's kinda simple :-) 
>
> 1 - https://github.com/nodejitsu/forever 
> 2 - https://github.com/isaacs/node-supervisor 
> -- 
> Att, 
> Alan Hoffmeister 
>
>
> 2013/7/26 linbo liao <[email protected] <javascript:>>: 
> > Just simplify the follow. 
> > 
> > For each request,  application get an id from redis(using incr command), 
> and 
> > store id to Mysql in other module. When redis is down, application need 
> get 
> > latest id from Mysql and reset it in redis, to make sure no id is 
> duplicated 
> > when created from redis for anytime. 
> > 
> > Thanks, 
> > Linbo 
> > 
> > 在 2013年7月26日星期五UTC+8下午7时27分05秒,Alan Hoffmeister写道: 
> >> 
> >> https://gist.github.com/alanhoff/6088166 
> >> 
> >> 1 - It will depends on how your driver is configured. 
> >> 2 - Use cache to avoid performance issue. 
> >> -- 
> >> Att, 
> >> Alan Hoffmeister 
> >> 
> >> 
> >> 2013/7/26 linbo liao <[email protected]>: 
> >> > Hi All, 
> >> > 
> >> > A simple question, I use nodejs for HTTP restful API service. Now I 
> want 
> >> > query some mysql data before http server start, the code snippet: 
> >> > 
> >> > var price = -1; 
> >> > var userId = 'some user provided value'; 
> >> > var sql    = 'SELECT max(price) FROM users WHERE id = ' + 
> >> > connection.escape(userId); 
> >> > connection.query(sql, function(err, results) { 
> >> >   price = results.price; 
> >> > }); 
> >> > 
> >> > server = http.createServer(function (request, response) { 
> >> >       handler(request);   //response depend on price 
> >> > }).listen(8012); 
> >> > 
> >> > Here are two solution to combine mysql query and http server code. 
> >> > 
> >> > 1. put http server in query callback. Will it cause Mysql keep 
> connect 
> >> > during http server running? If Mysql disconnect (usually after 8 
> hours), 
> >> > application works fine? 
> >> > 
> >> > 2. put query in every request, which cause Mysql query each time for 
> >> > every 
> >> > request, maybe performance issue. 
> >> > 
> >> > Any other suggestion for this situation? 
> >> > 
> >> > Thanks, 
> >> > 
> >> > Linbo 
> >> > 
> >> > 
> >> > 
> >> > -- 
> >> > -- 
> >> > Job Board: http://jobs.nodejs.org/ 
> >> > Posting guidelines: 
> >> > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines 
> >> > You received this message because you are subscribed to the Google 
> >> > Groups "nodejs" group. 
> >> > To post to this group, send email to [email protected] 
> >> > To unsubscribe from this group, send email to 
> >> > [email protected] 
> >> > For more options, visit this group at 
> >> > http://groups.google.com/group/nodejs?hl=en?hl=en 
> >> > 
> >> > --- 
> >> > You received this message because you are subscribed to the Google 
> >> > Groups 
> >> > "nodejs" group. 
> >> > To unsubscribe from this group and stop receiving emails from it, 
> send 
> >> > an 
> >> > email to [email protected]. 
> >> > For more options, visit https://groups.google.com/groups/opt_out. 
> >> > 
> >> > 
> > 
> > -- 
> > -- 
> > Job Board: http://jobs.nodejs.org/ 
> > Posting guidelines: 
> > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines 
> > You received this message because you are subscribed to the Google 
> > Groups "nodejs" group. 
> > To post to this group, send email to [email protected]<javascript:> 
> > To unsubscribe from this group, send email to 
> > [email protected] <javascript:> 
> > For more options, visit this group at 
> > http://groups.google.com/group/nodejs?hl=en?hl=en 
> > 
> > --- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "nodejs" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to [email protected] <javascript:>. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
> > 
> > 
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to