当前位置: 首页>>代码示例>>Golang>>正文


Golang aerospike-client-go.Client类代码示例

本文整理汇总了Golang中github.com/aerospike/aerospike-client-go.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: batchReads

/**
 * Read records in one batch.
 */
func batchReads(
	client *as.Client,
	keyPrefix string,
	binName string,
	size int,
) {
	// Batch gets into one call.
	keys := make([]*as.Key, size)
	for i := 0; i < size; i++ {
		keys[i], _ = as.NewKey(*shared.Namespace, *shared.Set, keyPrefix+strconv.Itoa(i+1))
	}

	records, err := client.BatchGet(nil, keys, binName)
	shared.PanicOnError(err)

	for i := 0; i < len(records); i++ {
		key := keys[i]
		record := records[i]
		level := asl.ERR
		var value interface{}

		if record != nil {
			level = asl.INFO
			value = record.Bins[binName]
		}
		asl.Logger.LogAtLevel(level, "Record: ns=%s set=%s key=%s bin=%s value=%s",
			key.Namespace(), key.SetName(), key.Value(), binName, value)
	}

	if len(records) != size {
		log.Fatalf("Record size mismatch. Expected %d. Received %d.", size, len(records))
	}
}
开发者ID:Kavec,项目名称:aerospike-client-go,代码行数:36,代码来源:batch.go

示例2: EnvExists

// EnvExists returns true iff the env exists.
func EnvExists(as *aerospike.Client, env string) (exists bool, err error) {
	key, err := envKey(env)
	if err != nil {
		return false, err
	}
	return as.Exists(nil, key)
}
开发者ID:,项目名称:,代码行数:8,代码来源:

示例3: runExample

func runExample(client *as.Client) {
	// Write initial record.
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "opkey")
	bin1 := as.NewBin("optintbin", 7)
	bin2 := as.NewBin("optstringbin", "string value")
	log.Printf("Put: namespace=%s set=%s key=%s bin1=%s value1=%s bin2=%s value2=%s",
		key.Namespace(), key.SetName(), key.Value(), bin1.Name, bin1.Value, bin2.Name, bin2.Value)
	client.PutBins(shared.WritePolicy, key, bin1, bin2)

	// Add integer, write new string and read record.
	bin3 := as.NewBin(bin1.Name, 4)
	bin4 := as.NewBin(bin2.Name, "new string")
	log.Println("Add: ", bin3.Value)
	log.Println("Write: ", bin4.Value)
	log.Println("Read:")

	record, err := client.Operate(shared.WritePolicy, key, as.AddOp(bin3), as.PutOp(bin4), as.GetOp())
	shared.PanicOnError(err)

	if record == nil {
		log.Fatalf(
			"Failed to get: namespace=%s set=%s key=%s",
			key.Namespace(), key.SetName(), key.Value())
	}

	binExpected := as.NewBin(bin3.Name, 11)
	shared.ValidateBin(key, binExpected, record)
	shared.ValidateBin(key, bin4, record)
}
开发者ID:Kavec,项目名称:aerospike-client-go,代码行数:29,代码来源:operate.go

示例4: runExample

func runExample(client *as.Client) {
	log.Printf("Scan parallel: namespace=" + *shared.Namespace + " set=" + *shared.Set)
	recordCount := 0
	begin := time.Now()
	policy := as.NewScanPolicy()
	recordset, err := client.ScanAll(policy, *shared.Namespace, *shared.Set)
	shared.PanicOnError(err)

L:
	for {
		select {
		case rec := <-recordset.Records:
			if rec == nil {
				break L
			}
			recordCount++

			if (recordCount % 10000) == 0 {
				log.Println("Records ", recordCount)
			}
		case err := <-recordset.Errors:
			// if there was an error, stop
			shared.PanicOnError(err)
		}
	}

	end := time.Now()
	seconds := float64(end.Sub(begin)) / float64(time.Second)
	log.Println("Total records returned: ", recordCount)
	log.Println("Elapsed time: ", seconds, " seconds")
	performance := shared.Round(float64(recordCount)/float64(seconds), 0.5, 0)
	log.Println("Records/second: ", performance)
}
开发者ID:Kavec,项目名称:aerospike-client-go,代码行数:33,代码来源:scan_parallel.go

示例5: syncAppAsDv

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
}
开发者ID:xiaotiejiang888,项目名称:goPraticse,代码行数:26,代码来源:main.go

示例6: batchReadHeaders

/**
 * Read record header data in one batch.
 */
func batchReadHeaders(
	client *as.Client,
	keyPrefix string,
	size int,
) {
	// Batch gets into one call.
	keys := make([]*as.Key, size)
	for i := 0; i < size; i++ {
		keys[i], _ = as.NewKey(*shared.Namespace, *shared.Set, keyPrefix+strconv.Itoa(i+1))
	}

	records, err := client.BatchGetHeader(nil, keys)
	shared.PanicOnError(err)

	for i := 0; i < len(records); i++ {
		key := keys[i]
		record := records[i]
		level := asl.ERR
		generation := 0
		expiration := 0

		if record != nil && (record.Generation > 0 || record.Expiration > 0) {
			level = asl.INFO
			generation = record.Generation
			expiration = record.Expiration
		}
		asl.Logger.LogAtLevel(level, "Record: ns=%s set=%s key=%s generation=%d expiration=%d",
			key.Namespace(), key.SetName(), key.Value(), generation, expiration)
	}

	if len(records) != size {
		log.Fatalf("Record size mismatch. Expected %d. Received %d.", size, len(records))
	}
}
开发者ID:Kavec,项目名称:aerospike-client-go,代码行数:37,代码来源:batch.go

示例7: runExample

func runExample(client *as.Client) {
	log.Println("Scan series: namespace=", *shared.Namespace, " set=", *shared.Set)

	// Use low scan priority.  This will take more time, but it will reduce
	// the load on the server.
	policy := as.NewScanPolicy()
	policy.MaxRetries = 1
	policy.Priority = as.LOW

	nodeList := client.GetNodes()
	begin := time.Now()

	for _, node := range nodeList {
		log.Println("Scan node ", node.GetName())
		recordset, err := client.ScanNode(policy, node, *shared.Namespace, *shared.Set)
		shared.PanicOnError(err)

	L:
		for {
			select {
			case rec := <-recordset.Records:
				if rec == nil {
					break L
				}
				metrics, exists := setMap[rec.Key.SetName()]

				if !exists {
					metrics = Metrics{}
				}
				metrics.count++
				metrics.total++
				setMap[rec.Key.SetName()] = metrics

			case err := <-recordset.Errors:
				// if there was an error, stop
				shared.PanicOnError(err)
			}
		}

		for k, v := range setMap {
			log.Println("Node ", node, " set ", k, " count: ", v.count)
			v.count = 0
		}
	}

	end := time.Now()
	seconds := float64(end.Sub(begin)) / float64(time.Second)
	log.Println("Elapsed time: ", seconds, " seconds")

	total := 0

	for k, v := range setMap {
		log.Println("Total set ", k, " count: ", v.total)
		total += v.total
	}
	log.Println("Grand total: ", total)
	performance := shared.Round(float64(total)/seconds, 0.5, 0)
	log.Println("Records/second: ", performance)
}
开发者ID:Kavec,项目名称:aerospike-client-go,代码行数:59,代码来源:scan_serial.go

示例8: DeleteEnv

// DeleteEnv removes an env.
func DeleteEnv(as *aerospike.Client, env string) error {
	key, err := envKey(env)
	if err != nil {
		return err
	}
	_, err = as.Delete(nil, key)
	return err
}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例9: ServiceExists

// ServiceExists returns true iff the service exists.
func ServiceExists(
	as *aerospike.Client, env string, service string) (
	exists bool, err error) {
	key, err := serviceKey(env, service)
	if err != nil {
		return false, err
	}
	return as.Exists(nil, key)
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例10: NewEnv

// NewEnv stores a new env.
func NewEnv(as *aerospike.Client, env string, description string) error {
	key, err := envKey(env)
	if err != nil {
		return err
	}
	wp := aerospike.NewWritePolicy(0, 0)
	wp.RecordExistsAction = aerospike.CREATE_ONLY
	return as.PutObject(wp, key, &EnvData{Description: description})
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例11: SetServiceLiveCodeVersion

// SetServiceLiveCodeVersion sets the provided version of the code as the live
// one.
func SetServiceLiveCodeVersion(
	as *aerospike.Client, env string, service string, version int64) (
	err error) {
	key, err := serviceKey(env, service)
	if err != nil {
		return err
	}
	bin := aerospike.NewBin("LiveVer", version)
	return as.PutBins(nil, key, bin)
}
开发者ID:,项目名称:,代码行数:12,代码来源:

示例12: runExample

func runExample(client *as.Client) {
	key, err := as.NewKey(*shared.Namespace, *shared.Set, "addkey")
	shared.PanicOnError(err)

	binName := "addbin"

	// Delete record if it already exists.
	client.Delete(shared.WritePolicy, key)

	// Perform some adds and check results.
	bin := as.NewBin(binName, 10)
	log.Println("Initial add will create record.  Initial value is ", bin.Value, ".")
	client.AddBins(shared.WritePolicy, key, bin)

	bin = as.NewBin(binName, 5)
	log.Println("Add ", bin.Value, " to existing record.")
	client.AddBins(shared.WritePolicy, key, bin)

	record, err := client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)

	if record == nil {
		log.Fatalf(
			"Failed to get: namespace=%s set=%s key=%s",
			key.Namespace(), key.SetName(), key.Value())
	}

	// The value received from the server is an unsigned byte stream.
	// Convert to an integer before comparing with expected.
	received := record.Bins[bin.Name]
	expected := 15

	if received == expected {
		log.Printf("Add successful: ns=%s set=%s key=%s bin=%s value=%s",
			key.Namespace(), key.SetName(), key.Value(), bin.Name, received)
	} else {
		log.Fatalf("Add mismatch: Expected %d. Received %d.", expected, received)
	}

	// Demonstrate add and get combined.
	bin = as.NewBin(binName, 30)
	log.Println("Add ", bin.Value, " to existing record.")
	record, err = client.Operate(shared.WritePolicy, key, as.AddOp(bin), as.GetOp())
	shared.PanicOnError(err)

	expected = 45
	received = record.Bins[bin.Name]

	if received == expected {
		log.Printf("Add successful: ns=%s set=%s key=%s bin=%s value=%s",
			key.Namespace(), key.SetName(), key.Value(), bin.Name, received)
	} else {
		log.Fatalf("Add mismatch: Expected %d. Received %d.", expected, received)
	}
}
开发者ID:shatil,项目名称:aerospike-client-go,代码行数:55,代码来源:add.go

示例13: createIndex

func createIndex(c *driver.Client, ns, set string) error {
	task, err := c.CreateIndex(nil, ns, set, set, urlField, driver.STRING)
	if err != nil {
		if err.Error() == "Index already exists" {
			return nil
		}

		return err
	}

	return <-task.OnComplete()
}
开发者ID:src-d,项目名称:go-git,代码行数:12,代码来源:storage.go

示例14: InitServiceTable

// InitServiceTable initializes the indices for the service table.
func InitServiceTable(as *aerospike.Client) error {
	bin := "Env"
	task, err := as.CreateIndex(
		nil, leverOSNamespace, serviceSet, serviceSet+bin, bin,
		aerospike.STRING)
	if err != nil {
		return err
	}
	err, isErr := <-task.OnComplete()
	if isErr && err != nil {
		return err
	}
	return nil
}
开发者ID:,项目名称:,代码行数:15,代码来源:

示例15: UpdateService

// UpdateService updates the data associated with a service.
func UpdateService(
	as *aerospike.Client, env string, service string, description string,
	isPublic bool, liveCodeVersion int64) (
	err error) {
	key, err := serviceKey(env, service)
	if err != nil {
		return err
	}
	wp := aerospike.NewWritePolicy(0, 0)
	wp.RecordExistsAction = aerospike.UPDATE_ONLY
	return as.PutBins(
		wp, key,
		aerospike.NewBin("Desc", description),
		aerospike.NewBin("IsPub", btoi(isPublic)),
		aerospike.NewBin("LiveVer", liveCodeVersion),
	)
}
开发者ID:,项目名称:,代码行数:18,代码来源:


注:本文中的github.com/aerospike/aerospike-client-go.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。