示例#1
0
文件: db.go 项目: darkseed/gocountme
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
}
示例#2
0
文件: db.go 项目: darkseed/gocountme
func (gr GetRequest) Execute(database *levigo.DB, ro *levigo.ReadOptions, wo *levigo.WriteOptions) (*kminvalues.KMinValues, error) {
	if gr.Key == "" {
		return nil, NoKeySpecified
	}

	data, err := database.Get(ro, []byte(gr.Key))
	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
		}
	}
	return kmv, err
}