{"issue":{"state":"open","created_at":"2011-04-06T19:05:12Z","updated_at":"2011-12-06T12:04:27Z","user":{"gravatar_id":"38ddcefff0db3bd04a6fc06e31d1c01d","id":40774,"url":"https://api.github.com/users/cloudhead","login":"cloudhead","avatar_url":"https://secure.gravatar.com/avatar/38ddcefff0db3bd04a6fc06e31d1c01d?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"comments":4,"body":"I'd like to have an opinion on this issue:\n\nI use different clients for different databases, and so I `select` the database I want when the client is first created. Sometimes, connections get dropped, and so the selected database is no longer selected on reconnect. Of course, I could call `select` before each command, but that seems like a huge waste. So ideally, the command would be run every time the client connects.\n\nBecause of the way node_redis works though, commands sent from the `\"connect\"` event listener will be sent *after* commands which were sent while offline, this is because of the `offline_queue`, and the fact that `ready` is set *after* `\"connect\"` is emitted, so commands in the listener are queued!\n\nThe `\"ready\"` event is then emitted after all this, but at that point the offline commands are already sent, with the wrong database selected.\n\nThe solution I'm currently using, which seems to work is:\n\n      client.on('connect', function () {\n          client.send_anyway = true;\n          client.select(DB);\n          client.send_anyway = false;\n      });\n\nThis makes it so the `select` skips the ready-check, and sends the command before the offline_queue is sent.\n\nHere's where this is all happening:\n\n<https://github.com/mranney/node_redis/blob/master/index.js#L187>\n\nA nice solution would be to emit `\"connect\"` *after* `ready = true`. Another solution would be to have another event there, like `\"connected\"`, which gets emitted after we're ready, but before the queue is sent.\n\nThoughts?\n","assignee":null,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"id":739026,"labels":[],"number":86,"title":"Selecting a database on re-connect - discussion","html_url":"https://github.com/mranney/node_redis/issues/86","closed_at":null,"url":"https://api.github.com/repos/mranney/node_redis/issues/86","milestone":null},"action":"created","comment":{"created_at":"2011-12-06T12:04:27Z","updated_at":"2011-12-06T12:04:27Z","user":{"gravatar_id":"8df4068df7118f27181035089eb1f72c","id":159633,"url":"https://api.github.com/users/maritz","login":"maritz","avatar_url":"https://secure.gravatar.com/avatar/8df4068df7118f27181035089eb1f72c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"It's fixed for me. (ran into the same issue and thought I was already using v0.7.1, turns out I didn't)","id":3031377,"url":"https://api.github.com/repos/mranney/node_redis/issues/comments/3031377"}}