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

怎么 select db 啊? #50

Open
yaqiangxue opened this issue Dec 4, 2019 · 3 comments
Open

怎么 select db 啊? #50

yaqiangxue opened this issue Dec 4, 2019 · 3 comments

Comments

@yaqiangxue
Copy link

怎么select 到某个db啊,如果是单机模式的时候。

bool bRet = redisclient.ConnectRedis("127.0.0.1", 6379, 4);

redisclient.RedisCommand(result, "select %d", 1); // 1.
RedisResult result;
redisclient.RedisCommand(result, "set %s %s", "key", "hello"); //2

这里的1和2 ,应该是不同的2个redis连接对象吧?

@0xsky
Copy link
Owner

0xsky commented Sep 17, 2020

由于xredis底层采用连接池。默认每个连接都是0号db,xredis不支持在执行命令前选择db。

@0xsky
Copy link
Owner

0xsky commented Sep 17, 2020

第二个问题:”这里的1和2 ,应该是不同的2个redis连接对象吧?“
bool bRet = redisclient.ConnectRedis("127.0.0.1", 6379, 4);
redisclient.RedisCommand(result, "select %d", 1); // 1.
RedisResult result;
redisclient.RedisCommand(result, "set %s %s", "key", "hello"); //2
上面使用的应该是支持redis官方集群的client实现,
上面执行的两个命令,会通过key计算选择到同一个redis节点 ,
但是,xredis内部对每个节点都可能有一个连接池,每次执行命令,都是从连接池取一个连接,再执行。
所以,上面的 1, 2 命令执行时,可能使用不同的redis client连接。

@0xsky
Copy link
Owner

0xsky commented Jun 13, 2023 via email

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

No branches or pull requests

2 participants