Beispiel #1
0
func NewUser(p *Models) *User {
	u := new(User)
	c, err := redis.Dial("tcp", cfg.RedisAddr(),
		redis.DialReadTimeout(1*time.Second), redis.DialWriteTimeout(1*time.Second))
	if err != nil {
		log.Error(err.Error())
		return nil
	}
	u.c = c

	//select db
	s, err := c.Do("SELECT", cfg.RedisDBs[cfg.Pf])
	if err != nil {
		log.Error(err.Error())
		return nil
	}
	//temp
	fw.PrintType(s, "s")

	//fill keys
	b, _ := redis.Bool(c.Do("EXISTS", k_account_count))

	//	switch b.(type) {
	//	case interface{}:
	//		log..Debug("interface")
	//	case []byte:
	//		log..Debug("byte")
	//	case string:
	//		log..Debug("string")
	//	case *int:
	//		log..Debug("int")
	//	default:
	//		log..Debug("other")
	//	}

	if b == false {
		c.Do("SET", k_account_count, 0)
		log.Info("fill key:", k_account_count)
	}

	//register model
	u.parent = p
	return u
}
Beispiel #2
0
func NewGame(p *Models) *Game {
	g := new(Game)
	c, err := redis.Dial("tcp", cfg.RedisAddr(),
		redis.DialReadTimeout(1*time.Second), redis.DialWriteTimeout(1*time.Second))
	if err != nil {
		log.Error(err.Error())
		return nil
	}
	g.c = c

	//select db
	_, err = c.Do("SELECT", cfg.RedisDBs[cfg.Game])
	if err != nil {
		log.Error(err.Error())
		return nil
	}

	//register model
	g.parent = p

	return g
}
Beispiel #3
0
func main() {
	redisConn, _ = redis.Dial("tcp", cfg.RedisAddr(),
		redis.DialReadTimeout(1*time.Second), redis.DialWriteTimeout(1*time.Second))
	s, _ := redisConn.Do("SELECT", 11)
	fmt.Println("select 11, s=", s)

	defer redisConn.Close()

	N := 10000
	//	acc := make(chan int, 0)
	//	do := 0
	//	mu := sync.Mutex{}
	//
	t1 := time.Now()

	for i := 0; i < N; i++ {
		//		go func() {
		//			mu.Lock()
		//			do = do + 1
		////			_, e := redisConn.Do("SET", do, "jjj")
		_, e := redisConn.Do("PING")
		if e != nil {
			fmt.Print(e, "\n")
		}
		//			mu.Unlock()
		//			acc <- 1
		//		}()
	}
	//	for i := 0; i < N; i++ {
	//		<-acc
	//	}

	t2 := time.Now()
	d := t2.Sub(t1)

	//	time.Sleep(3 * time.Second)
	//	log.Infof("BenchmarkGo, %+v times in %+v", do, d)
	log.Infof("BenchmarkGo, %+v times in %+v", N, d)
}