當前位置: 首頁>>代碼示例>>Golang>>正文


Golang DB.Put方法代碼示例

本文整理匯總了Golang中github.com/jmhodges/levigo.DB.Put方法的典型用法代碼示例。如果您正苦於以下問題:Golang DB.Put方法的具體用法?Golang DB.Put怎麽用?Golang DB.Put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/jmhodges/levigo.DB的用法示例。


在下文中一共展示了DB.Put方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Execute

func (ahr AddHashRequest) Execute(database *levigo.DB, ro *levigo.ReadOptions, wo *levigo.WriteOptions) (*kminvalues.KMinValues, error) {
	if ahr.Key == "" {
		return nil, NoKeySpecified
	}

	keyBytes := []byte(ahr.Key)

	data, err := database.Get(ro, keyBytes)
	if err != nil {
		return nil, err
	}

	kmv, err := kminvalues.KMinValuesFromBytes(data)
	if err != nil {
		if len(data) == 0 {
			kmv = kminvalues.NewKMinValues(*defaultSize)
		} else {
			return nil, err
		}
	}
	kmv.AddHash(ahr.Hash)

	err = database.Put(wo, keyBytes, kmv.Bytes())
	return kmv, err
}
開發者ID:darkseed,項目名稱:gocountme,代碼行數:25,代碼來源:db.go

示例2: AddProc

func AddProc(procID int, db *levigo.DB) error {
	ro := levigo.NewReadOptions()
	wo := levigo.NewWriteOptions()

	data, err := db.Get(ro, []byte("procs"))
	spdata := bytes.Split(data, []byte(":"))

	for i, e := range spdata {

		if string(e) != "" {
			fmt.Println("ProcID: #", i, string(e))
			pid, err := strconv.Atoi(string(e))
			if err != nil {
				return err
			}
			if pid == procID {
				return errors.New("Process already exists")
			}
			if isProcAlive(pid) == false {
				removeProc(pid, db)
			}
		}

		if err != nil {
			return err
		}
	}

	strdata := string(data)
	strdata = strdata + ":" + strconv.Itoa(procID)

	err = db.Put(wo, []byte("procs"), []byte(strdata))
	return err
}
開發者ID:jdpaton,項目名稱:Overseer,代碼行數:34,代碼來源:overseerdb.go

示例3: writeDataStoreVersion

// Write the datastore version to a shard.
func writeDataStoreVersion(store *dataStore, ldb *levigo.DB, v uint32) error {
	w := new(bytes.Buffer)
	encoder := gob.NewEncoder(w)
	err := encoder.Encode(&v)
	if err != nil {
		return err
	}
	return ldb.Put(store.writeOpts, []byte{VERSION_KEY}, w.Bytes())
}
開發者ID:clehene,項目名稱:incubator-htrace,代碼行數:10,代碼來源:datastore.go

示例4: Execute

func (sr SetRequest) Execute(database *levigo.DB, ro *levigo.ReadOptions, wo *levigo.WriteOptions) (*KMinValues, error) {
	if sr.Key == "" {
		return nil, NoKeySpecified
	}

	keyBytes := []byte(sr.Key)
	err := database.Put(wo, keyBytes, sr.Kmv.Bytes())

	return sr.Kmv, err
}
開發者ID:jehiah,項目名稱:gocountme,代碼行數:10,代碼來源:db.go

示例5: writePlaylistToDB

func writePlaylistToDB(db *levigo.DB, playlist []playListItem) {
	wo := levigo.NewWriteOptions()
	m := new(bytes.Buffer)
	enc := gob.NewEncoder(m)
	enc.Encode(playlist)

	err := db.Put(wo, []byte("playlist"), m.Bytes())
	if err != nil {
		log.Fatal(err)
	}
	wo.Close()
}
開發者ID:egelmex,項目名稱:hgd2,代碼行數:12,代碼來源:playlist.go

示例6: writeUsersToDB

func writeUsersToDB(db *levigo.DB, users map[string]User) {
	wo := levigo.NewWriteOptions()
	m := new(bytes.Buffer)
	enc := gob.NewEncoder(m)
	enc.Encode(users)

	err := db.Put(wo, []byte("Users"), m.Bytes())
	if err != nil {
		log.Fatal(err)
	}
	wo.Close()
}
開發者ID:egelmex,項目名稱:hgd2,代碼行數:12,代碼來源:usermanger.go

示例7: PushKeyVal

/*
PushKeyVal push KeyVal in provided DB handle.
*/
func PushKeyVal(key string, val string, db *levigo.DB) bool {
	writer := levigo.NewWriteOptions()
	defer writer.Close()

	keyname := []byte(key)
	value := []byte(val)
	err := db.Put(writer, keyname, value)
	if err != nil {
		golerror.Boohoo("Key "+key+" insertion failed. It's value was "+val, false)
		return false
	}
	return true
}
開發者ID:carriercomm,項目名稱:levigoNS,代碼行數:16,代碼來源:leveldb.go

示例8: write_data

func write_data(data []byte, db *levigo.DB, nitems int, keysize int, valsize int) {
	defer un(trace("write data"))
	wo := levigo.NewWriteOptions()
	keystart := 0
	valstart := 0
	for i := 0; i < nitems; i++ {
		db.Put(wo,
			data[keystart:keystart+keysize],
			data[valstart:valstart+valsize])
		keystart %= (len(data) - keysize)
		valstart %= (len(data) - valsize)
	}
	fmt.Println("Wrote ", nitems, "items with key size", keysize, "and value size", valsize)
}
開發者ID:salibrandi,項目名稱:mexos,代碼行數:14,代碼來源:levigo-ex.go

示例9: setProcStatus

func setProcStatus(db *levigo.DB, pid, status int) {
	wo := levigo.NewWriteOptions()
	key := "status:" + strconv.Itoa(pid)
	db.Put(wo, []byte(key), []byte(strconv.Itoa(status)))
}
開發者ID:jdpaton,項目名稱:Overseer,代碼行數:5,代碼來源:overseerdb.go


注:本文中的github.com/jmhodges/levigo.DB.Put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。