is there any command return the currently selected db?

4,155 views
Skip to first unread message

litao cheng

unread,
Mar 20, 2010, 11:26:41 PM3/20/10
to Redis DB
hi, buddies.

I find the wiki page about the commands, I can't find a command return
the currently selected db.
Is it need to add new command to return this info? corresponding with
the SELECT command.

Best Regards

litao cheng

mythz

unread,
Mar 21, 2010, 11:07:33 AM3/21/10
to Redis DB
Generally I have not needed this as the Redis client that sets the
database will know the 'selected database'.
When you first connect to Redis, the initial database is '0', it will
stay at '0' for the duration of the connection until its changed.
This setting is 'per connection', so does not affect any new
connections which will start at the default db of 0.

- Demis

litao cheng

unread,
Mar 21, 2010, 10:27:23 PM3/21/10
to redi...@googlegroups.com
thanks Demis.
I will save the selected db info in my client.
:)

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.


Anton Bessonov

unread,
Mar 22, 2010, 10:22:27 AM3/22/10
to redi...@googlegroups.com
You can use this example for ugly workaround:

from itertools import count
from redis import Redis, ResponseError

r = Redis()
try:
[r.select(x) and r.set('selected_db', x) for x in count()]
except ResponseError, e:
if not str(e) == 'invalid DB index':
raise e


>>> r.select(5)
'OK'

>>> r.get('selected_db')
5


> thanks Demis.
> I will save the selected db info in my client.
> :)
>
> On Sun, Mar 21, 2010 at 11:07 PM, mythz <demis....@gmail.com
> <mailto:demis....@gmail.com>> wrote:
>
> Generally I have not needed this as the Redis client that sets the
> database will know the 'selected database'.
> When you first connect to Redis, the initial database is '0', it will
> stay at '0' for the duration of the connection until its changed.
> This setting is 'per connection', so does not affect any new
> connections which will start at the default db of 0.
>
> - Demis
>
> On Mar 21, 3:26 am, litao cheng <litaoch...@gmail.com

> <mailto:litaoch...@gmail.com>> wrote:
> > hi, buddies.
> >
> > I find the wiki page about the commands, I can't find a command
> return
> > the currently selected db.
> > Is it need to add new command to return this info? corresponding
> with
> > the SELECT command.
> >
> > Best Regards
> >
> > litao cheng
>
> --
> You received this message because you are subscribed to the Google
> Groups "Redis DB" group.
> To post to this group, send email to redi...@googlegroups.com

> <mailto:redi...@googlegroups.com>.


> To unsubscribe from this group, send email to
> redis-db+u...@googlegroups.com

> <mailto:redis-db%2Bunsu...@googlegroups.com>.

Reply all
Reply to author
Forward
0 new messages