github.com/hdt3213/godis@v1.2.9/database/cluster_helper_test.go (about) 1 package database 2 3 import ( 4 "fmt" 5 "github.com/hdt3213/godis/lib/utils" 6 "github.com/hdt3213/godis/redis/protocol" 7 "github.com/hdt3213/godis/redis/protocol/asserts" 8 "testing" 9 ) 10 11 func TestExistIn(t *testing.T) { 12 testDB.Flush() 13 key := utils.RandString(10) 14 value := utils.RandString(10) 15 key2 := utils.RandString(10) 16 testDB.Exec(nil, utils.ToCmdLine("set", key, value)) 17 result := testDB.Exec(nil, utils.ToCmdLine("ExistIn", key, key2)) 18 asserts.AssertMultiBulkReply(t, result, []string{key}) 19 key3 := utils.RandString(10) 20 result = testDB.Exec(nil, utils.ToCmdLine("ExistIn", key2, key3)) 21 asserts.AssertMultiBulkReplySize(t, result, 0) 22 } 23 24 func TestDumpKeyAndRenameTo(t *testing.T) { 25 testDB.Flush() 26 key := utils.RandString(10) 27 value := utils.RandString(10) 28 newKey := key + utils.RandString(2) 29 testDB.Exec(nil, utils.ToCmdLine("set", key, value, "ex", "1000")) 30 31 result := testDB.Exec(nil, utils.ToCmdLine("DumpKey", key)) 32 if protocol.IsErrorReply(result) { 33 t.Error("dump key error") 34 return 35 } 36 dumpResult := result.(*protocol.MultiBulkReply) 37 result = testDB.Exec(nil, utils.ToCmdLine("RenameTo", newKey, 38 string(dumpResult.Args[0]), string(dumpResult.Args[1]))) 39 asserts.AssertNotError(t, result) 40 result = testDB.Exec(nil, utils.ToCmdLine("RenameFrom", key)) 41 asserts.AssertNotError(t, result) 42 43 result = testDB.Exec(nil, utils.ToCmdLine("exists", key)) 44 asserts.AssertIntReply(t, result, 0) 45 result = testDB.Exec(nil, utils.ToCmdLine("exists", newKey)) 46 asserts.AssertIntReply(t, result, 1) 47 // check ttl 48 result = testDB.Exec(nil, utils.ToCmdLine("ttl", newKey)) 49 intResult, ok := result.(*protocol.IntReply) 50 if !ok { 51 t.Error(fmt.Sprintf("expected int protocol, actually %s", result.ToBytes())) 52 return 53 } 54 if intResult.Code <= 0 { 55 t.Errorf("expected ttl more than 0, actual: %d", intResult.Code) 56 return 57 } 58 }