Code Monkey home page Code Monkey logo

model-cache's People

Contributors

assert6 avatar daydaygo avatar huangdijia avatar huangzhhui avatar limingxinleo avatar minxinqing avatar sy-records avatar wenbinye avatar weskiller avatar wuwu123 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

wuwu123

model-cache's Issues

使用 findManyFromCache 时报错

报错信息:
PHP Warning: foreach() argument must be of type array|object, bool given in /data/php-server/vendor/hyperf/model-cache/src/Redis/HashGetMultiple.php on line 32

问题定位点:

// vendor/hyperf/model-cache/src/Redis/HashGetMultiple.php

    public function parseResponse($data)
    {
        $result = [];
        foreach ($data ?? [] as $item) {
            if (! empty($item) && is_array($item)) {
                $temp = [];
                $count = count($item);
                for ($i = 0; $i < $count; ++$i) {
                    $temp[$item[$i]] = $item[++$i];
                }

                $result[] = $temp;
            }
        }

        return $result;
    }

查看源码发现 $data 的值是通过lua脚本获取的,脚本内容:

// vendor/hyperf/model-cache/src/Redis/HashGetMultiple.php

    public function getScript(): string
    {
        return <<<'LUA'
    local values = {}; 
    for i,v in ipairs(KEYS) do 
        if(redis.call('type',v).ok == 'hash') then
            values[#values+1] = redis.call('hgetall',v);
        end
    end
    return values;
LUA;
    }

本地环境测试了一下,在没有任何缓存时、有部分缓存时、全部key均有缓存时都没有复现这个问题。。
目前服务是正常的(程序会当作空数组,即没有获取到缓存处理)

想问一下,什么情况下这个lua脚本会返回false呢??是不是redis配置有什么问题?

本地和线上的model-cache包版本均为 3.0.17
线上使用的docker镜像为 hyperf/hyperf:8.0-alpine-v3.16-swoole-v5.0.1

使用`findManyFromCache($ids)`的时候,同一个浏览器下两次请求进入控制器的时间产生了间隔

问题描述:

在我的本地环境下,当我使用findManyFromCache($ids)的时候

  1. 在没有缓存的情况下,当$ids大于400之后,同一个浏览器下两次请求进入控制器的时间产生了间隔。
  2. 在缓存生成后或者$ids小于400的时候,同一个浏览器下没有两次请求进入控制器的时间产生了间隔这种情况发生。
  3. 在直接请求数据库limit()->get()的时候,同一个浏览器下没有两次请求进入控制器的时间产生了间隔这种情况发生。
  4. 在不同浏览器下发送请求,没有两次请求进入控制器的时间产生了间隔这种情况发生。

而且,这个间隔非常的相似,20s
所以,想请教一下,这个可能是我这里什么原因导致的?

php版本和swoole扩展

image
image

代码:

image

实验内容:

分别尝试limit100、400、500、1000的情况下请求是否产生了间隔。

实验结果:

1.清除缓存,使用一个浏览器发送两个请求,limit限制100
image

2.清除缓存,使用一个浏览器发送两个请求,limit限制400
image

3.清除缓存,使用一个浏览器发送两个请求,limit限制500
image

4.清除缓存,使用一个浏览器发送两个请求,limit限制1000
image

5.清除缓存,使用两个浏览器发送两个请求,limit限制1000
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.