• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang aerospike-client-go.NewWritePolicy函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: connectToDatabase

// Connect to the database, and initial setup
func connectToDatabase(host string, port int) {
	var err error

	// connect to the db
	if db, err = as.NewClient(host, port); err != nil {
		panic(err)
	}

	readPolicy = as.NewPolicy()
	writePolicy = as.NewWritePolicy(0, 0)
	scanPolicy = as.NewScanPolicy()

	// index on offer_id of bids, so we can find bids on a given offer
	if _, err := db.CreateIndex(writePolicy, "test", BIDS, "idx:br:1", "offer_id", as.NUMERIC); err != nil {
		fmt.Printf("Create Index Failed: %s\n", err.Error())
	}

	// index on broker_id of bids, so we can find bids by a particular broker
	if _, err := db.CreateIndex(writePolicy, "test", BIDS, "idx:br:2", "broker_id", as.NUMERIC); err != nil {
		fmt.Printf("Create Index Failed: %s\n", err.Error())
	}

	// index on broker_id of offers, so we can find offers by a particular broker
	if _, err := db.CreateIndex(writePolicy, "test", OFFERS, "idx:br:3", "broker_id", as.NUMERIC); err != nil {
		fmt.Printf("Create Index Failed: %s\n", err.Error())
	}

	// index on ticker of prices
	if _, err := db.CreateIndex(writePolicy, "test", PRICES, "idx:br:4", "ticker", as.STRING); err != nil {
		fmt.Printf("Create Index Failed: %s\n", err.Error())
	}

}
开发者ID:investislife,项目名称:stock-exchange,代码行数:34,代码来源:db.go


示例2: main

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	// defer client.Close()
	client, err = as.NewClient("172.31.53.227", 3000)
	fmt.Println(client)
	panicOnError(err)

	writePolicy = as.NewWritePolicy(0, 0)
	ch = make(chan Event, 1)
	key, err := as.NewKey("test", "totals", "test")
	panicOnError(err)
	// define some bins with data
	bins := as.BinMap{
		"value": 100,
	}
	err = client.Put(nil, key, bins)
	panicOnError(err)

	time.AfterFunc(1*time.Second, func() {
		for i := 1; i < 24; i++ {
			fmt.Println("starting worker %d", i)
			go worker(ch)
		}
	})

	http.HandleFunc("/vote", voteHandler)
	http.HandleFunc("/loaderio-35df9c4fffde902e3b0e3e0115816d82.html", validationHandler)
	http.ListenAndServe(":80", nil)
}
开发者ID:altoplano,项目名称:real_time_vote_benchmark,代码行数:29,代码来源:aerospike.go


示例3: lockKey

func (c *client) lockKey(key *as.Key) error {
	writePolicy := as.NewWritePolicy(0, -1)
	writePolicy.RecordExistsAction = as.CREATE_ONLY

	lockBin := as.NewBin(binLockName, "true")

	return c.asClient.PutBins(writePolicy, key, lockBin)
}
开发者ID:vad4msiu,项目名称:cache,代码行数:8,代码来源:client.go


示例4: writeData

func (c *client) writeData(key *as.Key, result interface{}, expire time.Duration) {
	writePolicy := as.NewWritePolicy(0, int32(expire.Seconds()))

	value, err := json.Marshal(result)
	panicOnError(err)

	lockBin := as.NewBin(binLockName, nil)
	dataBin := as.NewBin(binDataName, string(value))

	err = c.asClient.PutBins(writePolicy, key, lockBin, dataBin)
	panicOnError(err)
}
开发者ID:vad4msiu,项目名称:cache,代码行数:12,代码来源:client.go


示例5: main

func main() {
	// flags
	host := flag.String("h", "127.0.0.1", "host")
	port := flag.Int("p", 3000, "port")
	del := flag.Bool("del", false, "delete?")
	flag.Parse()

	// connect to Aerospike
	if h, found := os.LookupEnv("AEROSPIKE_PORT_3000_TCP_ADDR"); found {
		*host = h
	}
	cl, err := asc.NewClient(*host, *port)
	panicOnErr(err)

	key, err := asc.NewKey("test", "aerospike", "key")
	panicOnErr(err)

	// define some bins with data
	bins := asc.BinMap{
		"bin1": 42,
		"bin2": "elephant",
		"bin3": []interface{}{"Go", 2009},
	}

	// write the bins
	wp := asc.NewWritePolicy(0, 0)
	wp.SendKey = true // also send the key itself
	err = cl.Put(wp, key, bins)
	panicOnErr(err)

	rec, err := cl.Get(nil, key)
	panicOnErr(err)

	_, _ = pp.Printf("key: %v\nbins: %v\n", *rec.Key, rec.Bins)

	// scan all data
	rs, err := cl.ScanAll(nil, "test", "aerospike")
	panicOnErr(err)
	defer rs.Close()

	for r := range rs.Results() {
		_, _ = pp.Println(*r.Record.Key, r.Record.Bins)
	}

	if *del {
		existed, err := cl.Delete(nil, key)
		panicOnErr(err)
		fmt.Printf("Record existed before delete? %v\n", existed)
	}
}
开发者ID:skatsuta,项目名称:aerospike-sample,代码行数:50,代码来源:main.go


示例6: runExample

func runExample(client *as.Client) {
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "touchkey")
	bin := as.NewBin("touchbin", "touchvalue")

	log.Printf("Create record with 2 second expiration.")
	writePolicy := as.NewWritePolicy(0, 2)
	client.PutBins(writePolicy, key, bin)

	log.Printf("Touch same record with 5 second expiration.")
	writePolicy.Expiration = 5
	record, err := client.Operate(writePolicy, key, as.TouchOp(), as.GetHeaderOp())

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

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

	log.Printf("Sleep 3 seconds.")
	time.Sleep(3 * time.Second)

	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())
	}

	log.Printf("Success. Record still exists.")
	log.Printf("Sleep 4 seconds.")
	time.Sleep(4 * time.Second)

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

	if record == nil {
		log.Printf("Success. Record expired as expected.")
	} else {
		log.Fatalf("Found record when it should have expired.")
	}
}
开发者ID:mantyr,项目名称:aerospike-client-go,代码行数:49,代码来源:touch.go


示例7: noExpireExample

/**
 * Write and twice read a non-expiring tuple using the new "NoExpire" value (-1).
 * This example is most effective when the Default Namespace Time To Live (TTL)
 * is set to a small value, such as 5 seconds.  When we sleep beyond that
 * time, we show that the NoExpire TTL flag actually works.
 */
func noExpireExample(client *as.Client) {
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "expirekey")
	bin := as.NewBin("expirebin", "noexpirevalue")

	log.Printf("Put: namespace=%s set=%s key=%s bin=%s value=%s expiration=NoExpire",
		key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value)

	// Specify that record NEVER expires.
	// The "Never Expire" value is -1, or 0xFFFFFFFF.
	writePolicy := as.NewWritePolicy(0, 2)
	writePolicy.Expiration = math.MaxUint32
	client.PutBins(writePolicy, key, bin)

	// Read the record, showing it is there.
	log.Printf("Get: namespace=%s set=%s key=%s",
		key.Namespace(), key.SetName(), key.Value())

	record, err := client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)
	if record == nil {
		log.Fatalf(
			"Failed to get record: namespace=%s set=%s key=%s",
			key.Namespace(), key.SetName(), key.Value())
	}

	received := record.Bins[bin.Name]
	expected := bin.Value.String()
	if received == expected {
		log.Printf("Get record successful: namespace=%s set=%s key=%s bin=%s value=%s",
			key.Namespace(), key.SetName(), key.Value(), bin.Name, received)
	} else {
		log.Fatalf("Expire record mismatch: Expected %s. Received %s.",
			expected, received)
	}

	// Read this Record after the Default Expiration, showing it is still there.
	// We should have set the Namespace TTL at 5 sec.
	log.Printf("Sleeping for 10 seconds ...")
	time.Sleep(10 * time.Second)
	record, err = client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)

	if record == nil {
		log.Fatalf("Record expired and should NOT have.")
	} else {
		log.Printf("Found Record (correctly) after default TTL.")
	}
}
开发者ID:mantyr,项目名称:aerospike-client-go,代码行数:54,代码来源:expire.go


示例8: putEntry

// putEntry store data to cache
func (as *AeroSpikeClient) putEntry(key *AeroSpikeKey, data IEntryData, ttl time.Duration) {

	aKey, _ := as.createKey(key)

	policy := aerospike.NewWritePolicy(0, int32(ttl.Seconds()))
	policy.MaxRetries = maxRetries

	bins := data.Export()
	bins["tags"] = key.Tags
	bins["id"] = key.Pk

	if err := as.client.Put(policy, aKey, bins); err != nil {
		log.Printf("PutExternal error: %s", err)
	}

	return
}
开发者ID:iostrovok,项目名称:aerospike_etcd_cache,代码行数:18,代码来源:aero_client.go


示例9: expireExample

/**
 * Write and twice read an expiration record.
 */
func expireExample(client *as.Client) {
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "expirekey ")
	bin := as.NewBin("expirebin", "expirevalue")

	log.Printf("Put: namespace=%s set=%s key=%s bin=%s value=%s expiration=2",
		key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value)

	// Specify that record expires 2 seconds after it's written.
	writePolicy := as.NewWritePolicy(0, 2)
	client.PutBins(writePolicy, key, bin)

	// Read the record before it expires, showing it is there.
	log.Printf("Get: namespace=%s set=%s key=%s",
		key.Namespace(), key.SetName(), key.Value())

	record, err := client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)
	if record == nil {
		log.Fatalf(
			"Failed to get record: namespace=%s set=%s key=%s",
			key.Namespace(), key.SetName(), key.Value())
	}

	received := record.Bins[bin.Name]
	expected := bin.Value.String()
	if received == expected {
		log.Printf("Get record successful: namespace=%s set=%s key=%s bin=%s value=%s",
			key.Namespace(), key.SetName(), key.Value(), bin.Name, received)
	} else {
		log.Fatalf("Expire record mismatch: Expected %s. Received %s.",
			expected, received)
	}

	// Read the record after it expires, showing it's gone.
	log.Printf("Sleeping for 3 seconds ...")
	time.Sleep(3 * time.Second)
	record, err = client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)
	if record == nil {
		log.Printf("Expiry of record successful. Record not found.")
	} else {
		log.Fatalf("Found record when it should have expired.")
	}
}
开发者ID:mantyr,项目名称:aerospike-client-go,代码行数:47,代码来源:expire.go


示例10: runReplaceExample

func runReplaceExample(client *as.Client) {
	key, err := as.NewKey(*shared.Namespace, *shared.Set, "replacekey")
	shared.PanicOnError(err)
	bin1 := as.NewBin("bin1", "value1")
	bin2 := as.NewBin("bin2", "value2")
	bin3 := as.NewBin("bin3", "value3")

	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)

	log.Printf("Replace with: namespace=%s set=%s key=%s bin=%s value=%s",
		key.Namespace(), key.SetName(), key.Value(), bin3.Name, bin3.Value)

	wpolicy := as.NewWritePolicy(0, 0)
	wpolicy.RecordExistsAction = as.REPLACE
	client.PutBins(wpolicy, key, bin3)

	log.Printf("Get: namespace=%s set=%s key=%s", key.Namespace(), key.SetName(), key.Value())

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

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

	if record.Bins[bin1.Name] == nil {
		log.Printf(bin1.Name + " was deleted as expected.")
	} else {
		log.Fatalln(bin1.Name + " found when it should have been deleted.")
	}

	if record.Bins[bin2.Name] == nil {
		log.Printf(bin2.Name + " was deleted as expected.")
	} else {
		log.Fatalln(bin2.Name + " found when it should have been deleted.")
	}
	shared.ValidateBin(key, bin3, record)
}
开发者ID:atomx,项目名称:aerospike-client-go,代码行数:42,代码来源:replace.go


示例11: runReplaceOnlyExample

func runReplaceOnlyExample(client *as.Client) {
	key, err := as.NewKey(*shared.Namespace, *shared.Set, "replaceonlykey")
	shared.PanicOnError(err)
	bin := as.NewBin("bin", "value")

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

	log.Printf("Replace record requiring that it exists: namespace=%s set=%s key=%s",
		key.Namespace(), key.SetName(), key.Value())

	wpolicy := as.NewWritePolicy(0, 0)
	wpolicy.RecordExistsAction = as.REPLACE_ONLY
	err = client.PutBins(wpolicy, key, bin)
	if ae, ok := err.(ast.AerospikeError); ok && ae.ResultCode() == ast.KEY_NOT_FOUND_ERROR {
		log.Printf("Success. `Not found` error returned as expected.")
	} else {
		log.Fatalln("Failure. This command should have resulted in an error.")
	}
}
开发者ID:shatil,项目名称:aerospike-client-go,代码行数:20,代码来源:replace.go


示例12: runExample

func runExample(client *as.Client) {
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "genkey")
	binName := "genbin"

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

	// Set some values for the same record.
	bin := as.NewBin(binName, "genvalue1")
	log.Printf("Put: namespace=%s set=%s key=%s bin=%s value=%s",
		key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value)

	client.PutBins(shared.WritePolicy, key, bin)

	bin = as.NewBin(binName, "genvalue2")
	log.Printf("Put: namespace=%s set=%s key=%s bin=%s value=%s",
		key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value)

	client.PutBins(shared.WritePolicy, key, bin)

	// Retrieve record and its generation count.
	record, err := client.Get(shared.Policy, key, bin.Name)

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

	received := record.Bins[bin.Name]
	expected := bin.Value.String()

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

	// Set record and fail if it's not the expected generation.
	bin = as.NewBin(binName, "genvalue3")
	log.Printf("Put: namespace=%s set=%s key=%s bin=%s value=%s expected generation=%d",
		key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value, record.Generation)

	writePolicy := as.NewWritePolicy(0, 2)
	writePolicy.GenerationPolicy = as.EXPECT_GEN_EQUAL
	writePolicy.Generation = int32(record.Generation)
	client.PutBins(writePolicy, key, bin)

	// Set record with invalid generation and check results .
	bin = as.NewBin(binName, "genvalue4")
	writePolicy.Generation = 9999
	log.Printf("Put: namespace=%s set=%s key=%s bin=%s value=%s expected generation=%d",
		key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value, writePolicy.Generation)

	err = client.PutBins(writePolicy, key, bin)
	if err != nil {
		if ae, ok := err.(ast.AerospikeError); ok && ae.ResultCode() == ast.GENERATION_ERROR {
			shared.PanicOnError(errors.New("Should have received generation error instead of success."))
		}
		log.Printf("Success: Generation error returned as expected.")
	} else {
		log.Fatalf(
			"Unexpected set return code: namespace=%s set=%s key=%s bin=%s value=%s code=%s",
			key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value, err)
	}

	// Verify results.
	record, err = client.Get(shared.Policy, key, bin.Name)

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

	received = record.Bins[bin.Name]
	expected = "genvalue3"

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


示例13: ValidateBin

package shared

import (
	"bytes"
	"flag"
	"fmt"
	"log"
	"math"
	"os"
	"runtime"

	as "github.com/aerospike/aerospike-client-go"
)

var WritePolicy = as.NewWritePolicy(0, 0)
var Policy = as.NewPolicy()

var Host = flag.String("h", "127.0.0.1", "Aerospike server seed hostnames or IP addresses")
var Port = flag.Int("p", 3000, "Aerospike server seed hostname or IP address port number.")
var Namespace = flag.String("n", "test", "Aerospike namespace.")
var Set = flag.String("s", "testset", "Aerospike set name.")
var showUsage = flag.Bool("u", false, "Show usage information.")
var Client *as.Client

func ValidateBin(key *as.Key, bin *as.Bin, record *as.Record) {
	if !bytes.Equal(record.Key.Digest(), key.Digest()) {
		log.Fatalln(fmt.Sprintf("key `%s` is not the same as key `%s`.", key, record.Key))
	}

	if record.Bins[bin.Name] != bin.Value.GetObject() {
开发者ID:shatil,项目名称:aerospike-client-go,代码行数:30,代码来源:shared.go


示例14: NewDB

func NewDB(host string, port int, namespace string) *DB {
	return &DB{host, port, namespace, "", as.NewWritePolicy(0, 0), as.NewPolicy(), nil}
}
开发者ID:nslaughter,项目名称:goks,代码行数:3,代码来源:aerospikekv.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang aerospike-client-go.Client类代码示例发布时间:2022-05-24
下一篇:
Golang aerospike-client-go.NewKey函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap