Пример #1
0
func runExample(client *as.Client) {
	// Set LuaPath
	luaPath, _ := os.Getwd()
	luaPath += "/udf/"
	as.SetLuaPath(luaPath)

	filename := "sum_single_bin"
	regTask, err := client.RegisterUDFFromFile(nil, luaPath+filename+".lua", filename+".lua", as.LUA)
	shared.PanicOnError(err)

	// wait until UDF is created
	shared.PanicOnError(<-regTask.OnComplete())

	sum := 0
	for i := 1; i <= keyCount; i++ {
		sum += i
		key, err := as.NewKey(*shared.Namespace, *shared.Set, i)
		shared.PanicOnError(err)

		bin1 := as.NewBin("bin1", i)
		client.PutBins(nil, key, bin1)
	}

	t := time.Now()
	stm := as.NewStatement(*shared.Namespace, *shared.Set)
	res, err := client.QueryAggregate(nil, stm, filename, filename, "bin1")
	shared.PanicOnError(err)

	for rec := range res.Results() {
		log.Printf("Result %f should equal %d\n", rec.Record.Bins["SUCCESS"], sum)
	}
	log.Println("Map/Reduce took", time.Now().Sub(t))
}
Пример #2
0
func syncAppAsDv(ac *as.Client, pool *redis.Pool, app string) error {
	stm := as.NewStatement(NS_PUSH, SET_DV, "id", "tp", "mt")
	stm.Addfilter(as.NewEqualFilter("app", app))
	p := as.NewQueryPolicy()
	p.RecordQueueSize = 200000
	rs, err := ac.Query(p, stm)
	if err != nil {
		fmt.Println("error happen When we sync @app:", app, " @err:", err)
		return err
	}
	latch := utee.NewThrottle(10000)
	for res := range rs.Results() {
		if res.Err != nil {
			return res.Err
		}
		bins := res.Record.Bins
		id, ok := bins["id"].(string)
		if !ok {
			//			log.Println("warn, id is empty", bins)
			continue
		}
		latch.Acquire()
		go Deq(pool, latch, id)
	}
	return nil
}
Пример #3
0
func (s *Storage) IterEncodedObjects(t plumbing.ObjectType) (storer.EncodedObjectIter, error) {
	stmnt := driver.NewStatement(s.ns, t.String())
	err := stmnt.Addfilter(driver.NewEqualFilter(urlField, s.url))

	rs, err := s.client.Query(nil, stmnt)
	if err != nil {
		return nil, err
	}

	return &EncodedObjectIter{t, rs.Records}, nil
}
Пример #4
0
func login(res http.ResponseWriter, req *http.Request, _ httprouter.Params) {
	name := req.FormValue("username")
	p := req.FormValue("password")

	var u *user

	// statements are query statements
	// namespace, set/kind, ...fieldsWeWant
	// note: usernames must be unique; not checked in this example
	stmt := as.NewStatement("bar", "users", "Username", "Password", "ID")
	stmt.Addfilter(as.NewEqualFilter("Username", name))
	rs, err := client.Query(nil, stmt)
	if err != nil {
		http.Error(res, "Server Error", http.StatusInternalServerError)
		log.Printf("error querying: %s\n", err.Error())
		return
	}
	defer rs.Close()
	for res := range rs.Results() {
		if res.Err != nil {
			log.Printf("error querying specific data: %s\n", err.Error())
		} else {
			u = &user{
				Username: res.Record.Bins["Username"].(string),
				Password: res.Record.Bins["Password"].(string),
				ID:       res.Record.Bins["ID"].(string),
			}
			break
		}
	}

	if u == nil {
		log.Printf("error logging in, no such user: %s\n", name)
		http.Redirect(res, req, "/login?msg=No such user", http.StatusSeeOther)
		return
	}
	if bcrypt.CompareHashAndPassword([]byte(u.Password), []byte(p)) != nil {
		http.Redirect(res, req, "/login?msg=Incorrect password", http.StatusSeeOther)
		return
	}

	http.SetCookie(res, &http.Cookie{
		Name:  "login",
		Value: u.ID,
	})
	http.Redirect(res, req, "/", http.StatusSeeOther)
}
Пример #5
0
// List bids on an offer
func (command *Command) Bids(r *http.Request, offerId *int, bids *[]m.Bid) error {

	stmt := as.NewStatement(NAMESPACE, BIDS)
	stmt.Addfilter(as.NewEqualFilter("offer_id", *offerId))

	recordset, err := db.Query(nil, stmt)
	if err != nil {
		return err
	}

	for rec := range recordset.Records {
		*bids = append(*bids, m.Bid{
			Id:       int(rec.Bins["bid_id"].(int)),
			BrokerId: rec.Bins["broker_id"].(int),
			OfferId:  rec.Bins["offer_id"].(int),
			Price:    int(rec.Bins["price"].(int)),
		})
	}

	return nil
}
Пример #6
0
func (s *Storage) IterReferences() (storer.ReferenceIter, error) {
	stmnt := driver.NewStatement(s.ns, referencesSet)
	err := stmnt.Addfilter(driver.NewEqualFilter(urlField, s.url))
	if err != nil {
		return nil, err
	}

	rs, err := s.client.Query(nil, stmnt)
	if err != nil {
		return nil, err
	}

	var refs []*plumbing.Reference
	for r := range rs.Records {
		refs = append(refs, plumbing.NewReferenceFromStrings(
			r.Bins["name"].(string),
			r.Bins["target"].(string),
		))
	}

	return storer.NewReferenceSliceIter(refs), nil
}