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

Factor our RedisDict._encode_dict() #571

Merged
merged 1 commit into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pottery/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ def _populate(self, # type: ignore
dict_[key] = original + sign * value

dict_ = {key: self[key] + value for key, value in dict_.items()}
encoded_dict = {
self._encode(key): self._encode(value)
for key, value in dict_.items()
}
encoded_dict = self._encode_dict(dict_)
if encoded_dict:
pipeline.multi()
pipeline.hset(self.key, mapping=encoded_dict) # type: ignore
Expand Down
14 changes: 10 additions & 4 deletions pottery/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ def _populate(self,
arg = cast(InitMap, arg).items()
items = itertools.chain(cast(InitIter, arg), kwargs.items())
dict_ = dict(items)
encoded_dict = {
self._encode(key): self._encode(value)
for key, value in dict_.items()
}
encoded_dict = self.__encode_dict(dict_)
if encoded_dict:
pipeline.multi()
pipeline.hset(self.key, mapping=encoded_dict) # type: ignore
Expand All @@ -86,6 +83,15 @@ def _populate(self,
# https://stackoverflow.com/a/38534939
__populate = _populate

def _encode_dict(self, dict_):
encoded_dict = {
self._encode(key): self._encode(value)
for key, value in dict_.items()
}
return encoded_dict

__encode_dict = _encode_dict

# Methods required by collections.abc.MutableMapping:

def __getitem__(self, key: JSONTypes) -> JSONTypes:
Expand Down