select

1. 基本語法

select( index:<string>,callback)

切換至對應index資料庫,成功切換會回傳OK,不同資料庫的Key名稱及資料互不影響。

多人共用Redis時,建議每次在建立Client連線後,總是先切換至自己的資料庫。

client.select('0', redis.print);
client.set('db:0:foo', 'bar');
client.set('db:0:foo1', 'bar1');
client.keys('*', redis.print);

client.select('1', redis.print);
client.set('db:1:foo', 'bar');
client.keys('*', redis.print);
Reply: OK
Reply: db:0:foo1,db:0:foo
Reply: OK
Reply: db:1:foo

Last updated

Was this helpful?