{"action":"reopened","issue":{"url":"https://api.github.com/repos/NodeRedis/node_redis/issues/616","labels_url":"https://api.github.com/repos/NodeRedis/node_redis/issues/616/labels{/name}","comments_url":"https://api.github.com/repos/NodeRedis/node_redis/issues/616/comments","events_url":"https://api.github.com/repos/NodeRedis/node_redis/issues/616/events","html_url":"https://github.com/NodeRedis/node_redis/issues/616","id":36625905,"number":616,"title":"Bind client methods to the client instance","user":{"login":"balupton","id":61148,"avatar_url":"https://avatars.githubusercontent.com/u/61148?v=3","gravatar_id":"","url":"https://api.github.com/users/balupton","html_url":"https://github.com/balupton","followers_url":"https://api.github.com/users/balupton/followers","following_url":"https://api.github.com/users/balupton/following{/other_user}","gists_url":"https://api.github.com/users/balupton/gists{/gist_id}","starred_url":"https://api.github.com/users/balupton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/balupton/subscriptions","organizations_url":"https://api.github.com/users/balupton/orgs","repos_url":"https://api.github.com/users/balupton/repos","events_url":"https://api.github.com/users/balupton/events{/privacy}","received_events_url":"https://api.github.com/users/balupton/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NodeRedis/node_redis/labels/Feature%20Request","name":"Feature Request","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-06-26T23:58:15Z","updated_at":"2015-09-25T01:46:40Z","closed_at":null,"body":"It would be nice for the constructor of the redis client, to bind it's method to the instance, so I can throw around the methods using functional programming paradigms, without having to bind them myself. E.g. this is some code I recently wrote using ChainyJS and FeathersJS:\r\n\r\n``` javascript\r\nvar services = {\r\n\t'/rsku': {\r\n\t\t// Return all todos from this service\r\n\t\tfind: function(params, next) {\r\n\t\t\tChainy.create()\r\n\t\t\t\t.set('rskus')\r\n\t\t\t\t.action(config.r.hgetall.bind(config.r))\r\n\t\t\t\t.decodetable()\r\n\t\t\t\t.done(next)\r\n\t\t},\r\n\r\n\t\t// Get an object\r\n\t\tget: function(id, params, next) {\r\n\t\t\tChainy.create()\r\n\t\t\t\t.set(['rskus', id])\r\n\t\t\t\t.action(config.r.hget.bind(config.r))\r\n\t\t\t\t.decode()\r\n\t\t\t\t.done(next)\r\n\t\t},\r\n\r\n\t\t// Create a new Todo with the given data\r\n\t\tcreate: function(data, params, next) {\r\n\t\t\tconsole.log(data, params)\r\n\t\t\tChainy.create()\r\n\t\t\t\t.set(['rskus:count'])\r\n\t\t\t\t.action(config.r.incr.bind(config.r))\r\n\t\t\t\t.log()\r\n\t\t\t\t.action(function(id){\r\n\t\t\t\t\tdata.id = id\r\n\t\t\t\t\treturn ['rskus', id, JSON.stringify(data)]\r\n\t\t\t\t})\r\n\t\t\t\t.action(config.r.hsetnx.bind(config.r))\r\n\t\t\t\t.action(function(result){\r\n\t\t\t\t\tif ( !result ) {\r\n\t\t\t\t\t\terr = new Error('id already existed')\r\n\t\t\t\t\t\treturn err\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn data\r\n\t\t\t\t})\r\n\t\t\t\t.done(next)\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nWould be great if I could get rid of that `.bind(config.r)`\r\n\r\nThe following code added to the constructor of the client should do the trick:\r\n\r\n``` javascript\r\nvar client = this;\r\nObject.keys(client).forEach(function(key){\r\n\tvar method = client[key];\r\n\tif ( typeof method !== 'function' )  return;\r\n\tclient[key] = method.bind(client)\r\n});\r\n```"}}