Hyperf如何使用redis

1程序根目录下 .env文件配置redis服务器参数
 

REDIS_HOST=127.0.0.1
REDIS_AUTH=(null)
REDIS_PORT=6379
REDIS_DB=1

2  Controller文件中

request->input('user', 'Hyperf');
        $method = $this->request->getMethod();

		$container = ApplicationContext::getContainer();
        $this->redis = $container->get(\Redis::class);

        $this->redis->set('name',12345);
        $user.=$this->redis->get('name');       
        

        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }


}

 

你可能感兴趣的:(redis,redis)