-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
509d5be
commit 0b8a032
Showing
8 changed files
with
41 additions
and
12 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Tuple, List, AnyStr | ||
|
||
class BaseParser(ABC): | ||
@abstractmethod | ||
def parse(self, data, *args, **kwargs) -> Tuple[AnyStr, List[AnyStr]]: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from hiredis import Reader | ||
|
||
from redis_clone.parser.base import BaseParser | ||
|
||
|
||
class HiRedisParser(BaseParser): | ||
def __init__(self): | ||
self.reader_class = Reader | ||
|
||
def parse(self, data, *args, **kwargs): | ||
reader = self.reader_class(*args, **kwargs) | ||
reader.feed(data) | ||
if data := reader.gets(): | ||
command = data[0] | ||
arguments = data[1:] | ||
return command, arguments | ||
|
||
raise Exception("Invalid data received") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
async-timeout==4.0.3 | ||
exceptiongroup==1.1.3 | ||
hiredis==2.3.2 | ||
iniconfig==2.0.0 | ||
packaging==23.2 | ||
pluggy==1.3.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters