예제 #1
0
func main() {
	in := "   fauns         sakjdkl  sakd "
	out := util.TrimSpace(in)
	fmt.Println(out)
	mydb := db.NewMyDB()

	mapobj := object.NewMapObj()
	errs := mapobj.Set(" z , zzz , r, rrr,c,mmm ")
	if errs != nil {
		panic(errs)
	}
	mydb.SetValue("zrc", mapobj)

	strobj := object.NewStringObj()
	strobj.Set("make you feel my love!")
	mydb.SetValue("qiqi", strobj)

	listobj := object.NewListObj()
	listobj.Set("all,out,of,love")
	listobj.Sort()
	mydb.SetValue("shanghai", listobj)

	value1, err := mydb.GetValue("zrc")
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(value1.String())
		fmt.Println(value1.(*object.MapObj).GetElem("c"))
	}

	value2, err := mydb.GetValue("qiqi")
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(value2.String())

	}
	mydb.DelKey("shanghai")
	value3, err := mydb.GetValue("shanghai")
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(value3.String())
		fmt.Println(value3.(*object.ListObj).Vals(4))
	}

	return
}
예제 #2
0
func Clist(conn *Connection) {
	fmt.Println("Clist")
	conn.DB.Lock()
	value, err := conn.DB.GetValue(conn.ReqData.Key)
	if err == nil {
		if reflect.TypeOf(value).String() != "*object.ListObj" {
			conn.RespData = conn.ReqData.Key + " is not a list key"
			conn.DB.Unlock()
			return
		}
	}
	listobj := object.NewListObj()
	listobj.Set(conn.ReqData.Data)
	ret := conn.DB.SetValue(conn.ReqData.Key, listobj)
	conn.DB.Unlock()
	switch ret {
	case db.UPDATE:
		conn.RespData = conn.ReqData.Command + " Update " + conn.ReqData.Key
	case db.CREATE:
		conn.RespData = conn.ReqData.Command + " Create " + conn.ReqData.Key
	}
}