DB

一般來說,在預設的配置文件(redis.conf)內容中,有一段databases = 16的配置項目,代表預設Redis底下有16個資料庫(database, DB),索引分別對應至'0''1'、...、'15'

redis.conf
# ...

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
databases 16

# ...

如果多人共用Redis時,可以適度區分資料庫(DB),避免共用資料庫導致整體資料架構混亂,甚至覆蓋到其他人的資料;針對不同的專案,除了開新的Redis之外,可以整合多個需求較小的專案,透過不同的資料庫(DB)區分資料環境,除了節省成本,也得以讓協作更順暢。

另外​,本章節也介紹資料庫(DB)層級的指令,要謹記有些指令的作用範圍包含整個資料庫(DB);甚至直接影響整個Redis系統,使用上要特別注意。

Last updated

Was this helpful?