php-Redis+easytask-公众号发送消息,消息队列

php-Redis+easytask-公众号发送消息,消息队列

redis命令与安装

10、redis安装设置密码(https://www.bilibili.com/read/cv10091113/)
1.获取redis资源(安装在这个目录下:/usr/local )
  wget http://download.redis.io/releases/redis-4.0.8.tar.gz

2.解压

  tar xzvf redis-4.0.8.tar.gz

3.安装

  cd redis-4.0.8

  make或者make installls
# 方法一:
redis-cli -a 123456
# 方法一去掉waring警告
redis-cli -a 123456 2>/dev/null
# 方法二:
redis-cli
>auth 123456
redis 127.0.0.1:6379> ping
PONG
我们已经成功安装了redis。
https://www.codetd.com/article/7977268
[root@iZbp1b2c0jvnj0npffk75aZ redis-4.0.8]# src/redis-server ./redis.conf
vim redis.conf

(68条消息) liunx php redis扩展,CentOS 7下安装php-redis扩展及简单使用_暗山的博客-CSDN博客

ps -aux:解析redis进程
ctrl+c 退出
top命令经常用来监视系统活动进程和系统的资源负载信息等
shift+m 查看内存占用排序
https://www.cnblogs.com/zhoug2020/p/6336453.html(查看cup资源负载消息)
9.设置redis密码

  a.运行命令:redis-cli

  b.查看现有的redis密码(可选操作,可以没有)

    运行命令:config get requirepass 如果没有设置过密码的话运行结果会如下图所示

  c.设置redis密码

    运行命令:config set requirepass ****(****为你要设置的密码),设置成功的话会返回‘OK’字样 作者:Dolue https://www.bilibili.com/read/cv10091113/ 出处:bilibili

出现这种错误后解决的方法有两种:

一、第一种方法:如果有root权限,可以输入  :wq!强行保存退出。

二、第二种方法:

(1)按ESC

(2)输入   :set noreadonly

(3)输入    :wq就可保存退出

1:配置文件confi/redis.php

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/10
 * Time: 17:39
 */
return [
    // 服务器地址
  'host'       => env('redis.host','127.0.0.1'),
    // 端口
  'port'     => env('redis.port',6379),
    //密码
  'password' => env('redis.password','123456')
];

1:文件use app\util\Redis(封装类);

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/12/1
 * Time: 11:04
 */

namespace app\util;


use think\facade\Config;

class Redis
{
    protected $config;
    public $redis;

    public function __construct()
    {
        $this->config=Config::get('redis');
        $this->redis=new \Redis();
        $this->redis->connect($this->config['host'],intval($this->config['port']));
        if($this->config['password']) $this->redis->auth($this->config['password']);
    }

    public function getRedis(){
        return $this->redis;
    }
}

2:字符串插入redis–lPush(应用类:use app\util\Redis;)

                $redis = new Redis();
                $credis = $redis->getRedis();
                $tmp=[];
                foreach ($sendUser as $v) {
                    $msend = new \app\index\model\MessageSend();
                    $msend->fname = 'notice';
                    $msend->contentId = $v->id;
                    $msend->save();
                    $credis->lPush('tmessage', $msend->id);
                    $arr=[];
                    $arr['title']=$send->title;
                    $arr['toUserId']=$v->userId;
                    $arr['messageTime']=$send->createTime;
                    $arr['contentId']=$id;
//                    $arr['type']=2;
                    $arr['remark']=$send->remark;
                    $tmp[]=$arr;
                }
                Notice::insertAll($tmp);
                $credis->close();

3:字符串读写进行删除redis–lPop

<?php


namespace app\task;


use app\util\MessageSend;
use think\facade\Config;

class Send
{
//推送的消息队列
    public function redisQueue()
    {
        set_time_limit(0);
        $messgeSend = new MessageSend();

        $redis = new \Redis();
        $config = Config::get('redis');
        $redis->connect($config['host'], intval($config['port']));
        if ($config['password']) {
            $redis->auth($config['password']);
        }
        $isTrue = true;
        do {
            $id = $redis->lPop('message');
            if ($id) {
                try {
                    $messgeSend->getMessageSend($id);//指定方法执行操作
                } catch (\Exception $e) {
                    setLog($e->getLine() . '.' . $e->getMessage(), 'send_queue', 'sync');
                }
            } else {
                $isTrue = false;
                $messgeSend->close();
            }
        } while ($isTrue);
        $redis->close();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值