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

Flesh out abstract base mixins #17

Merged
merged 1 commit into from
Oct 3, 2016
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
19 changes: 18 additions & 1 deletion pottery/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ class _Clearable(metaclass=abc.ABCMeta):
def redis(self):
'Redis client.'

@abc.abstractproperty
def key(self):
'Redis key.'

def clear(self):
'Remove the elements in a Redis-backed container. O(n)'
self.redis.delete(self.key)
Expand All @@ -155,11 +159,16 @@ class _ContextManaged(metaclass=abc.ABCMeta):
def redis(self):
'Redis client.'

@abc.abstractmethod
def __del__(self):
...

def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
self.__del__()
self.__del__() # We can't do del self because we still need a
# referense to self for the next line...
self.redis.connection_pool.disconnect()


Expand All @@ -170,6 +179,14 @@ class Base(_Common, _ContextManaged, _Clearable, Pipelined):


class Iterable(metaclass=abc.ABCMeta):
@abc.abstractmethod
def _decode(value):
...

@abc.abstractproperty
def key(self):
'Redis key.'

@abc.abstractmethod
def _scan(self, key, *, cursor=0):
...
Expand Down
2 changes: 1 addition & 1 deletion pottery/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@



class RedisDict(Iterable, Base, collections.abc.MutableMapping):
class RedisDict(Base, Iterable, collections.abc.MutableMapping):
'Redis-backed container compatible with Python dicts.'

def __init__(self, iterable=tuple(), *, redis=None, key=None, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion pottery/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@



class RedisSet(Iterable, Base, collections.abc.MutableSet):
class RedisSet(Base, Iterable, collections.abc.MutableSet):
'Redis-backed container compatible with Python sets.'

def __init__(self, iterable=tuple(), *, redis=None, key=None):
Expand Down