Test.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\index\controller;
  3. use think\Db;
  4. use Redis;
  5. class Test
  6. {
  7. //显示所有人,匹配状态
  8. public function showredis(){
  9. $list = Db::name('user')->order('id desc')->column('id');
  10. foreach($list as $key => $id){
  11. dump($id.':'.redis_matching_get($id));
  12. echo '<br/>';
  13. }
  14. exit;
  15. }
  16. //清除所有人,匹配状态
  17. public function clearredis(){
  18. $list = Db::name('user')->order('id desc')->column('id');
  19. foreach($list as $key => $id){
  20. $a = redis_matching_set($id,0);
  21. }
  22. exit;
  23. }
  24. public function test1(){
  25. // 文本加一个回车
  26. $buffer1 = 'abcdefghijklmn';
  27. // 在php中双引号中的\n代表一个换行符,例如"\n"
  28. $buffer2 = '{"type":"say", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello"}'."";
  29. $buffer2 = 'abcdefghijklmn'."\n";
  30. // 与服务端建立socket连接
  31. $client = stream_socket_client('tcp://1.14.197.70:2349');
  32. // 以text协议发送buffer1数据
  33. //fwrite($client, $buffer1);
  34. // 以text协议发送buffer2数据
  35. fwrite($client, $buffer2);
  36. }
  37. //直播间详情
  38. public function show_livebc(){
  39. $party_id = input('party_id');
  40. if(empty($party_id)){
  41. $this->error();
  42. }
  43. $redis = new Redis();
  44. $redisconfig = config("redis");
  45. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  46. $a = $redis->get("livebc_".$party_id);
  47. dump($a);
  48. }
  49. //直播间贡献值
  50. public function show_livebc_jewel(){
  51. $party_id = input('party_id');
  52. if(empty($party_id)){
  53. $this->error();
  54. }
  55. $redis = new Redis();
  56. $redisconfig = config("redis");
  57. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  58. $userModel = new \app\common\model\User();
  59. // 获取条数
  60. $num = 3;
  61. // 获取3条财富排行周记录
  62. $getweek = $redis->zRevRange("livebc_jewel_to_".$party_id,0,-1,true);
  63. $getweek2 = $redis->zRevRange("livebc_jewel_get_".$party_id,0,0,true);
  64. $userList = $userModel->rankList($getweek);
  65. $userList2 = $userModel->rankList($getweek2);
  66. dump($getweek);
  67. dump($getweek2);
  68. dump($userList);
  69. dump($userList2);
  70. $avatarArr = [];
  71. if($userList) {
  72. foreach($userList as $k => $v) {
  73. $v["jewel"] > 0 && $avatarArr[] = $v["avatar"];
  74. }
  75. // 加入缓存做备份
  76. $redis->hSet("user_jewel_top3",$party_id,json_encode($avatarArr));
  77. //$redis->hSet("livebc_jewel_top3",$party_id,json_encode($avatarArr));
  78. }
  79. dump($avatarArr);
  80. }
  81. //清空直播间贡献值
  82. public function clear(){
  83. $party_id = input('party_id');
  84. if(empty($party_id)){
  85. $this->error();
  86. }
  87. //清空房间排行榜
  88. $redis = new Redis();
  89. $redisconfig = config("redis");
  90. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  91. $redis->del('livebc_jewel_to_' . $party_id);
  92. $redis->del('livebc_jewel_get_' . $party_id);
  93. $redis->hDel("user_jewel_top3",$party_id);
  94. }
  95. }