Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * 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!');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement