Example #1
0
func xrestore(t *testing.T, db uint32, key string, ttlms uint64, value string) {
	var x rdb.String = []byte(value)
	dump, err := rdb.EncodeDump(x)
	checkerror(t, err, true)
	err = testbl.Restore(db, key, ttlms, dump)
	checkerror(t, err, true)
	xdump(t, db, key, value)
	if ttlms == 0 {
		kpttl(t, db, key, -1)
	} else {
		kpttl(t, db, key, int64(ttlms))
	}
}
Example #2
0
func xslotsrestore(t *testing.T, db uint32, args ...interface{}) {
	x := []interface{}{}
	for i, a := range args {
		switch i % 3 {
		case 0, 1:
			x = append(x, a)
		case 2:
			dump, err := rdb.EncodeDump(rdb.String([]byte(a.(string))))
			checkerror(t, err, true)
			x = append(x, dump)
		}
	}
	err := testbl.SlotsRestore(db, x...)
	checkerror(t, err, true)
}
Example #3
0
func srestore(t *testing.T, db uint32, key string, ttlms int64, expect ...string) {
	var x rdb.Set
	for _, s := range expect {
		x = append(x, []byte(s))
	}
	dump, err := rdb.EncodeDump(x)
	checkerror(t, err, true)
	err = testbl.Restore(db, key, ttlms, dump)
	checkerror(t, err, true)
	sdump(t, db, key, expect...)
	if ttlms == 0 {
		kpttl(t, db, key, -1)
	} else {
		kpttl(t, db, key, int64(ttlms))
	}
}
Example #4
0
func hrestore(t *testing.T, db uint32, key string, ttlms int64, expect ...string) {
	checkerror(t, nil, len(expect)%2 == 0)
	var x rdb.Hash
	for i := 0; i < len(expect); i += 2 {
		x = append(x, &rdb.HashElement{Field: []byte(expect[i]), Value: []byte(expect[i+1])})
	}
	dump, err := rdb.EncodeDump(x)
	checkerror(t, err, true)
	err = testbl.Restore(db, key, ttlms, dump)
	checkerror(t, err, true)
	hdump(t, db, key, expect...)
	if ttlms == 0 {
		kpttl(t, db, key, -1)
	} else {
		kpttl(t, db, key, int64(ttlms))
	}
}
Example #5
0
// DUMP key
func (h *Handler) Dump(arg0 interface{}, args [][]byte) (redis.Resp, error) {
	if len(args) != 1 {
		return toRespErrorf("len(args) = %d, expect = 1", len(args))
	}

	s, err := session(arg0, args)
	if err != nil {
		return toRespError(err)
	}

	if x, err := s.Rpdb().Dump(s.DB(), iconvert(args)...); err != nil {
		return toRespError(err)
	} else if dump, err := rdb.EncodeDump(x); err != nil {
		return toRespError(err)
	} else {
		return redis.NewBulkBytes(dump), nil
	}
}
Example #6
0
func zrestore(t *testing.T, db uint32, key string, ttlms int64, expect ...interface{}) {
	var x rdb.ZSet
	checkerror(t, nil, len(expect)%2 == 0)
	for i := 0; i < len(expect); i += 2 {
		score, err := ParseFloat(expect[i+1])
		checkerror(t, err, true)
		x = append(x, &rdb.ZSetElement{Member: []byte(fmt.Sprint(expect[i])), Score: score})
	}
	dump, err := rdb.EncodeDump(x)
	checkerror(t, err, true)
	err = testbl.Restore(db, key, ttlms, dump)
	checkerror(t, err, true)
	zdump(t, db, key, expect...)
	if ttlms == 0 {
		kpttl(t, db, key, -1)
	} else {
		kpttl(t, db, key, int64(ttlms))
	}
}