Created
July 22, 2012 13:19
-
-
Save tblobaum/3159668 to your computer and use it in GitHub Desktop.
script to rename lots of redis keys
This file contains hidden or 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
var Redis = require('redis-stream') | |
, client = new Redis(6379, 'localhost', process.argv[2] || 0) | |
, stream = client.stream() | |
var keys = client.stream('keys') | |
process.stdin | |
.pipe(Redis.es.split()) | |
.pipe(keys) | |
.pipe(Redis.es.mapSync(function (key) { | |
var newkey = key.replace(/user_/, 'users::') // regex to rename key with | |
return Redis.parse([ 'rename', key, newkey ]) | |
})) | |
.pipe(stream.redis) | |
.pipe(Redis.es.join('\r\n')) | |
.pipe(process.stdout) | |
console.log('enter a `keys` pattern, e.g. *') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment