Created
July 14, 2015 08:59
-
-
Save refaelos/523d841588e8a01f5462 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 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