-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
feat(django-redis): add set functionality to default client #654
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,3 +183,59 @@ def close(self, **kwargs): | |
@omit_exception | ||
def touch(self, *args, **kwargs): | ||
return self.client.touch(*args, **kwargs) | ||
|
||
@omit_exception | ||
def sadd(self, *args, **kwargs): | ||
return self.client.sadd(*args, **kwargs) | ||
|
||
@omit_exception | ||
def scard(self, *args, **kwargs): | ||
return self.client.scard(*args, **kwargs) | ||
|
||
@omit_exception | ||
def sdiff(self, *args, **kwargs): | ||
return self.client.sdiff(*args, **kwargs) | ||
|
||
@omit_exception | ||
def sdiffstore(self, *args, **kwargs): | ||
return self.client.sdiffstore(*args, **kwargs) | ||
|
||
@omit_exception | ||
def sinter(self, *args, **kwargs): | ||
return self.client.sinter(*args, **kwargs) | ||
|
||
@omit_exception | ||
def sinterstore(self, *args, **kwargs): | ||
return self.client.sinterstore(*args, **kwargs) | ||
|
||
@omit_exception | ||
def sismember(self, *args, **kwargs): | ||
return self.client.sismember(*args, **kwargs) | ||
|
||
@omit_exception | ||
def smembers(self, *args, **kwargs): | ||
return self.client.smembers(*args, **kwargs) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
@omit_exception | ||
def smove(self, *args, **kwargs): | ||
return self.client.smove(*args, **kwargs) | ||
|
||
@omit_exception | ||
def spop(self, *args, **kwargs): | ||
return self.client.spop(*args, **kwargs) | ||
|
||
@omit_exception | ||
def srandmember(self, *args, **kwargs): | ||
return self.client.srandmember(*args, **kwargs) | ||
|
||
@omit_exception | ||
def srem(self, *args, **kwargs): | ||
return self.client.srem(*args, **kwargs) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
@omit_exception | ||
def sunion(self, *args, **kwargs): | ||
return self.client.sunion(*args, **kwargs) | ||
|
||
@omit_exception | ||
def sunionstore(self, *args, **kwargs): | ||
return self.client.sunionstore(*args, **kwargs) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -776,3 +776,196 @@ def touch( | |
# Convert to milliseconds | ||
timeout = int(timeout * 1000) | ||
return bool(client.pexpire(key, timeout)) | ||
|
||
def sadd( | ||
self, | ||
key: Any, | ||
*values: Any, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> int: | ||
if client is None: | ||
client = self.get_client(write=True) | ||
|
||
key = self.make_key(key, version=version) | ||
values = [self.encode(value) for value in values] | ||
return int(client.sadd(key, *values)) | ||
|
||
def scard( | ||
self, | ||
key: Any, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> int: | ||
if client is None: | ||
client = self.get_client(write=False) | ||
|
||
key = self.make_key(key, version=version) | ||
return int(client.scard(key)) | ||
|
||
def sdiff( | ||
self, | ||
*keys, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> set: | ||
if client is None: | ||
client = self.get_client(write=False) | ||
|
||
keys = [self.make_key(key, version=version) for key in keys] | ||
return {self.decode(value) for value in client.sdiff(*keys)} | ||
|
||
def sdiffstore( | ||
self, | ||
dest: Any, | ||
*keys, | ||
version: Optional[int] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe here we would like to have two versions? version of set A and version of set B There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is alirezaei1380#1 kinda what you had in mind for the multiple versions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but please use camel_case... I am really sorry for the late reply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're referring to the Hoping the author accepts this PR soon. |
||
client: Optional[Redis] = None, | ||
) -> int: | ||
if client is None: | ||
client = self.get_client(write=True) | ||
|
||
dest = self.make_key(dest, version=version) | ||
keys = [self.make_key(key, version=version) for key in keys] | ||
return int(client.sdiffstore(dest, *keys)) | ||
|
||
|
||
def sinter( | ||
self, | ||
*keys, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> set: | ||
if client is None: | ||
client = self.get_client(write=False) | ||
|
||
keys = [self.make_key(key, version=version) for key in keys] | ||
return {self.decode(value) for value in client.sinter(*keys)} | ||
|
||
def sinterstore( | ||
self, | ||
dest: Any, | ||
*keys, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> int: | ||
if client is None: | ||
client = self.get_client(write=True) | ||
|
||
dest = self.make_key(dest, version=version) | ||
keys = [self.make_key(key, version=version) for key in keys] | ||
return int(client.sinterstore(dest, *keys)) | ||
|
||
def sismember( | ||
self, | ||
key: Any, | ||
member: Any, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> bool: | ||
if client is None: | ||
client = self.get_client(write=False) | ||
|
||
key = self.make_key(key, version=version) | ||
member = self.encode(member) | ||
return bool(client.sismember(key, member)) | ||
|
||
def smembers( | ||
self, | ||
key: Any, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> set: | ||
if client is None: | ||
client = self.get_client(write=False) | ||
|
||
key = self.make_key(key, version=version) | ||
return {self.decode(value) for value in client.smembers(key)} | ||
|
||
def smove( | ||
self, | ||
source: Any, | ||
destination: Any, | ||
member: Any, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> bool: | ||
if client is None: | ||
client = self.get_client(write=True) | ||
|
||
source = self.make_key(source, version=version) | ||
destination = self.make_key(destination) | ||
member = self.encode(member) | ||
return bool(client.smove(source, destination, member)) | ||
|
||
def spop( | ||
self, | ||
key: Any, | ||
count: Optional[int] = None, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> Union[set, Any]: | ||
if client is None: | ||
client = self.get_client(write=True) | ||
|
||
key = self.make_key(key, version=version) | ||
result = client.spop(key, count) | ||
if type(result) == list: | ||
return {self.decode(value) for value in result} | ||
return self.decode(result) | ||
|
||
def srandmember( | ||
self, | ||
key: Any, | ||
count: Optional[int] = None, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> Union[set, Any]: | ||
if client is None: | ||
client = self.get_client(write=False) | ||
|
||
key = self.make_key(key, version=version) | ||
result = client.srandmember(key, count) | ||
if type(result) == list: | ||
return {self.decode(value) for value in result} | ||
return self.decode(result) | ||
|
||
def srem( | ||
self, | ||
key: Any, | ||
*members, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> int: | ||
if client is None: | ||
client = self.get_client(write=True) | ||
|
||
key = self.make_key(key, version=version) | ||
members = [self.decode(member) for member in members] | ||
return int(client.srem(key, *members)) | ||
|
||
def sunion( | ||
self, | ||
*keys, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> set: | ||
if client is None: | ||
client = self.get_client(write=False) | ||
|
||
keys = [self.make_key(key, version=version) for key in keys] | ||
return {self.decode(value) for value in client.sunion(*keys)} | ||
|
||
def sunionstore( | ||
self, | ||
destination: Any, | ||
*keys, | ||
version: Optional[int] = None, | ||
client: Optional[Redis] = None, | ||
) -> int: | ||
if client is None: | ||
client = self.get_client(write=True) | ||
|
||
destination = self.make_key(destination, version=version) | ||
keys = [self.make_key(key, version=version) for key in keys] | ||
return int(client.sunionstore(destination, *keys)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SINTERCARD
is missing