Unable to set expiry time in codecrafter tester

I’m stuck on Stage #YZ1.

I’ve tried … (mention what you’ve tried so far).
I create a tester of my own in golang and tried to test if this is working or not it is working well and the i am able to set the Expiry time also but when codecrafter tester is setting the key the expiry time is becoming 0

Here are my logs:

[Uploading: image.png…]

In the logs you can observe the expiry time is being set to 0000 and the expiry time is not being added
And here’s a snippet of my code:

func executeSet(output *Command, s *Store) ([]byte, error) {
	s.mu.Lock()

	defer s.mu.Unlock()
	log.Println(output)
	if len(output.Args) < 2 {
		return nil, fmt.Errorf("either the key or value is missing")
	}
	key := output.Args[0]

	value := output.Args[1]
	record := &Record{
		value:     value,
		createdAt: time.Now(),
	}
	log.Println(output.Args)

	if len(output.Args) == 4 && output.Args[2] == "PX" {
		expiration, err := strconv.Atoi(output.Args[3])

		if err != nil {

			fmt.Println(err)

			return nil, fmt.Errorf("-ERR wrong expiration time provided for the record")

		}

		record.expiryAt = time.Now().Add(time.Duration(expiration) * time.Millisecond) // Converting milliseconds to seconds
	}
	s.kv[key] = record

	log.Println("Expiry time",s.kv[key].expiryAt)

	return respOK, nil
}

func executeGet(output *Command, s *Store) ([]byte, error) {
	// s.mu.RLock()
	// defer s.mu.RUnlock()
	if len(output.Args) < 1 {
		return nil, fmt.Errorf("Key is missing")
	}

	key := output.Args[0]
	val, ok := s.kv[key]
	if ok {
		if val.expiryAt.IsZero() || val.expiryAt.After(time.Now()) {
			return respString(val.value), nil
		}
		// If expired, delete the key and return null
		delete(s.kv, key)
		return respNull, nil
	} else {
		return respNull, nil
	}

}

Hi @tarun-kavipurapu, it looks like your logs didn’t upload successfully. :sweat_smile:

Could you also upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

Continuing the discussion from Unable to set expiry time in codecrafter tester:

https://github.com/tarun-kavipurapu/tarun-kavipurapu-codecrafters-redis-go

Entire code is uploaded here

Thanks for sharing your repo! It would be helpful if you could also re-upload the logs.

I’ll take a look at your code and try to get back to you by the end of the week.

@tarun-kavipurapu, it seems that the issue stems from a mismatch between upper and lower case letters.

You can update the logic in your code to be case insensitive.

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.