Test.php 3.3 KB

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