|
memcachedb是為了持久化而產(chǎn)生的一個(gè)分布式 "key-value"存儲(chǔ)系統(tǒng),你可以認(rèn)為是memcached+berkeley DB+sina的一些東西的一個(gè)集成,這個(gè)東西主要是為了提高持久化對象的訪問效率,而不是一個(gè)緩存,他的特點(diǎn)是: l 比傳統(tǒng)的RDBMS速度快效率高; l 高并發(fā)環(huán)境下訪問安全可靠,效率很不錯(cuò); l 存儲(chǔ)的數(shù)據(jù)比較小。 總之:高效、安全的事物機(jī)制、memcached的分布式協(xié)議支持是他的幾大亮點(diǎn). 你可以將一些數(shù)據(jù)量不大,讀寫卻很頻繁的數(shù)據(jù)放再這里面,而不用往mysql等數(shù)據(jù)庫里寫,據(jù)說“sohu”的在線用戶是存在這里面的,可見這東西還是挺可靠的。 在官方文檔里明確指出,只提倡用此數(shù)據(jù)庫保存如下類型的數(shù)據(jù): Index, Counter, Flags Identity Management(Account, Profile, User config info, Score) Messaging Personal domain name meta data of distributed system Other non-relatonal data![]() ![]() ![]() ![]() ![]() ![]() ![]() ..即,要求訪問數(shù)據(jù)快、數(shù)據(jù)量不大,并且需要持久化到數(shù)據(jù)庫中,卻不需要sql查詢的數(shù)據(jù)。 下面我們來說應(yīng)用: 如果你看過了上一篇文章,并且已經(jīng)成功安裝memcachedb的話,那么,現(xiàn)在請啟動(dòng)你的memcachedb,命令如下: memcachedb -p21201 -d -r -u root -f 21201.db -H /data1/demo -N -P /data1/logs/21201.pid參數(shù)說明如下: ‘-p <num>’ TCP port number to listen on (default: 21201) tcp偵聽端 ‘-l <ip addr>’ interface to listen on, default is INDRR ANY 這個(gè)不要管他 ‘-d’ run as a daemon 作為隱藏的線程運(yùn)行 ‘-r’ maximize core file limit ‘-u <username>’ assume identity of <username> (only when run as root) 用戶名 ‘-c <num>’ max simultaneous connections, default is 1024 ‘-b <num>’ max item buffer size in bytes, default is 1KB ‘-v’ verbose (print errors/warnings while in event loop) ‘-vv’ very verbose (also print client commands/reponses) ‘-P <file>’ save PID in <file>, only used with -d option ‘-m <num>’ in-memmory cache size of BerkeleyDB in megabytes, default is 64MB ‘-f <file>’ filename of database, default is /data1/memcachedb/default.db ‘-H <dir>’ env home of database, default is /data1/memcachedb ‘-L <num>’ log buffer size in kbytes, default is 32KB ‘-C <num>’ do checkpoint every XX seconds, 0 for disable, default is 60s ‘-D <num>’ do deadlock detecting every XXX millisecond, 0 for disable default is 100ms ‘-N’ enable DB TXN NOSYNC to gain big performance improved, default is off如果你想要將數(shù)據(jù)保存再特定的目錄可以使用-H 但是你必須首先要?jiǎng)?chuàng)建該目錄,否則數(shù)據(jù)庫將不可啟動(dòng)。 telnet 127.0.0.1 21201 Trying 127.0.0.1![]() Connected to 127.0.0.1. Escape character is ’^]’. 如果可以連接,證明已經(jīng)啟動(dòng),現(xiàn)在我們可以來聯(lián)系下memcached的命令了,呵呵. ‘get’ Retrieval of one or multiple items ‘set’ ”Store this data” ‘add’ ”Store this data, but only if the server *doesn’t* already hold data for this key” ‘replace’ ”Store this data, but only if the server *does* already hold data for this key” ‘delete’ deletes one item based a key ‘incr/decr’ Increment or decrement a numeric value. It’s atomic! ‘stats’ shows the status of current deamon. ’stats’, ’stats malloc’, ’stats maps’ Steve ‘db checkpoint’ does a checkpoint manuanlly. ‘db archive’ removes log files that are no longer needed. ‘stats bdb’ shows the status of BerkeleyDB. ‘rep ismaster’ shows whether the site is a master. ‘rep whoismaster’ shows which site is a master. ‘rep set priority’ sets the priority of a site for electing in replication. ‘rep set ack policy’ sets ACK policy of the replication. ‘rep set ack timeout’ sets ACK timeout value of the replication . ‘rep set bulk’ Enable bulk transfer or not in replication. ‘rep set request’ sets the minimum and maximum number of missing log records that a client waits before requesting retransmission. ‘stats rep’ shows the status of Replication |
|
|