Namespaces in Redis?

前端 未结 3 1274
清酒与你
清酒与你 2021-02-04 23:53

Is it possible to create namespaces in Redis?

From what I found, all the global commands (count, delete all) work on all the objects. Is there a way to create sub-spaces

3条回答
  •  长情又很酷
    2021-02-05 00:27

    If you are using Node, ioredis has transparent key prefixing, which works by having the client prepend a given string to each key in a command. It works in the same way that Ruby's redis-namespace does. This client-side approach still puts all your keys into the same database, but at least you add some structure, and you don't have to use multiple databases or servers.

    var fooRedis = new Redis({ keyPrefix: 'foo:' });
    fooRedis.set('bar', 'baz');  // Actually sends SET foo:bar baz
    

提交回复
热议问题