人的差别在于业余时间,而一个人的命运决定于晚上8点到10点之间。 北京安全测试精英QQ群:164265622 北京白盒测试精英QQ群:164265999 北京性能测试精英QQ群:164266156 北京自动化测试精英群:212723528 北京软件测试精英QQ群:86920845

memcache在telnet下的使用说明(转)

上一篇 / 下一篇  2011-09-20 15:36:15 / 个人分类:性能测试

 

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):

 

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相关操作

telnet 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

 

 

 


TAG:

 

评分:0

我来说两句

Open Toolbar