`

memcache在telnet下的使用说明

    博客分类:
  • PHP
阅读更多

 

memcached Telnet Interface

This is a short summary of everything important that helps to inspect a running memcached instance.

How To Connect

Use "ps -ef" to find out which IP and port was passed when memcached was started and use the same with telnet to connect to memcache. Example:

telnet 10.10.1.24 23456

 

Supported Commands

The supported commands (the official ones and some unofficial) are documented in the doc/protocol.txt document.

Sadly the syntax description isn't really clear and a simple help command listing the existing commands would be much better. Here is an overview of the commands you can find in the source (as of 16.12.2008):

 

Command Description Example
get Reads a value get mykey
set Set a key unconditionally set mykey 0 60 5
add Add a new key add newkey 0 60 5
replace Overwrite existing key replace key 0 60 5
append Append data to existing key append key 0 60 15
prepend Prepend data to existing key prepend key 0 60 15
incr Increments numerical key value by given number incr mykey 2
decr Decrements numerical key value by given number decr mykey 5
delete Deletes an existing key delete mykey
flush_all Invalidate specific items immediately flush_all
Invalidate all items in n seconds flush_all 900
stats Prints general statistics stats
Prints memory statistics stats slabs
Prints memory statistics stats malloc
Print higher level allocation statistics stats items
stats detail
stats sizes
Resets statistics stats reset
version Prints server version. version
verbosity Increases log level verbosity
quit Terminate telnet session quit

Traffic Statistics

You can query the current traffic statistics using the command

stats
You will get a listing which serves the number of connections, bytes in/out and much more.

 

Example Output:

STAT pid 14868
STAT uptime 175931
STAT time 1220540125
STAT version 1.2.2
STAT pointer_size 32
STAT rusage_user 620.299700
STAT rusage_system 1545.703017
STAT curr_items 228
STAT total_items 779
STAT bytes 15525
STAT curr_connections 92
STAT total_connections 1740
STAT connection_structures 165
STAT cmd_get 7411
STAT cmd_set 28445156
STAT get_hits 5183
STAT get_misses 2228
STAT evictions 0
STAT bytes_read 2112768087
STAT bytes_written 1000038245
STAT limit_maxbytes 52428800
STAT threads 1
END

 

Memory Statistics

You can query the current memory statistics using

stats slabs

 

Example Output:

STAT 1:chunk_size 80
STAT 1:chunks_per_page 13107
STAT 1:total_pages 1
STAT 1:total_chunks 13107
STAT 1:used_chunks 13106
STAT 1:free_chunks 1
STAT 1:free_chunks_end 12886
STAT 2:chunk_size 100
STAT 2:chunks_per_page 10485
STAT 2:total_pages 1
STAT 2:total_chunks 10485
STAT 2:used_chunks 10484
STAT 2:free_chunks 1
STAT 2:free_chunks_end 10477
[...]
STAT active_slabs 3
STAT total_malloced 3145436
END

 

Which Keys Are Used?

There seems to be no builtin function to determine the currently set keys. However you can use the

stats items
command to determine how many keys do exist.
stats items
STAT items:1:number 220
STAT items:1:age 83095
STAT items:2:number 7
STAT items:2:age 1405
[...]
END
This at least helps to see if any keys are used. To dump the key names from a PHP script that already does the memcache access you can use the PHP code from100days.de.

 

Never Set a Timeout > 30 Days!

While this has nothing to do with the telnet access this is a problem you might run into. If you try to "set" or "add" a key with a timeout bigger than the allowed maximum you might not get what you expect because memcached then treats the value as a Unix timestamp. Also if the timestamp is in the past it will do nothing at all. Your command will silently fail.

So if you want to use the maximum lifetime specify 2592000. Example:

set my_key 0 2592000 1
1

Disappearing Keys on Overflow

Despite the documentation saying something about wrapping around 64bit overflowing a value using "incr" causes the value to disappear. It needs to be created using "add"/"set" again.

 




memcached telnet相关操作

elnet localhost 11211
//保存
set good 32 0 10
helloworld
STORED

//取回
gets good
VALUE good 32 10 10
helloworld
END

//替换
replace good 32 0 10
worldhello
STORED
get good
VALUE good 32 10
worldhello
END

//尾部添加
append good 32 0 5
after
STORED
get good
VALUE good 32 15
worldhelloafter
END

//头部添加
prepend good 32 0 6
before
STORED
get good
VALUE good 32 21
beforeworldhelloafter
END

//删除
delete good
DELETED
get good
END


delete good
NOT_FOUND


cas good 32 0 10 hel
helloworld
EXISTS

gets good
VALUE good 32 10 10
helloworld
END


cas bad 32 0 10 good
worldhello
NOT_FOUND


//统计
stats items
STAT items:1:number 1
STAT items:1:age 24
STAT items:1:evicted 0
STAT items:1:outofmemory 0
END


stats sizes
96 1
END

stats slabs
STAT 1:chunk_size 88
STAT 1:chunks_per_page 11915
STAT 1:total_pages 1
STAT 1:total_chunks 11915
STAT 1:used_chunks 11914
STAT 1:free_chunks 1
STAT 1:free_chunks_end 11913
STAT 2:chunk_size 112
STAT 2:chunks_per_page 9362
STAT 2:total_pages 1
STAT 2:total_chunks 9362
STAT 2:used_chunks 9361
STAT 2:free_chunks 1
STAT 2:free_chunks_end 9361
STAT 5:chunk_size 232
STAT 5:chunks_per_page 4519
STAT 5:total_pages 1
STAT 5:total_chunks 4519
STAT 5:used_chunks 4518
STAT 5:free_chunks 1
STAT 5:free_chunks_end 4518
STAT active_slabs 3
STAT total_malloced 3145472
END


stats items
STAT items:1:number 1
STAT items:1:age 1768
STAT items:1:evicted 0
STAT items:1:outofmemory 0
END

stats
STAT pid 18261
STAT uptime 528593
STAT time 1237277383
STAT version 1.2.6
STAT pointer_size 32
STAT rusage_user 0.004999
STAT rusage_system 0.015997
STAT curr_items 1
STAT total_items 2
STAT bytes 66
STAT curr_connections 2
STAT total_connections 13
STAT connection_structures 3
STAT cmd_get 11
STAT cmd_set 8
STAT get_hits 2
STAT get_misses 9
STAT evictions 0
STAT bytes_read 1342
STAT bytes_written 8752
STAT limit_maxbytes 134217728
STAT threads 1
END


使用usr/bin/perl /root/memcached-1.2.6/scripts/memcached-tool localhost:11211
output
# Item_Size   Max_age 1MB_pages Count   Full?
1      88 B     1531 s       1       1      no
2     112 B        0 s       1       0      no
5     232 B        0 s       1       0      no

# slab class编号 
Item_Size Chunk大小 
Max_age LRU内最旧的记录的生存时间 
1MB_pages 分配给Slab的页数 
Count Slab内的记录数 
Full? Slab内是否含有空闲chunk

 

分享到:
评论

相关推荐

    MemCache服务器端和使用说明

    1. **命令行测试**:使用telnet命令行工具连接到MemCache服务器,进行简单的键值对操作。 2. **性能监控**:通过MemCache的统计接口,可以获取内存使用情况、命中率等性能指标。 3. **第三方工具**:使用像`mcstat`...

    windows本地开启memcache服务

    - 默认情况下,Memcache会使用11211端口,并且在本地主机上运行。如果你需要更改这些设置,可以在启动服务时提供相应的参数。例如,`memcached.exe -p 12345 -l 192.168.1.100`将使Memcache监听12345端口并在IP地址...

    memcache win7 64位 安装文件

    4. **验证安装**:在命令行中输入`net start memcached`启动服务,然后通过`telnet localhost 11211`测试连接,如果成功,说明Memcache已经安装并运行。 5. **集成到Web应用程序**:为了在PHP、Python、Java等应用...

    memcache+tomcat集群说明手册

    5. **验证安装**:使用`telnet *.*.*.* 11211`验证memcache是否启动成功。 ##### 3.4 安装Tomcat 1. **登录系统**:使用`appuser`登录系统。 2. **解压安装包**:使用命令`tar –zxvf /app/soft/tomcat.tar.gz`解压...

    memcache安装包.zip

    3. 使用telnet工具连接到Memcached服务器,如`telnet localhost 11211`,然后尝试set和get操作验证功能。 **使用场景与注意事项** Memcached适用于需要快速缓存数据的应用,如Web应用的session存储、高并发的...

    linux环境memcache详细安装步骤(含memcache软件包)

    - 默认情况下,Memcached不使用认证,因此强烈建议限制只在内网环境中使用,或配置防火墙规则以限制访问。 - 如果需要,可以使用第三方工具如`libmemcached-tools`中的`memcached-tool`进行监控和管理。 通过以上...

    memcache 安装包 64

    例如,在PHP中,你可以使用`memcached`或`memcache`扩展来操作Memcached服务器。 7. **优化与管理** 对于生产环境,你可能需要进行更深入的配置,如设置超时时间、调整缓存策略、监控性能等。这些可以通过修改启动...

    64位机器上安装memcache详细说明

    为了测试Memcached是否正常工作,你可以使用telnet客户端连接到本地的11211端口,并进行一些基本操作,如设置和获取键值对: ```bash # telnet localhost 11211 ``` 在telnet会话中,输入`set key 0 0 5`,然后按...

    memcache配置文档

    本文档将详细介绍如何在Linux环境下部署和配置Memcache。 #### 二、环境准备 为了确保部署过程顺利进行,我们需要准备好以下软件包: 1. **Libevent**:用于事件处理的库,是Memcached运行的基础。 2. **Memcached...

    【监控】netstat+telnet+m-top+phpmemcached

    标题中的“netstat+telnet+m-top+phpmemcached”提到了四个在IT领域中用于系统监控和管理的重要工具。...在给定的压缩包文件中,`memcache-top-v0.6`可能就是m-top的一个特定版本,供你下载安装和使用。

    windows中为php安装mongodb与memcache

    6. 测试Memcache是否能够正常工作,可以使用Telnet命令连接到Memcache服务: ```cmd telnet ***.*.*.***211 ``` 连接成功后,键入stats查看服务状态。 7. 最后,需要下载Memcache的PHP扩展并进行配置。下载地址...

    linux下安装memcached以及解决安装中遇到的问题

    在 Linux 系统下部署 Memcached 是一个常见的需求,然而在安装过程中可能会遇到各种各样的问题,如依赖库缺失等。本文将详细介绍如何在 Linux 系统下安装 Memcached,同时解决在安装过程中可能遇到的一些问题。 ###...

    配置Memcache服务器并实现主从复制功能(repcached)

    如果在slave节点上能够成功获取到在master节点上设置的数据,说明复制功能已经正常工作。 5. 应用场景与注意事项 repcached的主从复制功能可以实现数据的冗余备份,防止因主节点故障导致的数据丢失。然而,需要注意...

    win7下memCache的安装过程(具体操作步骤)

    在命令提示符下,输入`H:/wamp/www/php api/memcache/memcached.exe -d install`来尝试安装memcached服务。有时可能会遇到"failed to install service or service already installed"的错误。这时,你需要以管理员...

    memcache安装步骤

    为了测试 Memcached 是否正常工作,你可以使用 telnet 工具连接到本地的11211端口: ``` telnet localhost 11211 ``` 输入 `get` 命令后回车,如果没有返回错误信息,说明 Memcached 已经正常运行。 至此,你...

    memcached-1.4.5 windows版

    3. **使用说明**:压缩包中的`readme.txt`文件提供了详细的使用指南,包括启动、停止服务的方法,以及如何调整配置参数。务必阅读此文件,以确保正确运行Memcached。 4. **客户端支持**:在Windows上,你需要一个与...

    linux下编译安装memcached服务.pdf

    3. 使用`telnet localhost 11211`尝试连接到本地的Memcached服务,如果连接成功,说明服务运行正常。 日常操作中,可以使用以下命令管理Memcached服务: - 启动服务:`./memcached -d -m 1024 -u root -l 127.0.0.1...

    memcached1.5.6.rar

    通过以上内容,我们了解了memcached的基本概念、安装与使用方法,特别是在Windows环境下如何利用提供的资源进行安装和管理。如果你需要在Windows 10系统上部署memcached,可以参考提供的文档和执行文件进行操作。

    linux下编译安装memcached服务

    通过ps命令查看进程列表中是否存在memcache进程,使用netstat命令检查11211端口是否被监听,或者通过telnet命令直接连接到11211端口测试服务响应。 8. 常用命令: 提供了启动和关闭Memcached服务的命令,关闭服务...

    Linux一键安装web环境全攻略

    - 各组件的具体安装位置会在安装过程中说明。 2. **常用命令**: - **查看Nginx状态**:`systemctl status nginx` - **重启Nginx**:`systemctl restart nginx` - **查看Apache状态**:`systemctl status httpd`...

Global site tag (gtag.js) - Google Analytics