2011-11-11 38 views
0

我可以使用telnet命令連接到遠程redis並獲取「mytest」鍵的值。以下按預期工作。在命令提示符處輸出遠程服務器

[[email protected] shantanu]# telnet 10.10.10.100 6379 
Trying 10.10.10.100... 
Connected to 10.10.10.100 (10.10.10.100). 
Escape character is '^]'. 
get mytest 
$14 
this is first 

但是我如何在shell腳本中使用它? 我習慣使用連接到mysql如下:

msyql -h10.10.10.100 -uroot [email protected] -e"show databases" 

可用於Redis的一個simialar語法?

回答

2

您也可以使用redis-cli,在Redis的包括

$ ./src/redis-cli --raw GET key 
test 
+0

感謝 「--raw」 一角。但我需要連接到遠程服務器。上述命令將我連接到本地服務器。對? – shantanuo

+0

您可以使用-h 覆蓋該選項-p seppo0010

0

我會用像wget的工具,其目的是從網站獲得的內容,並且非常易於配置和自動設置。你甚至可以逃脫

export myTestKey=`echo "get mytest" | telnet 10.10.10.100 6379` 

如果談話需要比這更復雜,我會結合使用Telnet expect,這是專爲觸發和響應對話。

相關問題