具有多个项目的开发机器上的 Redis 数据库 [英] Redis databases on a dev machine with multiple projects

查看:57
本文介绍了具有多个项目的开发机器上的 Redis 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当其中一些项目使用 Redis 数据库时,您如何在开发和/或测试机器上管理多个项目?

How do you manage multiple projects on your development and/or testing machine, when some of those projects use Redis databases?

有两个主要问题:

  1. Redis 没有命名数据库(只有数字 0-16)
  2. 测试可能会在每次运行时执行 FLUSHDB

现在,我认为我们有三个选择:

Right now, I think we have three options:

  1. 为每个项目、每个开发和测试环境分配不同的数据库
  2. 使用类似redis-namespace
  3. 的项目名称前缀键
  4. 随时在项目之间切换时对数据库进行核对和播种

如果多个项目为主要用途分配0"而为测试等分配1",则第一个是有问题的.即使项目 B 决定更改为2"和3",项目中的另一个成员可能会为他在另一个项目中发生冲突.换句话说,这种方法对 SCM 不友好.

The first one is problematic if multiple projects assign "0" for the main use and "1" for the test and such. Even if Project B decided to change to "2" and "3", another member in the project might have a conflict in another projects for him. In other words, that approach is not SCM friendly.

对于第二个,这是一个坏主意,因为它在运行时性能和内存效率上增加了不必要的开销.而且无论您做什么,当您加入该项目时,另一个项目可能已经在使用相同的密钥.

For the second one, it's a bad idea simply because it adds needless overhead on runtime performance and memory efficiency. And no matter what you do, another project might be already using the same key coincidentally when you joined the project.

第三个选项是妥协的产物,但有时我希望在为其他项目部署小补丁时保持本地数据不变.

The third option is rather a product of compromise, but sometimes I want to keep my local data untouched while I deploy small patches for another projects.

我知道这可能是 Redis 的功能请求,但我现在需要一个解决方案.

I know this could be a feature request for Redis, but I need a solution now.

有什么想法、做法吗?

推荐答案

如果项目是独立的,所以不需要共享数据,最好使用多个redis实例——每个项目配置有一个端口号而不是数据库名称/ID.为每个实例创建一个适当命名的配置文件和启动脚本,以便您只需单击一下即可运行所需的任何实例.

If the projects are independent and so do not need to share data, it is much better to use multiple redis instances - each project configuration has a port number rather than a database name/id. Create an appropriately named config file and startup script for each one so that you can get whichever instance you need running with a single click.

确保更新每个配置文件中的保存设置以及设置端口 - 使用同一个 dump.rdb 文件的多个实例可以工作,但会导致一些相当混乱的错误.

Make sure you update the save settings in each config file as well as setting the ports - Multiple instances using the same dump.rdb file will work, but lead to some rather confusing bugs.

我还使用单独的实例进行开发和测试,以便测试实例永远不会向磁盘写入任何内容,并且可以在每次测试开始时刷新.

I also use separate instances for development and testing so that the test instance never writes anything to disk and can be flushed at the start of each test.

这篇关于具有多个项目的开发机器上的 Redis 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆