Home Backend Development PHP Tutorial About memcached common commands and usage instructions

About memcached common commands and usage instructions

Jun 11, 2018 am 11:40 AM
memcached

memcached View method

Format: telnet ip port

For example telnet localhost 11211
Exit command:quit

1. Storage command

Storage command Format:

<command name> <key> <flag> <expire> <bytes>
<data block>
Copy after login

Parameter description:

command name Command name
keyFind keyword
flagStoring additional information
expireData storage time, 0 means forever, unit seconds
bytesThe number of bytes of stored data
data blockThe stored data

1.set 无论如何都存储,数据不存在时存储,数据存在时更新。

set mykey 0 0 3
123
STORED
set mykey 0 0 3
456
STORED
Copy after login

2.add 当数据不存在时存储。

add mykey 0 0 3
123
STORED
add mykey 0 0 3
456
NOT_STORED
Copy after login

3.replace 当数据存在时存储

set mykey 0 0 3
123
STORED
replace mykey 0 0 3
456
STORED
delete mykey
DELETED
replace mykey 0 0 3
678
NOT_STORED
Copy after login

二.读取命令

1.get key 可以一个或多个,用空格格开。

set mykey 0 0 3
123
STORED
set mykey1 0 0 3
456
STORED
get mykey mykey1
VALUE mykey 0 3
123
VALUE mykey1 0 3
456
END
Copy after login

2.gets 与 get 一样,但会返回多一个数字,这个数字用来检查数据是否被修改过,如修改过,这个数字回改变。

set mykey 0 0 3
123
STORED
gets mykey
VALUE mykey 0 3 7
123
END
replace mykey 0 0 3
888
STORED
gets mykey
VALUE mykey 0 3 8
888
END
Copy after login

3.cas cas即checked and set ,当最后一个参数与gets返回的数字一致时才存储,否则返回EXISTS。

set mykey 0 0 3
123
STORED
gets mykey
VALUE mykey 0 3 9
123
END
cas mykey 0 0 3 8
456
EXISTS
cas mykey 0 0 3 9
456
STORED
Copy after login

三.追加与清除命令

1.append 将数据追加到当前缓存数据的之后,当缓存数据存在时才存储。

set mykey 0 0 3
123
STORED
append mykey 0 0 3
456
STORED
get mykey
VALUE mykey 0 6
123456
END
append notexists 0 0 3
456
NOT_STORED
Copy after login

2.prepend 将数据追加到当前缓存数据的之前,当缓存数据存在时才存储。

set mykey 0 0 3
123
STORED
prepend mykey 0 0 3
456
STORED
get mykey
VALUE mykey 0 6
456123
END
prepend notexists 0 0 3
456
NOT_STORED
Copy after login

3.delete 删除缓存数据,数据存在返回DELETED,数据不存在返回NOT_FOUND

set mykey 0 0 3
123
STORED
delete mykey
DELETED
delete mykey
NOT_FOUND
Copy after login

4.flush_all 将当前所有缓存数据设置为过期,但不会释放内存。

flush_all
OK
Copy after login

四.状态命令

1.stats 查看memcached运行状态

pid                     Memcached 进程ID  
  
uptime                  Memcached 运行时间,单位:秒  
  
time                    Memcached 当前的UNIX时间  
  
version                 Memcached 的版本号  
  
rusage_user             该进程累计的用户时间,单位:秒  
  
rusage_system           该进程累计的系统时间,单位:秒  
  
curr_items              Memcached 当前存储的内容数量  
  
total_items             Memcached 启动以来存储过的内容总数  
  
bytes                   Memcached 当前存储内容所占用的字节数(*/1024/1024=mb)  
  
curr_connections        当前连接数量  
  
total_connections       Memcached 运行以来接受的连接总数  
  
connection_structures   Memcached 分配的连接结构的数量  
  
cmd_get                 查询请求总数  
  
cmd_set                 存储(添加/更新)请求总数  
  
get_hits                查询成功获取数据的总次数  
  
get_misses              查询成功未获取到数据的总次数  
  
bytes_read              Memcached 从网络读取到的总字节数  
  
bytes_written           Memcached 向网络发送的总字节数  
  
limit_maxbytes          Memcached 在存储时被允许使用的字节总数
Copy after login

2.stats items
执行stats items,可以看到STAT items行,如果memcached存储内容很多,那么这里也会列出很多的STAT items行。

3.stats cachedump slabs_id limit_num
slabs_id:由stats items返回的结果(STAT items后面的数字)决定的
limit_num:返回的记录数,0表示返回所有记录
通过stats items、stats cachedump slab_id limit_num配合get命令可以遍历memcached的记录。

stats cachedump 1 0
ITEM mykey [3 b; 1362880145 s]
END
Copy after login

4.stats slabs 显示各个slab的信息,包括chunk的大小、数目、使用情况等


5.stats sizes
 输出所有item的大小和个数


6.stats reset
清空统计数据

本文讲解了memcached 常用命令及使用说明,更多相关内容请关注php中文网。

相关推荐:

Related explanations about PHPMailer - PHP email transport class

About PHP understanding of folder traversal, file classes and processing classes

Explain RewriteCond and 13 mod_rewrite application examples and related knowledge of Apache pseudo-static

The above is the detailed content of About memcached common commands and usage instructions. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Memcached caching technology optimizes Session processing in PHP Memcached caching technology optimizes Session processing in PHP May 16, 2023 am 08:41 AM

Memcached is a commonly used caching technology that can greatly improve the performance of web applications. In PHP, the commonly used Session processing method is to store the Session file on the server's hard disk. However, this method is not optimal because the server's hard disk will become one of the performance bottlenecks. The use of Memcached caching technology can optimize Session processing in PHP and improve the performance of Web applications. Session in PHP

Caching library in PHP8.0: Memcached Caching library in PHP8.0: Memcached May 14, 2023 am 08:16 AM

Caching library in PHP8.0: Memcached With the rapid development of the Internet, modern applications require efficient and reliable caching technology to improve performance and handle large amounts of data. Due to PHP's popularity and open source nature, the PHP caching library has become an essential tool in the web development community. Memcached is a widely used open source high-speed memory caching system that can handle millions of simultaneous connected cache requests and can be used in many different types of applications, such as social networks, online

How to optimize PHP application CPU usage using Memcached caching technology? How to optimize PHP application CPU usage using Memcached caching technology? Jun 21, 2023 pm 05:07 PM

With the development of the Internet, PHP applications have become more and more common in the field of Internet applications. However, high concurrent access by PHP applications can lead to high CPU usage on the server, thus affecting the performance of the application. In order to optimize the performance of PHP applications, Memcached caching technology has become a good choice. This article will introduce how to use Memcached caching technology to optimize the CPU usage of PHP applications. Introduction to Memcached caching technology Memcached is a

PHP and Memcached database backup and recovery PHP and Memcached database backup and recovery May 15, 2023 pm 09:12 PM

With the rapid development of the Internet, large-scale MySQL database backup and recovery has become one of the essential skills for major enterprises and websites. With the widespread application of Memcached, how to back up and restore Memcached has also become an important issue. As one of the main languages ​​for web development, PHP has unique advantages and skills in handling backup and recovery of MySQL and Memcached. This article will introduce in detail the implementation method of PHP processing MySQL and Memcached backup and recovery.

Cache management with PHP and Memcached Cache management with PHP and Memcached May 23, 2023 pm 02:21 PM

With the continuous increase of network applications and the continuous expansion of data volume, data reading and writing efficiency has become one of the important factors affecting application performance. The application of caching technology can solve this problem well. In PHP applications, Memcached is the most commonly used cache server. Memcached is a high-performance distributed memory object caching system that can store commonly used data in memory and improve the efficiency of data retrieval. This article will introduce how to use PHP and Memcached for cache management, and how to optimize

PHP and Memcached performance monitoring PHP and Memcached performance monitoring May 15, 2023 pm 09:51 PM

With the rapid development of modern Internet applications, user experience is crucial to the success of an application. How to ensure high performance and high availability of applications has become one of the important issues that developers need to solve. As one of the widely used programming languages, PHP's performance monitoring and optimization are also very important. Memcached is a high-performance, distributed memory object caching system that can help applications improve performance and scalability. This article will introduce how to use PHP and Memcached to implement performance monitoring.

Use Memcached caching technology to optimize audio and video playback in PHP Use Memcached caching technology to optimize audio and video playback in PHP May 17, 2023 pm 04:01 PM

With the continuous development of Internet technology, audio and video resources have become a very important form of content on the Internet, and PHP, as one of the most widely used languages ​​in network development, is also constantly used in the field of video and audio playback. However, with the increasing number of users of audio and video websites, many websites have discovered a problem: under high concurrency conditions, PHP's processing speed of audio and video slows down significantly, resulting in problems such as inability to play in time or stuck playback. To solve this problem, Memcached caching technology should

How to use Memcached with CakePHP? How to use Memcached with CakePHP? Jun 04, 2023 am 08:14 AM

With the rapid growth of modern applications, caching has become a vital part of many developers. Caching can greatly improve application performance and reduce server load. In CakePHP, one way to implement caching is to use Memcached. Memcached is a memory-based distributed caching system. It stores data in memory and can read and write data quickly. In a multi-server environment, Memcached can store data in a distributed manner and share it over the network. not only can

See all articles