memcache的使用,memcache使用
Jun 13, 2016 am 09:24 AMmemcache的使用,memcache使用
什么是memcache?
Memcache是一個(gè)高性能的分布式的內(nèi)存對(duì)象緩存系統(tǒng),通過(guò)在內(nèi)存里維護(hù)一個(gè)統(tǒng)一的巨大的hash表,它能夠用來(lái)存儲(chǔ)各種格式的數(shù)據(jù),包括圖像、視頻、文件以及數(shù)據(jù)庫(kù)檢索的結(jié)果等。簡(jiǎn)單的說(shuō)就是將數(shù)據(jù)調(diào)用到內(nèi)存中,然后從內(nèi)存中讀取,從而大大提高讀取速度(摘自360百科)
?
它相當(dāng)于一個(gè)內(nèi)存數(shù)據(jù)庫(kù) 可以減少對(duì)數(shù)據(jù)庫(kù)的操作.
最初看見(jiàn)是在公司的一個(gè)PHP接口服務(wù)器中。
?
安裝:
在ubuntu中的安裝方式: 挖坑(下次填寫 ?操作步驟忘記了)
apt-get install memcached
安裝好后
sudo memcached start 啟動(dòng) ?
/etc/memcached.conf 是默認(rèn)的配置文件
-p 監(jiān)聽(tīng)的端口
-l 連接的IP地址, 默認(rèn)是本機(jī)
-d start 啟動(dòng)memcached服務(wù)
-d restart 重起memcached服務(wù)
-d stop|shutdown 關(guān)閉正在運(yùn)行的memcached服務(wù)
-d install 安裝memcached服務(wù)
-d uninstall 卸載memcached服務(wù)
-u 以的身份運(yùn)行 (僅在以root運(yùn)行的時(shí)候有效)
-m 最大內(nèi)存使用,單位MB。默認(rèn)64MB
-M 內(nèi)存耗盡時(shí)返回錯(cuò)誤,而不是刪除項(xiàng)
-c 最大同時(shí)連接數(shù),默認(rèn)是1024
-f 塊大小增長(zhǎng)因子,默認(rèn)是1.25-n 最小分配空間,key+value+flags默認(rèn)是48
-h 顯示幫助2)安裝Memcache客戶端?
?
php memcache模塊安裝方法:
sudo apt-get install php5-memcache
?
使用方法: ?php手冊(cè)用有該模塊的使用說(shuō)明
<?php /* OO API */ $memcache_obj = new Memcache; /* connect to memcached server */ $memcache_obj->connect('memcache_host', 11211); /* 設(shè)置'var_key'對(duì)應(yīng)值,使用即時(shí)壓縮 失效時(shí)間為50秒 */ $memcache_obj->set('var_key', 'some really big variable', MEMCACHE_COMPRESSED, 50); echo $memcache_obj->get('var_key'); ?>
python : 模塊下載地址 https://pypi.python.org/pypi/python-memcached
import memcache mc = memcache.Client(['127.0.0.1:11211']) mc.set('hello','world') mc.get('hello')
一些說(shuō)明:
memcached 沒(méi)有安全認(rèn)證 所以如果把配置的-l 監(jiān)聽(tīng)I(yíng)P該為本地以外的IP 可能導(dǎo)致數(shù)據(jù)安全性問(wèn)題
以后用熟悉了再填坑
CI 是 memcacehd 你安裝的是 memcache 差了一個(gè)"d"字符,差別就很大了。CI 只支持 memcached,不支持 memcache。Windows 下只有 memcache。
?
memcache服務(wù)器,要特殊配置,內(nèi)存要大,其他硬件能用即可
其他解決方案:可以配置分布式緩存
因?yàn)閙emcache一般是只供局域網(wǎng)使用的
工作原理是:web服務(wù)器使用memcache緩存,然后把數(shù)據(jù)緩存在memcache服務(wù)器上,memecache只用到內(nèi)存
數(shù)據(jù)量過(guò)大只能增加服務(wù)器,部署分布式緩存
其他可以再聯(lián)系
?

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In web development, we often need to use caching technology to improve website performance and response speed. Memcache is a popular caching technology that can cache any data type and supports high concurrency and high availability. This article will introduce how to use Memcache in PHP development and provide specific code examples. 1. Install Memcache To use Memcache, we first need to install the Memcache extension on the server. In CentOS operating system, you can use the following command

How to use Memcache for efficient data writing and querying in PHP development? With the continuous development of Internet applications, the requirements for system performance are getting higher and higher. In PHP development, in order to improve system performance and response speed, we often use various caching technologies. One of the commonly used caching technologies is Memcache. Memcache is a high-performance distributed memory object caching system that can be used to cache database query results, page fragments, session data, etc. By storing data in memory

In PHP development, using the Memcache caching system can greatly improve the efficiency of data reading and writing. Memcache is a memory-based caching system that can cache data in memory to avoid frequent reading and writing of the database. This article will introduce how to use Memcache in PHP for efficient data reading and writing operations, and provide specific code examples. 1. Install and configure Memcache First, you need to install the Memcache extension on the server. able to pass

The practice and thinking of Memcache caching technology to optimize data interaction in PHP In modern Web applications, data interaction is a very important issue. It is not efficient enough and will limit the scalability and performance of Web applications. In order to speed up data interaction, our usual approach is to optimize the design of the database, improve the performance of the hardware and increase the server capacity. However, these methods all have a common limitation: they increase the cost of the system. In recent years, Memcache technology has made progress in solving this problem.

Memcache is an open source, distributed caching technology. It greatly improves the speed of data access by storing data in memory, thus improving the performance and responsiveness of the website. In PHP projects, Memcache caching technology is also widely used and has achieved good results. This article will deeply explore the application and practice of Memcache caching technology in PHP projects. 1. Principles and advantages of Memcache Memcache is a memory caching technology that can store data

With the rapid development of the Internet, more and more applications need to face a large number of concurrent requests. How to improve the concurrent processing capabilities of applications has become a problem that developers need to solve. Among them, using Memcache caching technology for concurrency optimization has become a relatively popular solution. Memcache is an efficient caching technology suitable for large-scale web applications, databases and distributed systems. Its characteristic is to store data in memory to achieve high-speed read and write operations. During the data access process of web applications,

As web applications become increasingly complex, performance has become a critical issue. In many applications, database queries are one of the most time-consuming operations. In order to avoid frequently reading data from the database, a caching system can be used to store frequently read data in memory for quick access. In PHP development, using Memcached for distributed caching is an extremely common practice. In this article we will introduce how to use Memcached for distributed caching. What is Memca

How to use Memcache to optimize data storage operations in your PHP application? In web application development, data storage is a crucial link. In PHP applications, Memcache, as a memory cache system, can effectively improve the efficiency of data storage and reading operations. This article will introduce how to use Memcache to optimize data storage operations in PHP applications, and attach specific code examples. Step 1: Install the Memcache extension First, you need to install Me in your PHP environment
