Memcache概念
- Memcache是一款高性能、分布式的内存对象缓存系统
-
类似数据库的存储系统
-
Memcache可以有效的分担数据库的负载
-
Memcache基于libvent事件处理实现无阻塞通信
memcached的数据底层
-
1.Memcached是key/value键值对的形式存储
-
2.key的样子:key flags extime length
memcache安装部署
包名 | 作用 |
---|---|
memcached-1.5.7.tar.gz | memcached主程序 |
libevent-2.1.8-stable.tar.gz | 依赖包 |
部署安装
tar -xf libevent-2.1.8-stable.tar.gz
cd libevent-2.1.8-stable
./configure --prefix=/usr/local/libevent
make &&make install
tar -xf memcached-1.5.7.tar.gz
cd memcached-1.5.7
./configure --prefix=/usr/local/memcached/ --with-libevent=/usr/local/libevent
make &&make install
Memcached启动参数
参数 | 参数作用 |
---|---|
-d | 启动一个守护进程 |
-m | 分配给Memcached使用的内存数量 |
-u | 运行Memcached的用户 |
-I | 监听的服务器IP地址 |
-p | 监听的端口 |
-c | 最大运行的并发连接数 |
-P | 设置保存Memcache的PID文件 |
启动第一个memcached
memcached -u root -l 192.168.4.51 -p 2222 -c 128 -m 10 -P my.pid -d #后台执行监听2222端口内存10M允许连接的客户端128指定PID文件
memcached常用命令
分类 | 命令 | 命令作用 |
---|---|---|
新增 | set | 用于向缓存添加新的键值对 |
新增 | add | 当缓冲中不存在键时候则写入 |
修改 | replace | 当键值已经存在时候进行替换 |
修改 | append | 在已经有的结果上追加数据 |
修改 | prepend | 在已经有的数据前补充数据 |
特殊修改 | cas | 检查和更新,通常与gets一起使用 |
特殊修改 | lncr/decr | 增加/减少数值 |
查询 | get/gets | 获取数据/数据+版本号 |
连接memcached
简单的文本协议工具telnet,并非针对memcache使用,可以测试端口、网路是否通畅。
[root@ceph-manager memcached]# telnet 192.168.4.51 2222 #放肆的体验
You are my intake, I possess few blogs and often run out from post :). “Yet do I fear thy nature It is too full o’ the milk of human kindness.” by William Shakespeare.
Great – I should definitely pronounce, impressed with your web site. I had no trouble navigating through all tabs and related information ended up being truly easy to do to access. I recently found what I hoped for before you know it in the least. Reasonably unusual. Is likely to appreciate it for those who add forums or anything, site theme . a tones way for your customer to communicate. Nice task.
Thanks for some other informative web site. The place else may I am getting that kind of info written in such a perfect manner? I have a project that I am simply now operating on, and I’ve been at the look out for such info.
I recommend markdown