示例#1
0
func exampleNS(db *levigo.DB) {
	runtime.GOMAXPROCS(runtime.NumCPU())

	fmt.Println("add some data first for a,a:1,a:2,a:1:2,a:2:1,a:3,a:1:1 ~")
	lns.PushNS("a", "A", db)
	lns.PushNS("a:1", "A1", db)
	lns.PushNS("a:2", "A2", db)
	lns.PushNS("a:1:2", "A12", db)
	lns.PushNS("a:2:1", "A21", db)
	lns.PushNS("a:3", "A3", db)
	lns.PushNS("a:1:1", "A11", db)
	lns.PushNS("b:2:1", "A11", db)

	fmt.Println("read some data now ~")
	read("val::a", db)
	read("val::a:1", db)
	read("val::a:2", db)
	read("val::a:1:2", db)
	read("val::a:2:1", db)
	read("val::a:3", db)
	read("val::a:1:1", db)

	fmt.Println("super keys~")
	read("key::a", db)
	read("key::a:1", db)
	read("key::a:2", db)
	read("key::b", db)
	read("key::b:2", db)

	var hmap map[string]string
	hmap = make(map[string]string)
	hmap = lns.ReadNS("key::a", db)
	for k, v := range hmap {
		fmt.Printf("%s => %s\n", k, v)
	}
	hmap = lns.ReadNS("key::c", db)
	for k, v := range hmap {
		fmt.Printf("%s => %s", k, v)
	}

	fmt.Println("read/delete~")
	fmt.Printf("Recursive under a: %v\n", lns.ReadNSRecursive("a", db))
	fmt.Println("before del a:1:2 ~ ", abkleveldb.GetVal("key::a:1", db))
	lns.DeleteNSRecursive("a:1:2", db)
	fmt.Println("after del of a:1:2 ~ ", abkleveldb.GetVal("key::a:1", db))
	fmt.Printf("Recursive under a: %v\n", lns.ReadNSRecursive("a", db))
	fmt.Println("before del a ~ ", abkleveldb.GetVal("key::a", db))
	lns.DeleteNSRecursive("a", db)
	fmt.Println("after del a ~ ", abkleveldb.GetVal("key::a", db))
	fmt.Printf("Recursive under a: %v\n", lns.ReadNSRecursive("a", db))
	fmt.Printf("Recursive under b: %v\n", lns.ReadNSRecursive("b", db))
	fmt.Println("before del of b ~", abkleveldb.GetVal("key::b", db))
	lns.DeleteNS("b", db)
	fmt.Println("after del of b ~ ", abkleveldb.GetVal("key::b", db))
	fmt.Println("after del b:2 ~ ", abkleveldb.GetVal("key::b:2", db))
	fmt.Println("after del b:2:1 ~ ", abkleveldb.GetVal("key::b:2:1", db))
	fmt.Printf("Recursive under b: %v\n", lns.ReadNSRecursive("b", db))
}
func everySecondOfHour(hour int, check string, db *levigo.DB) {
	for sec := 0; sec < 3600; sec++ {
		nukey := fmt.Sprintf("127.0.0.1:%s:2013:10:26:%d:%d",
			check, hour, sec)
		if sec%500 != 0 {
			continue
		}
		val := "up"
		if sec%1000 == 0 {
			val = "down"
		}
		abklevigoNS.PushNS(nukey, val, db)
	}
	fmt.Printf("Hour %d done. Enter 'yes' anytime to end Push action.\n", hour)
}
func setupTestData() {
	db = abkleveldb.CreateDB(test_dbpath)
	abkleveldb.PushKeyVal("upstate:2014:January:2:12:1:20", "down", db)
	abklevigoNS.PushNS("upstate:2014:January:2:12:1:20", "down", db)
	abklevigoNS.PushNS("upstate:2014:January:2:12:11:20", "up", db)
}
func PushKeyValNS(key string, val string) bool {
	return levigoNS.PushNS(key, val, db)
}