IT story

memcached에 모든 키를 설정하십시오.

hot-time 2020. 7. 17. 07:59
반응형

memcached에 모든 키를 설정하십시오.


memcached 인스턴스에 설정된 모든 키를 어떻게 얻을 수 있습니까?

인터넷 검색을 시도했지만 methodPHP지원하는 것을 제외하고 많이 찾지 못했습니다. 즉, 실제로 어떻게 든 할 수 있습니다. 텔넷 세션 내에서 어떻게합니까?getAllKeys

memcached cheat sheetMemcached telnet 명령 요약에 언급 된 모든 검색 관련 옵션을 시도했지만 그중 아무것도 작동하지 않으며 올바른 방법을 찾지 못했습니다.

참고 : 현재 개발 중에이 작업을 수행하고 있으므로 새 키가 설정되거나 다른 경쟁 조건이 발생하여 문제가 없으며 키 수도 제한된다고 가정 할 수 있습니다.


여기링크 덕분에 방법을 찾았습니다 (원래 Google 그룹 토론이 여기에 있음 )

먼저 Telnet서버로 :

telnet 127.0.0.1 11211

다음으로 슬래브 ID를 가져올 항목을 나열하십시오.

통계 아이템
STAT 아이템 : 3 : 숫자 1
STAT 아이템 : 3 : 나이 498
STAT 아이템 : 22 : 숫자 1
STAT 아이템 : 22 : 연령 498
종료

'항목'다음의 첫 번째 숫자는 슬래브 ID입니다. 덤프 할 최대 키 수를 제한하여 각 슬랩 ID에 대한 캐시 덤프를 요청하십시오.

통계 캐시 덤프 3100
ITEM views.decorators.cache.cache_header..cc7d9 [6 b; 1256056128 s]
종료

통계 캐시 덤프 22100
ITEM views.decorators.cache.cache_page..8427e [7736 b; 1256056128 s]
종료


memdump

그 (부분)에 대한 memcdump(때로는 memdump) 명령이 있습니다 libmemcached-tools.

memcdump --servers=localhost

모든 키를 반환합니다.


memcached-tool

최신 버전에는 memcached다음 memcached-tool과 같은 명령 도 있습니다.

memcached-tool localhost:11211 dump | less

모든 키와 값을 덤프합니다.

또한보십시오:


에 대한 자료 @mu는無 여기에 대답합니다. 캐시 덤프 스크립트를 작성했습니다.

스크립트는 memcached 서버의 모든 내용을 덤프합니다. Ubuntu 12.04 및 로컬 호스트 memcached로 테스트되었으므로 마일리지가 다를 수 있습니다.

#!/usr/bin/env bash

echo 'stats items'  \
| nc localhost 11211  \
| grep -oe ':[0-9]*:'  \
| grep -oe '[0-9]*'  \
| sort  \
| uniq  \
| xargs -L1 -I{} bash -c 'echo "stats cachedump {} 1000" | nc localhost 11211'

그것이하는 일은 모든 캐시 슬래브를 거치고 각각 1000 개의 항목을 인쇄합니다.

이 스크립트의 특정 한계를 알고 있어야합니다. 예를 들어 5GB 캐시 서버에 맞게 확장되지 않을 수 있습니다. 그러나 로컬 컴퓨터에서 디버깅 목적으로 유용합니다.


PHP & PHP-memcached가 설치되어 있다면

$ php -r '$c = new Memcached(); $c->addServer("localhost", 11211); var_dump( $c->getAllKeys() );'

세게 때리다

Bash에서 키 목록을 얻으려면 다음 단계를 수행하십시오.

First, define the following wrapper function to make it simple to use (copy and paste into shell):

function memcmd() {
  exec {memcache}<>/dev/tcp/localhost/11211
  printf "%s\n%s\n" "$*" quit >&${memcache}
  cat <&${memcache}
}

Memcached 1.4.31 and above

You can use lru_crawler metadump all command to dump (most of) the metadata for (all of) the items in the cache.

As opposed to cachedump, it does not cause severe performance problems and has no limits on the amount of keys that can be dumped.

Example command by using the previously defined function:

memcmd lru_crawler metadump all

See: ReleaseNotes1431.


Memcached 1.4.30 and below

Get list of slabs by using items statistics command, e.g.:

memcmd stats items

For each slub class, you can get list of items by specifying slub id along with limit number (0 - unlimited):

memcmd stats cachedump 1 0
memcmd stats cachedump 2 0
memcmd stats cachedump 3 0
memcmd stats cachedump 4 0
...

Note: You need to do this for each memcached server.

To list all the keys from all stubs, here is the one-liner (per one server):

for id in $(memcmd stats items | grep -o ":[0-9]\+:" | tr -d : | sort -nu); do
    memcmd stats cachedump $id 0
done

Note: The above command could cause severe performance problems while accessing the items, so it's not advised to run on live.


Notes:

stats cachedump only dumps the HOT_LRU (IIRC?), which is managed by a background thread as activity happens. This means under a new enough version which the 2Q algo enabled, you'll get snapshot views of what's in just one of the LRU's.

If you want to view everything, lru_crawler metadump 1 (or lru_crawler metadump all) is the new mostly-officially-supported method that will asynchronously dump as many keys as you want. you'll get them out of order but it hits all LRU's, and unless you're deleting/replacing items multiple runs should yield the same results.

Source: GH-405.


Related:


The easiest way is to use python-memcached-stats package, https://github.com/abstatic/python-memcached-stats

The keys() method should get you going.

Example -

from memcached_stats import MemcachedStats
mem = MemcachedStats()

mem.keys()
['key-1',
 'key-2',
 'key-3',
 ... ]

참고URL : https://stackoverflow.com/questions/19560150/get-all-keys-set-in-memcached

반응형