Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. /**
  2. *
  3. * This node script will rename all keys according to a given pattern.
  4. *
  5. **/
  6.  
  7. var redisClient = redis.createClient(config.redis.port, config.redis.host),
  8. search = '*something*', // will rename all keys that contains 'something'
  9. postfix = '.postfix', // all keys will get the postfix '.postfix'
  10. prefix = 'prefix.'; // all keys will get the prefix '.prefix'
  11.  
  12. redisClient.on('erro', function (err) {
  13. console.error('(redisClient) Redis Error ' + err);
  14. });
  15. redisClient.on('connect', function () {
  16. console.info('(redisClient) connected to redis server at: ' + config.redis.host + ':' + config.redis.port);
  17. });
  18.  
  19. redisClient.keysAsync(search)
  20. .then(function(keys) {
  21. var multi = redisClient.multi();
  22. _.each(keys, function(key) {
  23. multi.rename(key, prefix+key+postfix);
  24. });
  25. return multi.execAsync();
  26. })
  27. .then(function() {
  28. console.log('DONE!');
  29. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement