Memcache Commands

命令速查表
来源 https://lzone.de/cheat-sheet/memcached
支持的命令(官方命令和一些非官方命令)在 doc/protocol.txt 文档中有记录。
遗憾的是语法描述并不清晰,一个简单的帮助命令列出现有命令会更好。以下是您可以在 源代码 中找到的命令概述(截至 2016 年 8 月 19 日):
get
读取值
get mykey
set
无条件设置密钥
set mykey <flags> <ttl> <size>
<p>在使用 Unix CLI 工具时,请确保使用 \r\n 作为换行符。例如</p> printf "set mykey 0 60 4\r\ndata\r\n"
add
添加新密钥
add newkey 0 60 5
replace
覆盖现有密钥
replace key 0 60 5
append
将数据附加到现有密钥
append key 0 60 15
prepend
将数据前置到现有密钥
prepend key 0 60 15
incr
将给定数字加到密钥值上
incr mykey 2
decr
将给定数字减去密钥值
decr mykey 5
delete
删除现有密钥
delete mykey
flush_all
立即使所有项目无效
flush_all
flush_all
在 n 秒内使所有项目无效
flush_all 900
stats
打印一般统计信息
stats
打印内存统计信息
stats slabs
打印更高级别的分配统计信息
stats malloc
打印项目信息
stats items
stats detail
stats sizes
重置统计计数器
stats reset
lru_crawler metadump
转储缓存中所有项目的(大部分)元数据
lru_crawler metadump all
version
打印服务器版本。
version
verbosity
增加日志级别
verbosity
quit
终止会话
quit
流量统计
您可以使用以下命令查询当前流量统计信息
stats
您将获得一个列出连接数、收发字节数等信息的清单。
示例输出:
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
内存统计
您可以使用以下命令查询当前内存统计信息
stats slabs
## Memcache Commands
### Stats Command
The `stats` command is used to retrieve general statistics about the Memcached server. This command can provide information such as total number of connections, memory usage, hit and miss ratio, and more.
To use the `stats` command, you can simply run:
```bash
stats
This will return a list of statistics that can help you analyze the performance and usage of the Memcached server.
Set Command
The set
command is used to store a new key with some data on the Memcached server. This command requires the key, flags, expiration time, and the length of data in bytes.
To use the set
command, you can run:
set mykey 0 3600 5
hello
In this example, we are setting a key mykey
with a value of hello
that expires in 3600 seconds.
Get Command
The get
command is used to retrieve the data stored with a specific key on the Memcached server.
To use the get
command, you can run:
get mykey
This will return the value associated with the key mykey
, if it exists in the Memcached server.
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
如果您不确定您的memcached实例是否有足够的内存,请始终关注“stats”命令提供的“evictions”计数器。如果实例有足够的内存,“evictions”计数器应为0,或者至少不会增加。
#### 使用了哪些键? <a href="#which-keys-are-used" id="which-keys-are-used"></a>
没有内置函数可以直接确定当前的键集。但是您可以使用
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
这至少有助于查看是否使用了任何键。要从已经执行memcache访问的PHP脚本中转储键名称,您可以使用来自[100days.de](http://100days.de/serendipity/archives/55-Dumping-MemcacheD-Content-Keys-with-PHP.html)的PHP代码。
<figure><img src="/.gitbook/assets/WebSec_1500x400_10fps_21sn_lightoptimized_v2.gif" alt=""><figcaption></figcaption></figure>
<div data-gb-custom-block data-tag="embed" data-url='https://websec.nl/'></div>
<details>
<summary><strong>从零开始学习AWS黑客技术,成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
支持HackTricks的其他方式:
* 如果您想在HackTricks中看到您的**公司广告**或**下载PDF版本的HackTricks**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family),我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**上关注**我们。
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。
</details>
最后更新于