zoukankan      html  css  js  c++  java
  • 【记录一个问题】redis中执行事务出现错误“EXECABORT Transaction discarded because of previous errors”

    执行事务的大致代码如下:

    redisClient := GetRedisClient()
    pipe := redisClient.TxPipeline()
    err := pipe.ZAdd(k, arrZ...).Result()
    //...
    arr, err := pipe.Exec()
    if err != nil {
        log.Println(err, arr)  //这里打印错误 EXECABORT Transaction discarded because of previous errors
    }
    

    陆续排除了以下可能:

    • 是不是redis的内存满了
    • 是不是redis服务器保存了个什么状态
    • 是不是因为竞争太激烈,所以出错

    改了一行代码后,错误不一样了:
    pipe := redisClient.Pipeline() //使用批量的管道,但是不使用事务
    错误变为:ERR wrong number of arguments for 'zadd' command

    认真看看,原来是特定条件下, arrZ这个数组可能会为空。
    修改为:

    redisClient := GetRedisClient()
    pipe := redisClient.TxPipeline()
    if len(arrZ)>0{
        err := pipe.ZAdd(k, arrZ...).Result()
    }
    //...
    arr, err := pipe.Exec()
    if err != nil {
        log.Println(err, arr)
    }
    

    问题解决。根本上还是命令参数错误导致的,但是事务模式下给出了错误的提示。

  • 相关阅读:
    HashMap 链表插入方式 → 头插为何改成尾插 ?
    MySQL 日志之 binlog 格式 → 关于 MySQL 默认隔离级别的探讨
    Eclipse
    Delphi
    Delphi
    Delphi
    Delphi
    Delphi
    Delphi
    Delphi
  • 原文地址:https://www.cnblogs.com/ahfuzhang/p/12918730.html
Copyright © 2011-2022 走看看