linux telnet memcache,memcache telnet 使用命令

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 from

100days.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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值