转载地址: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
Identity Management(Account, Profile, User config info, Score)
Messaging
Personal domain name
meta data of distributed system
Other non-relatonal data
..
即,要求访问数据快、数据量不大,并且需要持久化到数据库中,却不需要sql查询的数据。
下面我们来说应用:
如果你看过了上一篇文章,并且已经成功安装memcachedb的话,那么,现在请启动你的memcachedb,命令如下:
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侦听端
‘-l <ip addr>’ interface to listen on, default is INDRR ANY 这个不要管他
‘-d’ run as a daemon 作为隐藏的线程运行
‘-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
如果你想要将数据保存再特定的目录可以使用-H 但是你必须首先要创建该目录,否则数据库将不可启动。
现在我们来测试下memcachedb是否已经启动了:
输入 telnet 'your ip' 端口号 (默认21201)
telnet 127.0.0.1 21201
Trying 127.0.0.1
Connected to 127.0.0.1.
Escape character is ’^]’.
如果可以连接,证明已经启动,现在我们可以来联系下memcached的命令了,呵呵.
以下是memcachedb支持的命令:
‘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
posted on 2009-12-24 10:19
阿蜜果 阅读(1324)
评论(0) 编辑 收藏 所属分类:
Other