Exemplo n.º 1
0
func (s *testStoreSuite) xrestore(c *C, db uint32, key string, ttlms uint64, value string) {
	var x rdb.String = []byte(value)
	dump, err := rdb.EncodeDump(x)
	c.Assert(err, IsNil)

	err = s.s.Restore(db, FormatBytes(key, ttlms, dump))
	c.Assert(err, IsNil)

	s.xdump(c, db, key, value)
	if ttlms == 0 {
		s.kpttl(c, db, key, -1)
	} else {
		s.kpttl(c, db, key, int64(ttlms))
	}
}
Exemplo n.º 2
0
func (s *testStoreSuite) xslotsrestore(c *C, 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))))
			c.Assert(err, IsNil)

			x = append(x, dump)
		}
	}

	err := s.s.SlotsRestore(db, FormatBytes(x...))
	c.Assert(err, IsNil)
}
Exemplo n.º 3
0
func (s *testStoreSuite) srestore(c *C, db uint32, key string, ttlms int64, expect ...string) {
	var x rdb.Set
	for _, e := range expect {
		x = append(x, []byte(e))
	}
	dump, err := rdb.EncodeDump(x)
	c.Assert(err, IsNil)

	err = s.s.Restore(db, FormatBytes(key, ttlms, dump))
	c.Assert(err, IsNil)

	s.sdump(c, db, key, expect...)
	if ttlms == 0 {
		s.kpttl(c, db, key, -1)
	} else {
		s.kpttl(c, db, key, int64(ttlms))
	}
}
Exemplo n.º 4
0
func (s *testStoreSuite) hrestore(c *C, db uint32, key string, ttlms int64, expect ...string) {
	c.Assert(len(expect)%2, Equals, 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)
	c.Assert(err, IsNil)

	err = s.s.Restore(db, FormatBytes(key, ttlms, dump))
	c.Assert(err, IsNil)

	s.hdump(c, db, key, expect...)
	if ttlms == 0 {
		s.kpttl(c, db, key, -1)
	} else {
		s.kpttl(c, db, key, int64(ttlms))
	}
}
Exemplo n.º 5
0
func (s *testStoreSuite) zrestore(c *C, db uint32, key string, ttlms int64, expect ...interface{}) {
	c.Assert(len(expect)%2, Equals, 0)

	var x rdb.ZSet
	for i := 0; i < len(expect); i += 2 {
		score, err := ParseFloat(expect[i+1])
		c.Assert(err, IsNil)
		x = append(x, &rdb.ZSetElement{Member: []byte(fmt.Sprint(expect[i])), Score: float64(score)})
	}

	dump, err := rdb.EncodeDump(x)
	c.Assert(err, IsNil)

	err = s.s.Restore(db, FormatBytes(key, ttlms, dump))
	c.Assert(err, IsNil)

	s.zdump(c, db, key, expect...)
	if ttlms == 0 {
		s.kpttl(c, db, key, -1)
	} else {
		s.kpttl(c, db, key, int64(ttlms))
	}
}