# Hardly Stuck on Challange #YG$

**URL:** <https://forum.codecrafters.io/t/hardly-stuck-on-challange-yg/1208>\
**Category:** Challenges\
**Tags:** challenge:redis\
**Created:** [July 30, 2024, 7:58pm UTC](https://forum.codecrafters.io/t/hardly-stuck-on-challange-yg/1208 "2024-07-30T19:58:40Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![ProgMastermind](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/progmastermind/32/1089_2.png) [@ProgMastermind](https://forum.codecrafters.io/u/ProgMastermind)\
**Post date:** [August 1, 2024, 7:52pm UTC](https://forum.codecrafters.io/t/hardly-stuck-on-challange-yg/1208/21 "2024-08-01T19:52:32Z")

</div>

Actually , when i am trying to figure out stuff, i thought the rdb\_file is going to sent after handling of +FULLRESYNC by replica , but i am getting the rdb\_file along with it , for example:  
"+FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0\r\n$88\r\nREDIS001  
till now i am executing the receive\_rdb afte this psync\_response, now i have seen this is occuring i am parsing here itself  
the code i am using

#-----------------------------------------------------------------------  
case :gen\_tcp.recv(socket, 0, :infinity) do  
{:ok, data} →   
Logger.debug(“Received PSYNC response: #{inspect(data)}”)  
case parse\_psync\_response(data) do  
{:ok, repl\_id, offset, remaining\_data} →   
Logger.info(“PSYNC successful. Replication ID: #{repl\_id}, Offset: #{offset}, Remaining Data: #{remaining\_data}”)  
case parse\_data(remaining\_data, 0) do  
{:rdb\_complete, rdb\_data} →   
Logger.info(“Received complete RDB file of size #{byte\_size(rdb\_data)} bytes”)  
{:commands, commands} →   
Enum.each(commands, fn command →   
Logger.info(“Executing command: #{inspect(command)}”)  
execute\_set\_command(command)  
end)  
{:error, reason} →   
Logger.error(“Failed to receive RDB file: #{inspect(reason)}”)  
end  
case receive\_rdb\_file(socket) do  
{:ok, :rdb\_complete, rdb\_data} →   
process\_rdb\_data(rdb\_data)  
{:ok, :commands, commands} →   
Enum.each(commands, fn command →   
Logger.info(“Executing command: #{inspect(command)}”)  
execute\_set\_command(command)  
end)  
{:error, reason} →   
Logger.error(“Failed to receive RDB file: #{inspect(reason)}”)  
end  
:ok  
{:error, reason} →   
Logger.warning(“Error parsing PSYNC response: #{reason}”)  
{:error, reason}  
end

#----------------------------------------------------------------------  
but sometimes, when i am not getting that extra data along with response, means when i am getting response like this  
+FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0\r\n  
i may think to execute receive\_data function

#-----------------------------------------------------  
defp receive\_data(socket, buffer, expected\_length) do  
Logger.debug(“Receiving data. Buffer size: #{byte\_size(buffer)}, Expected length: #{expected\_length}”)  
case :gen\_tcp.recv(socket, 0, 5000) do  
{:ok, data} →   
Logger.debug(“Received raw bytes: #{inspect(data, limit: :infinity, binaries: :as\_binaries)}”)  
Logger.debug(“Received chunk of size: #{byte\_size(data)} bytes”)  
Logger.debug(“Received data (as string): #{inspect(data, charlists: :as\_lists)}”)  
new\_buffer = buffer \<\> data  
Logger.debug(“New buffer size: #{byte\_size(new\_buffer)} bytes”)  
case parse\_data(new\_buffer, expected\_length) do  
{:continue, remaining, new\_expected\_length} →   
Logger.info(“Incomplete data, continuing to receive. New expected length: #{new\_expected\_length}”)  
receive\_data(socket, remaining, new\_expected\_length)  
{:rdb\_complete, rdb\_data} →   
Logger.info(“Received complete RDB file of size #{byte\_size(rdb\_data)} bytes”)  
{:ok, :rdb\_complete, rdb\_data}  
{:commands, commands} →   
Logger.info(“Received complete command: #{inspect(commands)}”)  
# case command do  
# [\_command | args] →   
# execute\_set\_command(args)  
# end  
{:ok, :commands, commands}  
end  
{:error, reason} →   
Logger.error(“Error receiving data: #{inspect(reason)}”)  
{:error, reason}  
end  
end  
Actually i am new to elixir, so learning things is taking more time to figure out , and thanks for the suggestion of printing raw data , it has given me to figure out that extra data is carrying along with psync response,  
before the test has failing 7/10 times, now it is failing 3/10 times i still need to make accurate .

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [August 6, 2024, 7:52pm UTC](https://forum.codecrafters.io/t/hardly-stuck-on-challange-yg/1208/22 "2024-08-06T19:52:52Z")

</div>

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

[Previous page](https://forum.codecrafters.io/t/hardly-stuck-on-challange-yg/1208.md?page=1)
