Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple DB support and "SELECT" command support #61

Open
XiaoHeitu opened this issue Mar 21, 2024 · 8 comments
Open

Multiple DB support and "SELECT" command support #61

XiaoHeitu opened this issue Mar 21, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@XiaoHeitu
Copy link
Contributor

XiaoHeitu commented Mar 21, 2024

Can multiple DB support and "SELECT" command support be added. If you want to replace Redis, it is difficult to achieve without multi DB support. If supported, replacing Redis would be much more convenient.

@darrenge darrenge added the enhancement New feature or request label Mar 21, 2024
@pomazanbohdan
Copy link

I would also like to use many databases in one instance.
But now I can’t even test the operation of application, since it requires a connection indicating the database.
What is the default database name?

@badrishc
Copy link
Contributor

The default, and only, database in Garnet at the moment is 0 (zero).

@Ramon403
Copy link

Yes, I am testing whether replacing Redis is feasible,

Found no difference between GetDatabase (0) and GetDatabase (6)

The key: value written in db0 can be read and overwritten in db6, which will affect the original business

@XiaoHeitu
Copy link
Contributor Author

The default, and only, database in Garnet at the moment is 0 (zero).

Is this intentionally designed to ensure the excellent performance of "garnet"?

@XiaoHeitu
Copy link
Contributor Author

我有一个想法不知道当讲不当讲。算了先讲了吧。我英语不太行。直接写中文了,要是有大佬能看懂的话。能不能请大佬帮忙翻译一下。

先说目的:
1、想要让SELECT命令真正的用起来。
2、可以模拟出 多DB的效果。
3、不改动现在单DB的程序结构
4、尽量不影响整体性能

下面说方案:
1、设置一个绝对不使用的 DB_ID,用来模拟最大ID号。比如16,当客户端执行 SELECT 16时,返回ERR提示。这样做的目的是为了让Redis客户端程序(如:RedisDesktopManager) 以为16是最大ID。而不会继续向检测最大ID。

2、当某个会话调用 SELECT命令时,正常返回OK。前记录下应该会话前最后一次调用SELECT 时的DB_ID。当然这里可以做一个突破。我们可以允许使用 非数字ID

3、既然我们的会话中已经保存了 DB_ID。那么为了模拟出多DB的效果。在使用所有与key相关的命令时, 默认给 输入的key 加上前缀 "{DB_ID}:",懂的都懂。这样就能保证不同的DB_ID中的内容不会相互覆盖。

这样一来,虽然 所有内容都保存在同一个DB中。但都被 前缀进行了区分。也就完成了对 redis 多DB的模拟。对之前使用redis 项目也能进行良好的兼容。

@XiaoHeitu
Copy link
Contributor Author

like this:
image

@XiaoHeitu
Copy link
Contributor Author

代码部分在我自己仓库的分支上,这是提交记录:
XiaoHeitu@db4d673

@XiaoHeitu
Copy link
Contributor Author

不知道这样做,可行不?会不会有什么问题?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants