6

I want know how we can delete all keys for a specific namespace only?

FLUSHALL

delete all keys, its a problem when using multiple app with same redis server.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Matrix
  • 3,458
  • 6
  • 40
  • 76

3 Answers3

4

you can not flush a namespace in Redis, while you can flush all keys matching a pattern.

$ redis-cli --scan --pattern 'user:*' | xargs redis-cli unlink
flguo
  • 101
  • 1
  • 4
0

You should use (always with caution) FLUSHDB after ensuring you had SELECTed the right database.

On a related subject, you should consider using shared databases really carefully - there are all sorts of nastiness that can ensue from as well as the fact that it isn't compatible with the upcoming Redis cluster (v3 that is in beta, expected release EOY). You may want to look at this benchmark post about Shared vs. Dedicated Redis instances for more background on the subject.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
0
flush(namespace){
        console.log('delete namespace: ', namespace);
        redis.defineCommand('flush', {
            numberOfKeys: 0,
            lua: 'local keys = redis.call(\'keys\', ARGV[1]) for i=1,#keys,5000 do ' +
            'redis.call(\'del\', unpack(keys, i, math.min(i+4999, #keys))) end return keys'
        });
    }