Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 数据查询用了memcache缓存,用sql做的键值,分页数据不变

数据查询用了memcache缓存,用sql做的键值,分页数据不变

Jun 23, 2016 pm 01:38 PM

数据查询用了memcache缓存,用sql做的键值,传递分页的参数 sql就会产生变化  如果没有数据  就会重新查询并缓存 但是现在遇到这样一个问题  我在本地测试没有问题 但是传到服务器以后 无论传递什么参数 sql 是随之变化的 但是依据变化的键值 获得的数据列表并不跟着变化 请教一下大家可能是什么原因


回复讨论(解决方案)

怎????
如果你?的是一?字符串,不可能?的,?查下代?。
看看是否?自?加上??那些??。

是不是服务器数据就那么几条 不用分页啊? 导致每页数据都一样。。

贴出关键代码。

怎????
如果你?的是一?字符串,不可能?的,?查下代?。
看看是否?自?加上??那些??。

    我把整个查询的sql 作为键值来存储数据的 刚开始上传到服务器的时候是没问题的读取正常也没有分页重复 ,运行一段时间后发现重复,后来同事说可能是因为把整个sql作为键值太长  md5($sql) 以后 再作为键值传递就正常了 ,memcache 缓存 会因为键值太长影响数据读取吗?

贴出关键代码。


$sql = "select id,avg_point,name,xpoint,ypoint,agent_area_id,area_id,supplier_id,index_img,dp_count,avg_point,deal_cate_id,ratio,area_id,note from aa  where 1 = 1 and is_effect=1 and city_id in (18,1) order by id DESC limit 0,15"; $key =  $GLOBALS['append_config']['IOS_CACHE_PRE'].$sql;    $info = mcache_get($key); if(!$info){    $info = $GLOBALS['db']->getAll($sql);    mcache_set($key,$info); }
Copy after login
  每次查询根据条件产生的sql是不一样的,只要sql不一样就会重新获取 ,但现在是即使sql作为键值每次都不一样也没有重新获取数据

把$sql md5?理吧。
memcache key有?度限制的。

$sql = "select id,avg_point,name,xpoint,ypoint,agent_area_id,area_id,supplier_id,index_img,dp_count,avg_point,deal_cate_id,ratio,area_id,note from aa  where 1 = 1 and is_effect=1 and city_id in (18,1) order by id DESC limit 0,15";
 $key =  md5($GLOBALS['append_config']['IOS_CACHE_PRE'].$sql);
    $info = mcache_get($key);
 if(!$info){
    $info = $GLOBALS['db']->getAll($sql);
    mcache_set($key,$info);
 }

是不是服务器数据就那么几条 不用分页啊? 导致每页数据都一样。。

  数据有很多是需要分页的

Keys
----

Data stored by memcached is identified with the help of a key. A key
is a text string which should uniquely identify the data for clients
that are interested in storing and retrieving it.  Currently the
length limit of a key is set at 250 characters (of course, normally
clients wouldn't need to use such long keys); the key must not include
control characters or whitespace.

百度翻译:
数据存储在memcached通过键值来标识。一个键的
是一个文本字符串必须唯一地识别客户的数据
有兴趣的存储和检索。目前,
一个键的 长度限制是250字符(当然,通常
客户不需要使用长键); 键必须不包括
控制字符或空格。

显然你已经违规了

ls已经说的很清楚了,虽然你的sql语句大约是220个字符长,并没有超出memcached的最大字符限制。但是因为sql中含有空格,所以,实际是使用sql的第一个空格之前的部分作为key的,这样的话,显然所有分页的数据都是一样的。
还是MD5搞起吧。

谢谢大家的热心回答

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)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
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)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

What exactly is the non-blocking feature of ReactPHP? How to handle its blocking I/O operations? What exactly is the non-blocking feature of ReactPHP? How to handle its blocking I/O operations? Apr 01, 2025 pm 03:09 PM

An official introduction to the non-blocking feature of ReactPHP in-depth interpretation of ReactPHP's non-blocking feature has aroused many developers' questions: "ReactPHPisnon-blockingbydefault...

See all articles