func TestMain(t *testing.T) { server, err := redistest.NewServer(true, nil) if err != nil { t.Error(err) } defer server.Stop() host := server.Config["unixsocket"] opt := redis.Options{} opt.Addr = host opt.Network = "unix" client := redis.NewClient(&opt) defer client.Close() if strCmd := client.Set("foo2", "bar"); strCmd.Err() != nil { t.Errorf(strCmd.Err()) } if strCmd := client.Get("foo2"); strCmd.Err() != nil { t.Errorf(strCmd.Err()) } else { fmt.Println(strCmd.String()) } }
func main() { ch := make(chan int, 10) // 初始化Log stdOutput := logging.NewLogBackend(os.Stderr, "", 0) stdOutputFormatter := logging.NewBackendFormatter(stdOutput, format) logging.SetBackend(stdOutputFormatter) redis = goredis.NewClient(redisConf) // 读取参数来获得配置文件的名称 argCount := len(os.Args) if argCount == 0 { log.Warning("需要输入配置文件名称: 格式 '-c fileName'") return } cmd := flag.String("c", "help", "配置文件名称") flag.Parse() if *cmd == "help" { log.Warning("需要输入配置文件名称: 格式 '-c fileName'") return } if _, err := toml.DecodeFile(*cmd, &config); err != nil { log.Error("配置文件有问题: %v", err) return } for _, playerInfo := range config.PlayerInfo { go MakeRequest(playerInfo, ch) } <-ch }
func main() { // 初始化Log stdOutput := logging.NewLogBackend(os.Stderr, "", 0) stdOutputFormatter := logging.NewBackendFormatter(stdOutput, format) logging.SetBackend(stdOutputFormatter) redis = goredis.NewClient(redisConf) // 读取参数来获得配置文件的名称 argCount := len(os.Args) if argCount == 0 { log.Warning("需要输入配置文件名称: 格式 '-c fileName'") return } cmd := flag.String("c", "help", "配置文件名称") flag.Parse() if *cmd == "help" { log.Warning("需要输入配置文件名称: 格式 '-c fileName'") return } if _, err := toml.DecodeFile(*cmd, &config); err != nil { log.Error("配置文件有问题: %v", err) return } if _, err := toml.DecodeFile("comments.toml", &leaveComments); err != nil { log.Error("解析留言列表有问题: %v", err) return } _saveCommentsToRedis() // for i := 0; i < 100000; i++ { // log.Debug("Comment: %v", _getRandomComment()) // } epicHelper := []PlayerInfo{} for _, info := range config.PlayerInfo { if info.EpicHelper == true { epicHelper = append(epicHelper, info) } } if len(epicHelper) == 0 { log.Error("没有配置帮飞号信息") return } ch := make(chan int, len(epicHelper)) for _, playerInfo := range epicHelper { go MakeRequest(playerInfo, ch) } <-ch }
func main() { // 初始化Log stdOutput := logging.NewLogBackend(os.Stderr, "", 0) stdOutputFormatter := logging.NewBackendFormatter(stdOutput, format) logging.SetBackend(stdOutputFormatter) redis = goredis.NewClient(redisConf) http.HandleFunc("/verify", verifyResponse) err := http.ListenAndServe(":9896", nil) if err != nil { log.Fatal("ListenAndServe:", err) } }
func main() { redis = goredis.NewClient(redisConf) for _, key := range redis.Keys("energy:*:round").Val() { fmt.Println(key) redis.Del(key) } for _, key := range redis.Keys("epic:*:round").Val() { fmt.Println(key) redis.Del(key) } }
func example1() { var host string flag.StringVar(&host, "host", "localhost", "host name") flag.Parse() opt := redis.Options{} opt.Addr = strings.Join([]string{host, "6379"}, ":") opt.Network = "tcp" client := redis.NewClient(&opt) defer client.Close() client.Set("foo", "bar") strCmd := client.Get("foo") fmt.Println(strCmd.String()) }