How do I change between redis database?

前端 未结 2 1820
Happy的楠姐
Happy的楠姐 2020-12-24 00:27

I am new with redis and I didn\'t figured out how to create and change to another redis database.

How do I do this?

2条回答
  •  生来不讨喜
    2020-12-24 01:00

    Note: this is not a direct answer to the OP's question. However, this text is too long for a comment, and I thought I'd share it anyway, to clarify things to the OP. Hope I don't break too many SO rules by doing this...

    Some extra info on multiple databases:

    Please note that using multiple databases in one redis instance is discouraged.

    It is a nice feature for playing around and getting to know redis.

    In more serious setups, if you have multiple ports at your disposal, it's preferred and more performant to use separate instances. At our company, we run about 50 instances on the development/staging server, and about 5 on the production server.

    The reason is, that redis transactions are only atomic within one db number anyway. Most (if not all) clients nicely seperate that for you in the connect() phase. And if you have to connect separately, it's just as easy to connect to a different port.

    The core of redis is also single threaded. That's one of the things that makes redis so quick and simple. Everything is sequential. If you use multiple instances instead of just one, you gain the benefit of multi-processing (on multi-core machines).

提交回复
热议问题