Example #1
0
func benchMSet(cliPool *table.Pool, zop bool) {
	var colKeys = make([][]byte, *rangeNum)
	for i := 0; i < *rangeNum; i++ {
		colKeys[i] = []byte(fmt.Sprintf("%03d", i))
	}

	var op = func(v int, p *OpParam) {
		var rowKey = strconv.AppendInt(p.keyBuf, int64(v), 10)
		copy(p.value, rowKey)

		var ma table.MSetArgs
		for i := 0; i < len(colKeys); i++ {
			ma.Add(0, rowKey, colKeys[i], p.value, int64(v*1000+i), 0)
		}

		mSet(p.c, p.done, zop, ma)

		p.ResetValue(len(rowKey))
	}

	if zop {
		benchmark(cliPool, fmt.Sprintf("ZMSET %d", *rangeNum), op)
	} else {
		benchmark(cliPool, fmt.Sprintf("MSET %d", *rangeNum), op)
	}
}
Example #2
0
func testZScan(tc *table.Context) {
	// ZSET
	err := tc.ZSet(1, []byte("row2"), []byte("000"), []byte("v00"), 10, 0)
	if err != nil {
		fmt.Printf("ZSet failed: %s\n", err)
		return
	}

	// ZMSET
	var ma table.MSetArgs
	ma.Add(1, []byte("row2"), []byte("001"), []byte("v01"), 9, 0)
	ma.Add(1, []byte("row2"), []byte("002"), []byte("v02"), 6, 0)
	ma.Add(1, []byte("row2"), []byte("003"), []byte("v03"), 7, 0)
	ma.Add(1, []byte("row2"), []byte("004"), []byte("v04"), 8, 0)
	ma.Add(1, []byte("row2"), []byte("005"), []byte("v05"), -5, 0)
	_, err = tc.ZmSet(ma)
	if err != nil {
		fmt.Printf("ZmSet failed: %s\n", err)
		return
	}

	// ZSCAN
	r, err := tc.ZScan(1, []byte("row2"), true, true, 4)
	if err != nil {
		fmt.Printf("ZScan failed: %s\n", err)
		return
	}

	fmt.Println("ZSCAN result:")
	for {
		printScanReply(r)

		if r.End {
			fmt.Println("ZSCAN finished!")
			break
		} else {
			fmt.Println("ZSCAN has more records:")
		}

		r, err = tc.ScanMore(r)
		if err != nil {
			fmt.Printf("ScanMore failed: %s\n", err)
			return
		}
	}
}
Example #3
0
func testMGet(tc *table.Context) {
	// MSET
	var ma table.MSetArgs
	ma.Add(1, []byte("row1"), []byte("col0"), []byte("v00"), 10, 0)
	ma.Add(1, []byte("row1"), []byte("col1"), []byte("v01"), 9, 0)
	ma.Add(1, []byte("row1"), []byte("col2"), []byte("v02"), 8, 0)
	ma.Add(1, []byte("row1"), []byte("col3"), []byte("v03"), 7, 0)
	ma.Add(1, []byte("row8"), []byte("col4"), []byte("v04"), 6, 0)
	_, err := tc.MSet(ma)
	if err != nil {
		fmt.Printf("Mset failed: %s\n", err)
		return
	}

	// MGET
	var mb table.MGetArgs
	mb.Add(1, []byte("row8"), []byte("col4"), 0)
	mb.Add(1, []byte("row1"), []byte("col2"), 0)
	mb.Add(1, []byte("row1"), []byte("col1"), 0)
	mb.Add(1, []byte("row1"), []byte("col3"), 0)
	mb.Add(1, []byte("row8"), []byte("not"), 0)
	r, err := tc.MGet(mb)
	if err != nil {
		fmt.Printf("Mget failed: %s\n", err)
		return
	}

	fmt.Println("MGET result:")
	for i := 0; i < len(r); i++ {
		if r[i].ErrCode < 0 {
			fmt.Printf("[%q\t%q]\tget failed with error %d!\n",
				r[i].RowKey, r[i].ColKey, r[i].ErrCode)
		} else if r[i].ErrCode > 0 {
			fmt.Printf("[%q\t%q]\tkey not exist!\n",
				r[i].RowKey, r[i].ColKey)
		} else {
			fmt.Printf("[%q\t%q]\t[%d\t%q]\n",
				r[i].RowKey, r[i].ColKey,
				r[i].Score, r[i].Value)
		}
	}
}