func TestBgSave(t *testing.T) { //连接mongodb client, err := cluster.NewCluster(DEFAULT_REDIS_HOST) if err != nil { t.Fatal(err) } //序列化数据 bin, _ := msgpack.Marshal(&TestStruct{3721, "hello", 18, 999, 1.1, 2.2, []byte("world")}) //压缩 if env := os.Getenv(ENV_SNAPPY); env != "" { if enc, err := snappy.Encode(nil, bin); err == nil { bin = enc } else { t.Fatal(err) } } //存入 reply := client.Cmd("set", test_key, bin) if reply.Err != nil { t.Fatal(err) } //调用bg save conn, err := grpc.Dial(address) if err != nil { t.Fatalf("did not connect: %v", err) } defer conn.Close() c := pb.NewBgSaveServiceClient(conn) //传入需要落地的key _, err = c.MarkDirty(context.Background(), &pb.BgSave_Key{Name: test_key}) if err != nil { t.Fatalf("could not query: %v", err) } }
func TestBgSave(t *testing.T) { //t.Skip() // start connection to redis cluster client, err := cluster.NewCluster(DEFAULT_REDIS_HOST) if err != nil { t.Fatal(err) } // mset data into redis bin, _ := msgpack.Marshal(&TestStruct{3721, "hello", 18, 999, 1.1, 2.2, []byte("world")}) // snappy if env := os.Getenv(ENV_SNAPPY); env != "" { if enc, err := snappy.Encode(nil, bin); err == nil { bin = enc } else { t.Fatal(err) } } reply := client.Cmd("set", test_key, bin) if reply.Err != nil { t.Fatal(reply.Err) } // Set up a connection to the server. conn, err := grpc.Dial(address) if err != nil { t.Fatalf("did not connect: %v", err) } defer conn.Close() c := pb.NewBgSaveServiceClient(conn) // Contact the server and print out its response. _, err = c.MarkDirty(context.Background(), &pb.BgSave_Key{Name: test_key}) if err != nil { t.Fatalf("could not query: %v", err) } }