func main() { flag.Parse() if *number <= 0 { panic("invalid number") return } if *clients <= 0 || *number < *clients { panic("invalid client number") return } loop = *number / *clients addr := fmt.Sprintf("%s:%d", *ip, *port) cfg := new(ledis.Config) cfg.Addr = addr client = ledis.NewClient(cfg) rand.Seed(time.Now().Unix()) if *tp == "write" { benchZAdd() benchSet() } else if *tp == "read" { setRead() benchZSetRead() } else { fmt.Println("Unsupport type ") } }
func main() { flag.Parse() if *number <= 0 { panic("invalid number") return } if *clients <= 0 || *number < *clients { panic("invalid client number") return } loop = *number / *clients addr := fmt.Sprintf("%s:%d", *ip, *port) cfg := new(ledis.Config) cfg.Addr = addr cfg.MaxIdleConns = *clients client = ledis.NewClient(cfg) if *round <= 0 { *round = 1 } for i := 0; i < *round; i++ { benchSet() benchGet() benchRandGet() benchDel() benchPushList() benchRangeList10() benchRangeList50() benchRangeList100() benchPopList() benchHset() benchHGet() benchHRandGet() benchHDel() benchZAdd() benchZIncr() benchZRangeByRank() benchZRangeByScore() //rev is too slow in leveldb, rocksdb or other //maybe disable for huge data benchmark if *reverse == true { benchZRevRangeByRank() benchZRevRangeByScore() } benchZDel() println("") } }
func TestScan(t *testing.T) { cfg := new(config.Config) cfg.DataDir = "/tmp/test_scan" cfg.Addr = "127.0.0.1:11185" os.RemoveAll(cfg.DataDir) s, err := NewApp(cfg) if err != nil { t.Fatal(err) } go s.Run() defer s.Close() cc := new(ledis.Config) cc.Addr = cfg.Addr cc.MaxIdleConns = 1 c := ledis.NewClient(cc) defer c.Close() testKVScan(t, c) testHashScan(t, c) testListScan(t, c) testZSetScan(t, c) testSetScan(t, c) testBitScan(t, c) }
func main() { flag.Parse() cfg := new(ledis.Config) if len(*socket) > 0 { cfg.Addr = *socket } else { cfg.Addr = fmt.Sprintf("%s:%d", *ip, *port) } cfg.MaxIdleConns = 1 c := ledis.NewClient(cfg) setHistoryCapacity(100) reg, _ := regexp.Compile(`'.*?'|".*?"|\S+`) for { cmd, err := line(fmt.Sprintf("%s> ", cfg.Addr)) if err != nil { fmt.Printf("%s\n", err.Error()) return } cmds := reg.FindAllString(cmd, -1) if len(cmds) == 0 { continue } else { addHistory(cmd) args := make([]interface{}, len(cmds[1:])) for i := range args { args[i] = strings.Trim(string(cmds[1+i]), "\"'") } r, err := c.Do(cmds[0], args...) if err != nil { fmt.Printf("%s", err.Error()) } else { printReply(cmd, r) } fmt.Printf("\n") } } }
func main() { flag.Parse() if *number <= 0 { panic("invalid number") return } if *clients <= 0 || *number < *clients { panic("invalid client number") return } loop = *number / *clients addr := fmt.Sprintf("%s:%d", *ip, *port) cfg := new(ledis.Config) cfg.Addr = addr client = ledis.NewClient(cfg) benchSet() benchIncr() benchGet() benchPushList() benchRangeList10() benchRangeList50() benchRangeList100() benchPopList() benchHset() benchHGet() benchHIncr() benchHDel() benchZAdd() benchZIncr() benchZRangeByRank() benchZRangeByScore() benchZRevRangeByRank() benchZRevRangeByScore() benchZDel() }
func newTestLedisClient() { cfg := new(ledis.Config) cfg.Addr = "127.0.0.1:16380" cfg.MaxIdleConns = 4 testLedisClient = ledis.NewClient(cfg) }
func main() { flag.Parse() cfg := new(ledis.Config) if len(*socket) > 0 { cfg.Addr = *socket } else { cfg.Addr = fmt.Sprintf("%s:%d", *ip, *port) } cfg.MaxIdleConns = 1 c := ledis.NewClient(cfg) sendSelect(c, *dbn) SetCompletionHandler(completionHandler) setHistoryCapacity(100) reg, _ := regexp.Compile(`'.*?'|".*?"|\S+`) prompt := "" for { if *dbn > 0 && *dbn < 16 { prompt = fmt.Sprintf("%s[%d]>", cfg.Addr, *dbn) } else { prompt = fmt.Sprintf("%s>", cfg.Addr) } cmd, err := line(prompt) if err != nil { fmt.Printf("%s\n", err.Error()) return } cmds := reg.FindAllString(cmd, -1) if len(cmds) == 0 { continue } else { addHistory(cmd) args := make([]interface{}, len(cmds[1:])) for i := range args { args[i] = strings.Trim(string(cmds[1+i]), "\"'") } cmd := strings.ToLower(cmds[0]) if cmd == "help" || cmd == "?" { printHelp(cmds) } else { r, err := c.Do(cmds[0], args...) if err == nil && strings.ToLower(cmds[0]) == "select" { *dbn, _ = strconv.Atoi(cmds[1]) } if err != nil { fmt.Printf("%s", err.Error()) } else { if cmd == "info" { printInfo(r.([]byte)) } else { printReply(0, r) } } fmt.Printf("\n") } } } }