redis mongodb 多資料庫的區別

來源:互聯網
上載者:User

有人問我,redis的多資料庫,是不是啟動多個redis進程,監聽不同的連接埠。從某種層面上來說,這樣可以算是,但是不推薦。

1,redis資料庫

redis的資料庫個數,在設定檔中設定死了,並且名稱是不允許改的。
 
databases 16     //預設16個資料庫 

這16個資料庫編號是0-15,如果沒有切換資料庫的話,預設是0號資料庫.
 
# telnet 127.0.0.1 6379 
Trying 127.0.0.1... 
Connected to 127.0.0.1. 
Escape character is '^]'. 
set test 123   //在0號資料庫設定test為123 
+OK 
select 1  //切換到1號資料庫 
+OK 
set test 456   //設定test為456 
+OK 
get test  //1號資料庫test為456 
$3 
456 
select 0  //切換到0號資料庫 
+OK 
get test  //test為123 
$3 
123 
資料庫間相同的key,相互不受影響。

2,mongodb資料庫

mongodb非常像關係型資料庫,與redis不同的是,mongodb不用事先定義多少個資料庫,資料庫名也是自訂的。限制比redis少。
 
# mongo 
MongoDB shell version: 2.6.4-pre- 
connecting to: test 
> use tank //tank資料庫存在,切換到tank,如果不存在,建立tank資料庫 
switched to db tank 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.