{"action":"closed","issue":{"url":"https://api.github.com/repos/luin/ioredis/issues/170","repository_url":"https://api.github.com/repos/luin/ioredis","labels_url":"https://api.github.com/repos/luin/ioredis/issues/170/labels{/name}","comments_url":"https://api.github.com/repos/luin/ioredis/issues/170/comments","events_url":"https://api.github.com/repos/luin/ioredis/issues/170/events","html_url":"https://github.com/luin/ioredis/issues/170","id":109820717,"number":170,"title":"Cluster: problem when using Slaves for READ operations","user":{"login":"Adrien-P","id":5764896,"avatar_url":"https://avatars.githubusercontent.com/u/5764896?v=3","gravatar_id":"","url":"https://api.github.com/users/Adrien-P","html_url":"https://github.com/Adrien-P","followers_url":"https://api.github.com/users/Adrien-P/followers","following_url":"https://api.github.com/users/Adrien-P/following{/other_user}","gists_url":"https://api.github.com/users/Adrien-P/gists{/gist_id}","starred_url":"https://api.github.com/users/Adrien-P/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Adrien-P/subscriptions","organizations_url":"https://api.github.com/users/Adrien-P/orgs","repos_url":"https://api.github.com/users/Adrien-P/repos","events_url":"https://api.github.com/users/Adrien-P/events{/privacy}","received_events_url":"https://api.github.com/users/Adrien-P/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/luin/ioredis/labels/discussion","name":"discussion","color":"fef2c0"}],"state":"closed","locked":false,"assignee":{"login":"luin","id":635902,"avatar_url":"https://avatars.githubusercontent.com/u/635902?v=3","gravatar_id":"","url":"https://api.github.com/users/luin","html_url":"https://github.com/luin","followers_url":"https://api.github.com/users/luin/followers","following_url":"https://api.github.com/users/luin/following{/other_user}","gists_url":"https://api.github.com/users/luin/gists{/gist_id}","starred_url":"https://api.github.com/users/luin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luin/subscriptions","organizations_url":"https://api.github.com/users/luin/orgs","repos_url":"https://api.github.com/users/luin/repos","events_url":"https://api.github.com/users/luin/events{/privacy}","received_events_url":"https://api.github.com/users/luin/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/luin/ioredis/milestones/3","html_url":"https://github.com/luin/ioredis/milestones/2.0.0","labels_url":"https://api.github.com/repos/luin/ioredis/milestones/3/labels","id":1308478,"number":3,"title":"2.0.0","description":"","creator":{"login":"luin","id":635902,"avatar_url":"https://avatars.githubusercontent.com/u/635902?v=3","gravatar_id":"","url":"https://api.github.com/users/luin","html_url":"https://github.com/luin","followers_url":"https://api.github.com/users/luin/followers","following_url":"https://api.github.com/users/luin/following{/other_user}","gists_url":"https://api.github.com/users/luin/gists{/gist_id}","starred_url":"https://api.github.com/users/luin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luin/subscriptions","organizations_url":"https://api.github.com/users/luin/orgs","repos_url":"https://api.github.com/users/luin/repos","events_url":"https://api.github.com/users/luin/events{/privacy}","received_events_url":"https://api.github.com/users/luin/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":4,"state":"open","created_at":"2015-09-16T13:48:30Z","updated_at":"2016-03-13T05:24:25Z","due_on":null,"closed_at":null},"comments":12,"created_at":"2015-10-05T15:20:39Z","updated_at":"2016-03-13T05:24:25Z","closed_at":"2016-03-13T05:24:25Z","body":"I'm using Redis in Cluster mode with ioredis. \r\nI discovered the `{ readOnly: true }` option which looks amazing.\r\nHowever, I've got some new MOVED errors since using this option.\r\nIt is only happening on write operations (`del`, `hincrby`, etc.). \r\nI looked at the code and this piece of code (in cluster.js) attracted my attention:\r\n```\r\n          if (_this.options.readOnly) {\r\n            redis = _this.selectRandomNodeForSlot(targetSlot);\r\n          } else {\r\n            redis = _this.slots[targetSlot].masterNode;\r\n          }\r\n```\r\nMy guess: when the option readOnly is activated, it selects randomly one of the nodes that is reponsible of the targetSlot. In a setup where you've got a Slave for each Master, the selection is made between two nodes (one Master and its Slave). It means that the Read operations are randomly distributed between these two nodes, which is the objective (even though I originally thought it would only go on Slave nodes).\r\nHowever, it seems that the same process is applied for Write operations. It creates an issue because if the Slave node is selected for this operation, it will return a MOVED error. Eventually, with a few retries there is a good chance that the Master node will be picked by the random selector. So the operation has a good chance of succeeding. However, it looks very inefficient and with a lot of operations you'd get some operations actually failing.\r\nPlease let me know if it's a bug or if I'm not using the library properly\r\n  "}}