浏览代码

修改工具类

renzheng 9 年之前
父节点
当前提交
65aaaef4f2
共有 2 个文件被更改,包括 9 次插入2 次删除
  1. 3 0
      common/src/qfw/util/mongodb/mongodbutil.go
  2. 6 2
      common/src/qfw/util/redis/redisutil.go

+ 3 - 0
common/src/qfw/util/mongodb/mongodbutil.go

@@ -188,6 +188,7 @@ func SaveBulk(c string, doc ...map[string]interface{}) bool {
 	b := true
 	if sess != nil {
 		defer func() {
+			b = false
 			if r := recover(); r != nil {
 				log.Println("[E]", r)
 				for skip := 1; ; skip++ {
@@ -210,6 +211,8 @@ func SaveBulk(c string, doc ...map[string]interface{}) bool {
 			log.Println("BulkError", err)
 			b = false
 		}
+	} else {
+		b = false
 	}
 	return b
 }

+ 6 - 2
common/src/qfw/util/redis/redisutil.go

@@ -16,12 +16,16 @@ var RedisPool map[string]*redigo.Pool
 
 //初始化redis 1为多个连接池,2为共用一个连接池
 func InitRedis(addrs string) {
+	InitRedisBySize(addrs, 1000, 500, 240)
+}
+
+func InitRedisBySize(addrs string, maxSize, maxIdle, timeout int) {
 	RedisPool = map[string]*redigo.Pool{}
 	addr := strings.Split(addrs, ",")
 	for _, v := range addr {
 		saddr := strings.Split(v, "=")
-		RedisPool[saddr[0]] = &redigo.Pool{MaxActive: 1000, MaxIdle: 800,
-			IdleTimeout: 240 * time.Second, Dial: func() (redigo.Conn, error) {
+		RedisPool[saddr[0]] = &redigo.Pool{MaxActive: maxSize, MaxIdle: maxIdle,
+			IdleTimeout: time.Duration(timeout) * time.Second, Dial: func() (redigo.Conn, error) {
 				c, err := redigo.Dial("tcp", saddr[1])
 				if err != nil {
 					return nil, err