Skip to content

Instantly share code, notes, and snippets.

@tblobaum
Created July 22, 2012 13:19
Show Gist options
  • Save tblobaum/3159668 to your computer and use it in GitHub Desktop.
Save tblobaum/3159668 to your computer and use it in GitHub Desktop.
script to rename lots of redis keys
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