Redis服务器总是在应用

时间:2016-10-13 20:01:29

标签: php redis

所以我们一直在修改我们的应用程序以使用Redis来缓存我们的ORM(自定义构建)的一些结果,到目前为止它似乎工作得很好,直到我们遇到它总是崩溃我们给我们回来“RedisException:Redis服务器消失了”哦,因为有太多信息可以使用:)

我们一直在浏览日志(docker和verbose redis.log),以了解发生的事情无济于事。我们所知道的:

  • 问题的发生不是因为数据,而是因为尝试使用特定密钥进行SET或EXIST时。
  • 它始终与应用程序完全相同,我们可以刷新页面,并且它总是在代码中的某个特定点崩溃
  • 密钥可以是MD5,SHA'ed或我们从ORM数据构建的自然密钥,它总是崩溃。
  • 我们认为这可能是发送到redis的调用量(是的),但即使在删除所有对redis的EXIST调用并且仅使用GET并在内部处理异常或null值之后,错误仍然在该点完全弹出
  • 服务器没有真正消失,docker进程仍在运行,其中的进程仍在运行
  • 使用“redis-cli监视器”为我们提供了一个很好的日志记录,一切都记录到了那一点+ php session_save_handler将东西保存到redis(离开了,对,你接受保存恰好在错误之后的会议())
  • 查看“详细”定制的docker redis登录“/var/log/redis.log”会产生NO ERROR :(
  • 使用redis-cli从命令行自行设置密钥,使用MD5,SHA或自然组合密钥......

我们这里的选项实际上已经用完了,这里有一些更多的信息,比如代码,这样你就可以知道发生了什么,有些帮助会在这一点上受到赞赏:

更多信息

 Docker architecture
 PHP7.0 latest build
 Redis latest build from official repo on docker

RedisCache.php

/**
 * Standard Redis object coming from php-redis extension
 * @var \Redis
 */
protected $redis;

public function offsetExists($offset)
{
    try {
        return $this->redis->exists($offset); //<-- Fails here
    } catch (\RedisException $ex) {
        return false;
    }
}

public function offsetSet($offset, $value)
{
    $this->redis->set($offset, serialize($value)); //<-- Fails here
    $this->redis->expire($offset, 60 * 60);
}

client.api.php

public static function getCachedRecords(
    $endPoint,
    $data = [],
    $asArray = false,
    \LearningBird\Cache\BaseCache $cache
) {
    $key = 'api:' . md5(($asArray ? 'asArray' : '') . ':' . serialize([$endPoint, $data]));
    try {
        $data = $cache[$key];
    } catch (\Exceptions\Data\NotFoundException $ex) {
        $cache[$key] = $data = self::getRecords($endPoint, $data, $asArray);
    }

    return $data;
}

**编辑#1 - Stacktrace +有效的键的例子**

Array
(
[0] => Array
    (
        [file] => /var/www/Classes/LearningBird/Cache/RedisCache.php
        [line] => 64
        [function] => get
        [class] => Redis
        [type] => ->
        [args] => Array
            (
                [0] => api:4a23b037c2ff882924db6974a665b12a
            )

    )

[1] => Array
    (
        [file] => /var/www/feather/dataExchange/api.learningbird.com/client.api.php
        [line] => 262
        [function] => offsetGet
        [class] => LearningBird\Cache\RedisCache
        [type] => ->
        [args] => Array
            (
                [0] => api:4a23b037c2ff882924db6974a665b12a
            )

    )

[2] => Array
    (
        [file] => /var/www/feather/classes/mvc/models/topicsRecord.php
        [line] => 167
        [function] => getCachedRecords
        [class] => apiClient
        [type] => ::
        [args] => Array
            (
                [0] => /topics/getParentSuperTopics/4196
                [1] => Array
                    (
                    )

                [2] => 
                [3] => LearningBird\Cache\RedisCache Object
                    (
                        [redis:protected] => Redis Object
                            (
                                [socket] => 0
                            )

                    )

            )

    )

[3] => Array
    (
        [file] => /var/www/feather/classes/mvc/models/topicsRecord.php
        [line] => 177
        [function] => getParentSuperTopics
        [class] => topicsRecord
        [type] => ->
        [args] => Array
            (
            )

    )

[4] => Array
    (
        [file] => /var/www/Classes/LearningBird/Database/Provider/LessonProvider.php
        [line] => 282
        [function] => hasParentSuperTopics
        [class] => topicsRecord
        [type] => ->
        [args] => Array
            (
            )

    )

[5] => Array
    (
        [file] => /var/www/Classes/LearningBird/Database/Provider/LessonProvider.php
        [line] => 158
        [function] => getTopicsWithSuperTopics
        [class] => LearningBird\Database\Provider\LessonProvider
        [type] => ->
        [args] => Array
            (
                [0] => recordSet Object
                    (
                        /** hidden, too large **/
                    )

            )

    )

[6] => Array
    (
        [file] => /var/www/Classes/LearningBird/Database/Provider/LessonProvider.php
        [line] => 86
        [function] => LearningBird\Database\Provider\{closure}
        [class] => LearningBird\Database\Provider\LessonProvider
        [type] => ->
        [args] => Array
            (
                [0] => recordSet Object
                    (
                        /** hidden, too large **/
                    )

            )

    )

[7] => Array
    (
        [file] => /var/www/Classes/LearningBird/Database/Provider/LessonProvider.php
        [line] => 191
        [function] => getLessonsFromFilters
        [class] => LearningBird\Database\Provider\LessonProvider
        [type] => ->
        [args] => Array
            (
                [0] => Array
                    (
                        [0] => LearningBird\Database\Provider\LessonProviderFilter Object
                            (
                                [type:protected] => lesson
                                [id:protected] => 20386
                            )

                    )

                [1] => recordSet Object
                    (
                        /** hidden, too large **/
                    )

                [2] => Closure Object
                    (
                        /** hidden, too large **/
                    )

                [3] => 
                [4] => Array
                    (
                        /** hidden, too large **/
                    )

                [5] => Array
                    (
                        [0] => and
                        [1] => or
                        [2] => or
                    )

            )

    )

[8] => Array
    (
        [file] => /var/www/Classes/LearningBird/Database/Provider/STDAProvider.php
        [line] => 82
        [function] => getSTDALessons
        [class] => LearningBird\Database\Provider\LessonProvider
        [type] => ->
        [args] => Array
            (
                [0] => Array
                    (
                        [0] => LearningBird\Database\Provider\LessonProviderFilter Object
                            (
                                [type:protected] => lesson
                                [id:protected] => 20386
                            )

                    )

                [1] => topicLessonsRecordSet Object
                    (
                        /** hidden, too large **/
                    )

                [2] => differentiationsRecordSet Object
                    (
                        [records:protected] => Array
                            (
                                /** hidden, too large **/
                            )

                    )

            )

    )

[9] => Array
    (
        [file] => /var/www/Classes/LearningBird/Database/Provider/STDAProvider.php
        [line] => 44
        [function] => getAllSTDAs
        [class] => LearningBird\Database\Provider\STDAProvider
        [type] => ->
        [args] => Array
            (
                /** hidden, too large **/
            )

    )

[10] => Array
    (
        [file] => /var/www/app/application/components/lessons/component.php
        [line] => 227
        [function] => getSTDAs
        [class] => LearningBird\Database\Provider\STDAProvider
        [type] => ->
        [args] => Array
            (
                ** hidden, too large **/
            )

    )

[11] => Array
    (
        [function] => watch
        [class] => lessonsController
        [type] => ->
        [args] => Array
            (
                [0] => dlvi1mywqv6c6sh0
            )

    )

[12] => Array
    (
        [file] => /var/www/feather/classes/mvc/baseController.php
        [line] => 221
        [function] => invokeArgs
        [class] => ReflectionMethod
        [type] => ->
        [args] => Array
            (
                ** hidden, too large **/
            )

    )

[13] => Array
    (
        [file] => /var/www/feather/classes/mvc/baseController.php
        [line] => 105
        [function] => exec
        [class] => baseController
        [type] => ->
        [args] => Array
            (
            )

    )

[14] => Array
    (
        [file] => /var/www/feather/classes/mvc/baseController.php
        [line] => 89
        [function] => _run
        [class] => baseController
        [type] => ->
        [args] => Array
            (
            )

    )

[15] => Array
    (
        [file] => /var/www/feather/classes/component/core.component.php
        [line] => 43
        [function] => run
        [class] => baseController
        [type] => ::
        [args] => Array
            (
            )

    )

[16] => Array
    (
        [file] => /var/www/app/application/webroot/index.php
        [line] => 170
        [function] => run
        [class] => component
        [type] => ::
        [args] => Array
            (
                [0] => lessons
            )

    )

)

按照相同原则工作的密钥示例

topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"1599";";}";}

gradesModel:a:2:{s:9:"innerJoin";s:7:"s:0:"";";s:5:"where";s:95:"a:1:{s:10:"gradeLevel";s:63:"a:3:{i:0;s:8:"s:1:"9";";i:1;s:8:"s:1:"9";";i:2;s:8:"s:1:"9";";}";}";}

topicsModel:a:2:{s:9:"innerJoin";s:20:"s:12:"topicLessons";";s:5:"where";s:98:"a:2:{s:20:"topicLessons.deleted";s:8:"s:1:"0";";s:21:"topicLessons.lessonID";s:12:"s:5:"20386";";}";}

topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"4196";";}";}

languagesModel:a:1:{s:5:"where";s:37:"a:1:{s:9:"statusID!";s:8:"s:1:"0";";}";}

topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"2718";";}";}

differentiationsModel:a:2:{s:9:"innerJoin";s:30:"s:22:"lessonDifferentiations";";s:5:"where";s:65:"a:1:{s:31:"lessonDifferentiations.lessonID";s:12:"s:5:"20386";";}";}

regionsModel:a:1:{s:5:"where";s:66:"a:2:{s:9:"countryID";s:7:"s:0:"";";s:7:"stateID";s:9:"s:2:"79";";}";}

topicsModel:a:2:{s:9:"innerJoin";s:7:"s:0:"";";s:5:"where";s:103:"a:1:{s:7:"topicID";s:75:"a:3:{i:0;s:11:"s:4:"3361";";i:1;s:11:"s:4:"1523";";i:2;s:11:"s:4:"2115";";}";}";}

topicsModel:a:1:{s:5:"where";s:40:"a:1:{s:7:"topicID";s:12:"s:5:"11270";";}";}

topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"1523";";}";}

topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"3361";";}";}

api:b1eb15940ff2c1caca5e51239580c924

topicsModel:a:1:{s:5:"where";s:36:"a:1:{s:4:"slug";s:11:"s:4:"math";";}";}

topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"3205";";}";}

differentiationsModel:a:0:{}

stateSchoolStructuresModel:a:1:{s:5:"where";s:36:"a:1:{s:7:"stateID";s:9:"s:2:"79";";}";}

api:5135098ff6e115ec160bb9d552ac9442

statesModel:a:1:{s:5:"where";s:36:"a:1:{s:7:"stateID";s:9:"s:2:"79";";}";}

languagesModel:a:1:{s:5:"where";s:39:"a:1:{s:10:"languageID";s:8:"s:1:"1";";}";}

api:e532b1617c11604e6f5e241fffcc0e27

**不起作用的键(相同键,md5'或自然键)**

api::a:2:{i:0;s:33:"/topics/getParentSuperTopics/4196";i:1;a:0:{}}

4a23b037c2ff882924db6974a665b12a

0 个答案:

没有答案