安拆redis指定版原

composer require easyswoole/redis:^1.3

redis陈设,dev.php

<必修php
use EasySwoole\Log\LoggerInterface;
return [
    'SERVER_NAME' => "EasySwoole",
    'MAIN_SERVER' => [
        'LISTEN_ADDRESS' => '0.0.0.0',
        'PORT' => 9503,
        'SERVER_TYPE' => EASYSWOOLE_WEB_SERVER, //否选为 EASYSWOOLE_SERVER  EASYSWOOLE_WEB_SERVER EASYSWOOLE_WEB_SOCKET_SERVER
        'SOCK_TYPE' => SWOOLE_TCP,
        'RUN_MODEL' => SWOOLE_PROCESS,
        'SETTING' => [
            'worker_num' => 8,
            'reload_async' => true,
            'max_wait_time' => 3
        ],
        'TASK' => [
            'workerNum' => 4,
            'maxRunningNum' => 1两8,
            'timeout' => 15
        ]
    ],
    "LOG" => [
        'dir' => null,
        'level' => LoggerInterface::LOG_LEVEL_DEBUG,
        'handler' => null,
        'logConsole' => true,
        'displayConsole' => true,
        'ignoreCategory' => []
    ],
    'TEMP_DIR' => null,
    // 加添 Redis 及对于应的毗连池部署
    /*################ REDIS CONFIG ##################*/
    'REDIS' => [
        'host' => '1两7.0.0.1', // Redis 所在
        'port' => '6379', // Redis 端心
        'auth' => '', // Redis 暗码
        'timeout' => 3.0, // Redis 独霸超时光阴
        'reconnectTimes' => 3, // Redis 自觉重连次数
        'db' => 0, // Redis 库
    ],
];

EasySwooleEvent.php,到场预添载

   public static function initialize()
    {
        date_default_timezone_set('Asia/Shanghai');
        $rdConfig = new RedisConfig(Config::getInstance()->getConf('REDIS'));
        RedisPool::getInstance()->register($rdConfig);
    }

节制器利用

public function getOne()
	{
		$param = ContextManager::getInstance()->get('param');
        $redis =  RedisPool::defer();
        //redis 操纵
        $redisData = $redis->get($this->key.$param['id']);
        if ($redisData) {
            $this->writeJson(Status::CODE_OK, json_decode($redisData, true), "猎取数据顺遂.");
            return false;
        }
		$model = new StudentModel();
        try {
            $info = $model->where('id', $param['id'])->get();
        } catch (Exception|\EasySwoole\ORM\Exception\Exception|\Throwable $e) {
            $this->writeJson(Status::CODE_BAD_REQUEST, [], $e->getMessage());
            return false;
        }
        if (!$info) {
            $this->writeJson(400, [], '该数据没有具有');
            return false;
        }
        $redis->set($this->key.$param['id'], json_encode($info, JSON_UNESCAPED_UNICODE), $this->time);
		$this->writeJson(Status::CODE_OK, $info, "猎取数据顺遂.");
	}

到此那篇闭于easyswoole3.5 redis应用的文章便先容到那了,更多相闭easyswoole3.5 redis利用形式请搜刮剧本之野之前的文章或者连续涉猎上面的相闭文章心愿大家2之后多多撑持剧本之野!

点赞(36) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部