memcachedb使用
来源:百度文库 编辑:神马文学网 时间:2024/03/28 22:59:35
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 如果你想要将数据保存再特定的目录可以使用-H 但是你必须首先要创建该目录,否则数据库将不可启动。 telnet 127.0.0.1 21201 如果可以连接,证明已经启动,现在我们可以来联系下memcached的命令了,呵呵.
‘-l
‘-d’ run as a daemon 作为隐藏的线程运行
‘-r’ maximize core file limit
‘-u
‘-c
‘-b
‘-v’ verbose (print errors/warnings while in event loop)
‘-vv’ very verbose (also print client commands/reponses)
‘-P
‘-m
‘-f
‘-H
‘-L
‘-C
‘-D
‘-N’ enable DB TXN NOSYNC to gain big performance improved, default is off
现在我们来测试下memcachedb是否已经启动了:
输入 telnet 'your ip' 端口号 (默认21201)
Trying 127.0.0.1
Connected to 127.0.0.1.
Escape character is ’^]’.
以下是memcachedb支持的命令:
‘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