123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use Redis;
- class Demo extends Api
- {
-
-
-
-
-
- protected $noNeedLogin = ['test', 'test1'];
-
- protected $noNeedRight = ['test2'];
- protected $redis;
- public function __construct()
- {
- $this->roomTypeArr = [1=>"party",2=>"live"];
-
- $redis = new Redis();
- $redisconfig = config("redis");
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
- if ($redisconfig['redis_pwd']) {
- $redis->auth($redisconfig['redis_pwd']);
- }
- if($redisconfig['redis_selectdb'] > 0){
- $redis->select($redisconfig['redis_selectdb']);
- }
- $this->redis = $redis;
- }
-
- public function test()
- {
- exit;
- $party_id = 1;
- $userId = 3;
-
- $key = "party_seat_".$party_id;
- $seats = $this->redis->hGetAll($key);
- foreach($seats as $seat_num => $seatuserid){
- if($seatuserid == $userId){
- $this->redis->HDel($key, $seat_num);
- }
- }
- }
-
- public function test1()
- {
- $this->success('返回成功', ['action' => 'test1']);
- }
-
- public function test2()
- {
- $this->success('返回成功', ['action' => 'test2']);
- }
-
- public function test3()
- {
- $this->success('返回成功', ['action' => 'test3']);
- }
- }
|