56

dThe following works as expected. But how do I insert the data into forth database instead of default "0" from command prompt?

# echo -n "testing" | /home/shantanu/redis-2.4.2/src/redis-cli -x set my_pass
OK

# echo -n "testing" | /home/shantanu/redis-2.4.2/src/redis-cli -x select 4; set my_pass
(error) ERR wrong number of arguments for 'select' command
smilyface
  • 5,021
  • 8
  • 41
  • 57
shantanuo
  • 31,689
  • 78
  • 245
  • 403

2 Answers2

96

Just use the -n argument to choose DB number. It available since Redis 2.4.2.

echo -n "testing" | redis-cli -n 4 -x set my_pass

or

redis-cli -n 4 set my_pass testing
miaout17
  • 4,715
  • 2
  • 26
  • 32
44

Launch the CLI by issuing command:

redis-cli

Then use the following command:

select <db number>

For example:

select 4
COil
  • 7,201
  • 2
  • 50
  • 98
avichalp
  • 1,100
  • 11
  • 11
  • Thanks for this. In case anyone is using Python in addition to redis-cli, you simply add `db=4` to the connection parameters when you initialize a new redis client. Extended example: `POOL = redis.ConnectionPool(host='10.0.0.1', port=6379, db=4)` which is also referenced at the answer [here](http://stackoverflow.com/questions/12967107/managing-connection-to-redis-from-python#12973514) – james-see Mar 26 '17 at 20:31