Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save refaelos/523d841588e8a01f5462 to your computer and use it in GitHub Desktop.
Save refaelos/523d841588e8a01f5462 to your computer and use it in GitHub Desktop.
/**
*
* This node script will rename all keys according to a given pattern.
*
**/
var redisClient = redis.createClient(config.redis.port, config.redis.host),
search = '*something*', // will rename all keys that contains 'something'
postfix = '.postfix', // all keys will get the postfix '.postfix'
prefix = 'prefix.'; // all keys will get the prefix '.prefix'
redisClient.on('erro', function (err) {
console.error('(redisClient) Redis Error ' + err);
});
redisClient.on('connect', function () {
console.info('(redisClient) connected to redis server at: ' + config.redis.host + ':' + config.redis.port);
});
redisClient.keysAsync(search)
.then(function(keys) {
var multi = redisClient.multi();
_.each(keys, function(key) {
multi.rename(key, prefix+key+postfix);
});
return multi.execAsync();
})
.then(function() {
console.log('DONE!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment