nosco / redis-ns

This module enables you to create Redis namespaces.
1 stars 3 forks source link

Consider refactoring many of these methods using some metaprogramming #2

Open jhliberty opened 8 years ago

jhliberty commented 8 years ago

Quite a few of the functions you define in index.js have the exact same signature except for a name property change... if you are manually writing these out consider refactoring to something like this function here. Reducing how many times you have to write things means less head to update without errors.

jhliberty commented 8 years ago

Or better yet, use an es6 proxy could take care of that really easy.. Just trap out the construct and the apply calls.

On the constructor set the namespace just like you are doing now when you do new RedisNS('namespace', redisClient) and for the apply calls just take the namespace, add it to the key and Reflect the call back to the redisclient with the new namespaced key and you're good to go. No worrying about their implementation logic really at all... and it would be a fair bit less trouble to update

proxy construct handler apply handler

reflect