2011-11-24 69 views
25

以下按预期工作。但是,如何将数据插入第四个数据库而不是命令提示符中的默认“0”?在redis命令提示符下使用不同的数据库

# 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 
+1

重要的是要注意,redis-cli不允许多个命令。 – seppo0010

回答

47

只需使用-n参数来选择DB编号。它自Redis 2.4.2开始提供。

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

redis-cli -n 4 set my_pass testing 
+0

谢谢 - 我希望他们将此添加到文档 - http://redis.io/commands/select –

11

启动CLI通过发出命令:

redis-cli 

然后使用下面的命令:

select <db number> 

例如:

select 4 
+0

感谢您的。如果任何人使用Python以及redis-cli,只需在初始化新的redis客户端时将'db = 4'添加到连接参数。扩展示例:'POOL = redis.ConnectionPool(host = '10.0.0.1',port = 6379,db = 4)'这也被引用在答案[here](http://stackoverflow.com/questions/12967107/管理连接到Redis的 - 从 - 蟒蛇#12973514) – jamescampbell

相关问题