转载地址:http://www.cnblogs.com/eoiioe/archive/2008/11/11/1331242.html
        
memcachedb是为了持久化而产生的一个分布式 "key-value"存储系统,你可以认为是memcached+berkeley DB+sina的一些东西的一个集成,这个东西主要是为了提高持久化对象的访问效率,而不是一个缓存,他的特点是: 
l         比传统的RDBMS速度快效率高;
l         高并发环境下访问安全可靠,效率很不错;
l         存储的数据比较小。
总之:高效、安全的事物机制、memcached的分布式协议支持是他的几大亮点.
你可以将一些数据量不大,读写却很频繁的数据放再这里面,而不用往mysql等数据库里写,据说“sohu”的在线用户是存在这里面的,可见这东西还是挺可靠的。
在官方文档里明确指出,只提倡用此数据库保存如下类型的数据:
 Index, Counter, Flags
Index, Counter, Flags
 Identity Management(Account, Profile, User config info, Score)
Identity Management(Account, Profile, User config info, Score)
 Messaging
Messaging
 Personal domain name
Personal domain name
 meta data of distributed system
meta data of distributed system
 Other non-relatonal data
Other non-relatonal data







 ..
..下面我们来说应用:
如果你看过了上一篇文章,并且已经成功安装memcachedb的话,那么,现在请启动你的memcachedb,命令如下:
 memcachedb -p21201 -d -r -u root -f 21201.db -H /data1/demo  -N -P /data1/logs/21201.pid
memcachedb -p21201 -d -r -u root -f 21201.db -H /data1/demo  -N -P /data1/logs/21201.pid参数说明如下:
 ‘-p <num>’ TCP port number to listen on (default: 21201)       tcp侦听端
‘-p <num>’ TCP port number to listen on (default: 21201)       tcp侦听端
 ‘-l <ip addr>’ interface to listen on, default is INDRR ANY      这个不要管他
‘-l <ip addr>’ interface to listen on, default is INDRR ANY      这个不要管他
 ‘-d’ run as a daemon    作为隐藏的线程运行
‘-d’ run as a daemon    作为隐藏的线程运行
 ‘-r’ maximize core file limit
‘-r’ maximize core file limit
 ‘-u <username>’ assume identity of <username> (only when run as root) 用户名
‘-u <username>’ assume identity of <username> (only when run as root) 用户名
 ‘-c <num>’ max simultaneous connections, default is 1024
‘-c <num>’ max simultaneous connections, default is 1024
 ‘-b <num>’ max item buffer size in bytes, default is 1KB
‘-b <num>’ max item buffer size in bytes, default is 1KB
 ‘-v’ verbose (print errors/warnings while in event loop)
‘-v’ verbose (print errors/warnings while in event loop)
 ‘-vv’ very verbose (also print client commands/reponses)
‘-vv’ very verbose (also print client commands/reponses)
 ‘-P <file>’ save PID in <file>, only used with -d option
‘-P <file>’ save PID in <file>, only used with -d option
 ‘-m <num>’ in-memmory cache size of BerkeleyDB in megabytes, default is 64MB
‘-m <num>’ in-memmory cache size of BerkeleyDB in megabytes, default is 64MB
 ‘-f <file>’ filename of database, default is /data1/memcachedb/default.db
‘-f <file>’ filename of database, default is /data1/memcachedb/default.db
 ‘-H <dir>’ env home of database, default is /data1/memcachedb
‘-H <dir>’ env home of database, default is /data1/memcachedb
 ‘-L <num>’ log buffer size in kbytes, default is 32KB
‘-L <num>’ log buffer size in kbytes, default is 32KB
 ‘-C <num>’ do checkpoint every XX seconds, 0 for disable, default is 60s
‘-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
‘-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
‘-N’ enable DB TXN NOSYNC to gain big performance improved, default is off如果你想要将数据保存再特定的目录可以使用-H 但是你必须首先要创建该目录,否则数据库将不可启动。
    现在我们来测试下memcachedb是否已经启动了:
    输入  telnet 'your ip'  端口号 (默认21201)
 telnet 127.0.0.1 21201
telnet 127.0.0.1 21201
 Trying 127.0.0.1
Trying 127.0.0.1
 Connected to 127.0.0.1.
Connected to 127.0.0.1.
 Escape character is ’^]’.
Escape character is ’^]’.    如果可以连接,证明已经启动,现在我们可以来联系下memcached的命令了,呵呵.
    以下是memcachedb支持的命令:
 ‘get’ Retrieval of one or multiple items
‘get’ Retrieval of one or multiple items
 ‘set’ ”Store this data”
‘set’ ”Store this data”
 ‘add’ ”Store this data, but only if the server *doesn’t* already hold data for this key”
‘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”
‘replace’ ”Store this data, but only if the server *does* already hold data for this key”
 ‘delete’ deletes one item based a 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
‘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 checkpoint’ does a checkpoint manuanlly.
 ‘db archive’ removes log files that are no longer needed.
‘db archive’ removes log files that are no longer needed.
 ‘stats bdb’ shows the status of BerkeleyDB.
‘stats bdb’ shows the status of BerkeleyDB.
 ‘rep ismaster’ shows whether the site is a master.
‘rep ismaster’ shows whether the site is a master.
 ‘rep whoismaster’ shows which 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 priority’ sets the priority of a site for electing in replication.
 ‘rep set ack policy’ sets ACK policy of the replication.
‘rep set ack policy’ sets ACK policy of the replication.
 ‘rep set ack timeout’ sets ACK timeout value 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 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.
‘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
‘stats rep’ shows the status of Replicationposted on 2009-12-24 10:19 
阿蜜果 阅读(1358) 
评论(0)  编辑  收藏  所属分类: 
Other