// Increment a bin, being used as a sequence generator. func nextSeq(seq string) (int, error) { keyId := fmt.Sprintf("%s:%s", SEQUENCES, seq) key, err := as.NewKey(NAMESPACE, SEQUENCES, keyId) if err != nil { return 0, err } rec, err := db.Operate( writePolicy, key, as.AddOp(as.NewBin("seq", 1)), as.GetOpForBin("seq"), ) if err != nil { return 0, err } if seq, exists := rec.Bins["seq"]; !exists || int(seq.(int)) <= 0 { return 0, fmt.Errorf("sequence not found: %s", seq) } return rec.Bins["seq"].(int), nil }
// NewServiceCodeVersion generates a version number of the code and returns it. func NewServiceCodeVersion( as *aerospike.Client, env string, service string) ( newVersion int64, err error) { key, err := serviceKey(env, service) if err != nil { return 0, err } bin := aerospike.NewBin("NextVer", 1) record, err := as.Operate( nil, key, aerospike.AddOp(bin), aerospike.GetOpForBin("NextVer")) if err != nil { return 0, err } return int64(record.Bins["NextVer"].(int)), nil }