I’m stuck on Stage Command Processing #YG4
I’ve tried everything but unable to find a solution went through the code examples still not able to make it work please someone can help that will be great…
Here are my logs:
[tester::#YG4] [handshake] master: Sent bytes: "$88\r\nREDIS0011\xfa\tredis-ver\x057.2.0\xfa\nredis-bits\xc0@\xfa\x05ctime\xc2m\b\xbce\xfa\bused-mem°\xc4\x10\x00\xfa\baof-base\xc0\x00\xff\xf0n;\xfe\xc0\xffZ\xa2"
[tester::#YG4] [handshake] Sent RDB file.
[tester::#YG4] [propagation] master: > SET foo 123
[tester::#YG4] [propagation] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n"
[your_program] Starting Handle Connection on localhost 6379
[tester::#YG4] [propagation] master: > SET bar 456
[tester::#YG4] [propagation] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nbar\r\n$3\r\n456\r\n"
[tester::#YG4] [propagation] master: > SET baz 789
[tester::#YG4] [propagation] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nbaz\r\n$3\r\n789\r\n"
[tester::#YG4] [test] Getting key foo
[tester::#YG4] [test] client: $ redis-cli GET foo
[tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
[tester::#YG4] [test] client: Received bytes: "$-1\r\n"
[tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
[tester::#YG4] [test] Retrying... (1/5 attempts)
[tester::#YG4] [test] client: > GET foo
[tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
[your_program] Processing GET operation with following args [{Value:foo IsNull:false}]
[tester::#YG4] [test] client: Received bytes: "$-1\r\n"
[tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
[your_program] Processing GET operation with following args [{Value:foo IsNull:false}]
[tester::#YG4] [test] Retrying... (2/5 attempts)
[tester::#YG4] [test] client: > GET foo
[tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
[tester::#YG4] [test] client: Received bytes: "$-1\r\n"
[tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
[your_program] Processing GET operation with following args [{Value:foo IsNull:false}]
[tester::#YG4] [test] Retrying... (3/5 attempts)
[tester::#YG4] [test] client: > GET foo
[tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
[tester::#YG4] [test] client: Received bytes: "$-1\r\n"
[tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
[tester::#YG4] [test] Retrying... (4/5 attempts)
[tester::#YG4] [test] client: > GET foo
[tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
[your_program] Processing GET operation with following args [{Value:foo IsNull:false}]
[tester::#YG4] [test] client: Received bytes: "$-1\r\n"
[tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
[your_program] Processing GET operation with following args [{Value:foo IsNull:false}]
[tester::#YG4] [test] Retrying... (5/5 attempts)
[tester::#YG4] [test] client: > GET foo
[tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
[tester::#YG4] [test] client: Received bytes: "$-1\r\n"
[tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
[your_program] Processing GET operation with following args [{Value:foo IsNull:false}]
[tester::#YG4] Expected simple string or bulk string, got NIL
[tester::#YG4] Test failed
[tester::#YG4] Terminating program
[tester::#YG4] Program terminated successfully
And here’s a snippet of my code:
func SetCommand(args tools.Array) (string, error) {
_, expiryTime := "", time.Time{}
var err error
var message string
fmt.Println("Here For SET")
if len(args) != 2 && len(args) != 4 {
fmt.Println("\n Failed at length \n", len(args))
err = fmt.Errorf("Incorrect Input :: %v", args)
return message, err
}
key, okKey := args[0].(tools.BulkString)
value, okValue := args[1].(tools.BulkString)
if !okKey || !okValue {
fmt.Println("\n Failed at Key Val \n", len(args))
err = fmt.Errorf("Incorrect Input :: %v", args[0])
return message, err
}
now :=
time.Now()
SetStoreMux.Lock()
if len(args) == 4 {
typeEx, okTypeEx := args[2].(tools.BulkString)
exVal, okExVal := args[3].(tools.BulkString)
if !okTypeEx || !okExVal {
fmt.Println("\n Failed at Time \n", len(args))
err = fmt.Errorf("Incorrect Input :: %v %v", args[2], args[3])
return message, err
}
timeToExpire, convertErr := strconv.Atoi(exVal.Value)
if convertErr != nil {
err = fmt.Errorf("Incorrect Convert Time %v %v", args[2], args[3])
return message, err
}
var typeTime string = strings.ToUpper(typeEx.Value)
switch typeTime {
case "PX":
{
expiryTime = now.Add(time.Millisecond * time.Duration(timeToExpire))
}
case "EX":
{
expiryTime = now.Add(time.Second * time.Duration(timeToExpire))
}
}
}
SetStore[key.Value] = &DataStore{
value: value.Value,
expiry: expiryTime,
createOn: now,
}
SetStoreMux.Unlock()
message = tools.SimpleString("OK").Encode()
replicaConn := tools.GetReplicaConns()
if len(replicaConn) > 0 {
for _, conn := range replicaConn {
fmt.Println("Conn Details For Slave", conn)
serverhelpers.SendSetCommandToReplica(conn, key.Value, value.Value)
}
}
return message, err
}
type ServerConfig struct {
port int64
hostName string
id string
role string
replicas []net.Conn
}