Skip to content

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

Open
@jainmohit2001

Description

@jainmohit2001

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions