Exemple #1
0
func testDumpRestore(c *goredis.PoolConn, dump string, key string, t *testing.T) {
	if data, err := goredis.Bytes(c.Do(dump, key)); err != nil {
		t.Fatal(err)
	} else if _, err := c.Do("restore", key, 0, data); err != nil {
		t.Fatal(err)
	}
}
Exemple #2
0
func migrateKey(c *client, conn *goredis.PoolConn, tp string, key []byte, timeout int64) error {
	if !c.app.migrateKeyLock(tp, key) {
		// other may also migrate this key, skip it
		return errKeyInMigrating
	}

	defer c.app.migrateKeyUnlock(tp, key)

	data, err := xdump(c.db, tp, key)
	if err != nil {
		return err
	} else if data == nil {
		return errNoKey
	}

	ttl, err := xttl(c.db, tp, key)
	if err != nil {
		return err
	}

	//timeout is milliseconds
	t := time.Duration(timeout) * time.Millisecond

	conn.SetReadDeadline(time.Now().Add(t))

	//ttl is second, but restore need millisecond
	if _, err = conn.Do("restore", key, ttl*1e3, data); err != nil {
		return err
	}

	if err = xdel(c.db, tp, key); err != nil {
		return err
	}

	return nil
}