lua-resty-redis icon indicating copy to clipboard operation
lua-resty-redis copied to clipboard

Connect to database non-zero

Open cbarraford opened this issue 11 years ago • 5 comments
trafficstars

It seems to me (unless I'm missing something) that lua-resty-redis only allows you to connect to database 0 of redis. You cannot specify another number.

ie this uri connects to database 7

redis://[email protected]:6379/7

cbarraford avatar Nov 15 '14 14:11 cbarraford

@CBarraford Just use the select() method to choose which "database" to use. See the original redis documentation for the corresponding select command for more details:

http://redis.io/commands/SELECT

agentzh avatar Nov 15 '14 19:11 agentzh

Thanks. But I was hoping for a way to connect to a specific db. Not connect to db 0 and switch to db 1 everytime I connect. 

— Sent from Mailbox

On Sat, Nov 15, 2014 at 2:03 PM, Yichun Zhang [email protected] wrote:

@CBarraford Just use the select() method to choose which "database" to use. See the original redis documentation for the corresponding select command for more details:

http://redis.io/commands/SELECT

Reply to this email directly or view it on GitHub: https://github.com/openresty/lua-resty-redis/issues/53#issuecomment-63183866

cbarraford avatar Nov 17 '14 13:11 cbarraford

@CBarraford You can check if the connection comes from the connection pool by means of the get_reused_times method. You only need to run the select command if it is a newly established connection.

BTW, if you have connections to different databases (but to the same redis server), then you also need separate connection pools for different databases (by specifying the "pool" option of the connect method).

agentzh avatar Nov 17 '14 19:11 agentzh

Thanks. 

— Sent from Mailbox

On Mon, Nov 17, 2014 at 2:48 PM, Yichun Zhang [email protected] wrote:

@CBarraford You can check if the connection comes from the connection pool by means of the get_reused_times method. You only need to run the select command if it is a newly established connection.

BTW, if you have connections to different databases (but to the same redis server), then you also need separate connection pools for different databases (by specifying the "pool" option of the connect method).

Reply to this email directly or view it on GitHub: https://github.com/openresty/lua-resty-redis/issues/53#issuecomment-63363972

cbarraford avatar Nov 17 '14 19:11 cbarraford

I tried red:select(4) but it still saved data in db0.

dromer avatar Nov 12 '19 15:11 dromer