Example #1
0
func (z *zset) ReStore(name string) error {
	f, err := helper.LockFile(name, false)
	if err != nil {
		return err
	}
	tbl := make(map[string]float64, DEFAULT_TBL_LEN)
	buf := bufio.NewReader(f)
	decoder := json.NewDecoder(buf)
	decoder.Decode(&tbl)
	for k, v := range tbl {
		z.Add(v, k)
	}
	f.Close()
	return nil
}
Example #2
0
//use fork snapshot to save
func (z *zset) BgStore(name string) error {
	f, err := helper.LockFile(name, true)
	if err != nil {
		return err
	}
	pid, errno := helper.Fork()
	if errno != 0 {
		return errors.New("fork error," + errno.Error())
	}
	//child
	if pid == 0 {
		buf := bufio.NewWriter(f)
		encoder := json.NewEncoder(buf)
		encoder.Encode(z.tbl)
		buf.Flush()
		f.Close()
		os.Exit(0)
	}

	return nil

}