Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the code for challenge 8 more modular and scalable #26

Open
jainmohit2001 opened this issue Aug 30, 2023 · 1 comment
Open

Make the code for challenge 8 more modular and scalable #26

jainmohit2001 opened this issue Aug 30, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@jainmohit2001
Copy link
Owner

Currently the commands in the server implementation are handled via switch case statements as follows:

switch (command) {
  case RedisCommands.PING:
    this.handlePing(sock, data);
    break;
  case RedisCommands.ECHO:
    this.handleEcho(sock, data);
    break;
  case RedisCommands.SET:
    this.handleSet(sock, data);
    break;
  case RedisCommands.GET:
    this.handleGet(sock, data);
    break;
  case RedisCommands.DEL:
    this.handleDelete(sock, data);
    break;
  default:
    throw new Error(`UNKNOWN_COMMAND: ${command}`);
}

This way of writing code is not scalable.

What we can do is create a new folder, say commands, add the respective commands, and export them using module.exports.

We can take the sample code from Challenge 19 as a reference and build the command handlers in a similar manner.

@jainmohit2001 jainmohit2001 self-assigned this Aug 30, 2023
@jainmohit2001 jainmohit2001 added the enhancement New feature or request label Aug 30, 2023
@jainmohit2001 jainmohit2001 changed the title Make the code for challenge 8 - Write Your Own Redis Server more modular and scalable Make the code for challenge 8 more modular and scalable Aug 30, 2023
@alizainaslam
Copy link

Hey!
I know a different code structure for improve readability. Check object mapping / object dictionary. it's a better alternative of switch case.
I haven't seen the whole code, due to the less knowledge, so you can try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants