Redis Client del函数未在for循环内调用

时间:2019-01-02 06:38:05

标签: javascript node.js redis

我一直试图在for循环中调用redisClient.del函数,但该函数未返回任何状态。

studentSchema.methods.generateAuthToken = function () {
    let admin = this;
    let access = 'student';
    let token = jwt.sign({ _id: student._id.toHexString(), access }, HRCSECRET).toString();
    student.tokens.forEach(element => {
        console.log(element.token);
        redisClient.del(element.token, (err, result) => {
            if(err){
                console.log(err);
            }
            else{
                console.log(result);
            }
        })
    });
    student.tokens = [{ access, token }];
    return student.save().then(() => { return token; });
};

在执行过程中没有打印console.log语句

1 个答案:

答案 0 :(得分:0)

您尝试签入Redis-cli是否删除了您的东西?

只需重构一下

   <div className="d-flex col-sm-6">
      <div className="" style={{backgroundColor: 'white', borderRadius: 5, border: '1px solid #EAE8E8'}}>
        <div className="row">
          <div className="d-flex col-md-8">
            <div className="row" style={{paddingTop: 20, paddingBottom: 20, paddingLeft: 40}}>
              <h4>
                <b>{this.props.restaurant.name}</b>&nbsp;
                {this.props.restaurant.dietaryRestrictions.map(function(dietaryRestriction, index) {
                  return(<div key={index}><span className="badge-sm badge-secondary" style={{color: 'white', backgroundColor: '#DA9550', fontSize: 9}}>{dietaryRestriction}</span>&nbsp;&nbsp;&nbsp;</div>);
                })}
              </h4>
             {this.props.restaurant.description}
              <br /><br />
             <span className="munchtime pointer"><i className="fas fa-check"></i> <b>Add to Cart</b></span><br /><br />
                <b><s>${this.props.restaurant.price}</s></b> <span className="discount"><b>${this.props.restaurant.price * this.props.restaurant.restaurant.discount}</b></span>
              </div>
            </div>
            <div className="d-flex col-md-4">
                <img src={this.props.restaurant.images[0]} style={{width: '100%', height: 250, objectFit: 'cover'}} />
            </div>
        </div>
      </div>
    </div>