Skip to content

Commit 0b7b2e8

Browse files
authored
V2.5.1 (#55)
* Changed small housekeeping * bump version 2.5.1 * Changed small house keeping
1 parent bc58555 commit 0b7b2e8

File tree

4 files changed

+38
-49
lines changed

4 files changed

+38
-49
lines changed

.travis.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

redis_dict.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def __init__(self,
131131
Args:
132132
namespace (str, optional): A prefix for keys stored in Redis.
133133
expire (int, timedelta, optional): Expiration time for keys in seconds.
134-
preserve_expiration (bool, optional): Whether or not to preserve the expiration.
134+
preserve_expiration (bool, optional): Preserve the expiration count when the key is updated.
135135
**redis_kwargs: Additional keyword arguments passed to StrictRedis.
136136
"""
137137
self.temp_redis: Optional[StrictRedis[Any]] = None
@@ -403,14 +403,14 @@ def get(self, key: str, default: Optional[Any] = None) -> Any:
403403

404404
def iterkeys(self) -> Iterator[str]:
405405
"""
406-
Note: for pythone2 str is needed
406+
Note: for python2 str is needed
407407
"""
408408
to_rm = len(self.namespace) + 1
409409
return (str(item[to_rm:]) for item in self._scan_keys())
410410

411411
def key(self, search_term: str = '') -> Optional[str]:
412412
"""
413-
Note: for pythone2 str is needed
413+
Note: for python2 str is needed
414414
"""
415415
to_rm = len(self.namespace) + 1
416416
cursor, data = self.get_redis.scan(match='{}:{}{}'.format(self.namespace, search_term, '*'), count=1)
@@ -546,7 +546,7 @@ def setdefault(self, key: str, default_value: Optional[Any] = None) -> Any:
546546
547547
Args:
548548
key (str): The key to retrieve the value.
549-
default (Optional[Any], optional): The value to set if the key is not found.
549+
default_value (Optional[Any], optional): The value to set if the key is not found.
550550
551551
Returns:
552552
Any: The value associated with the key or the default value.
@@ -575,7 +575,7 @@ def update(self, dic: Dict[str, Any]) -> None:
575575
Update the RedisDict with key-value pairs from the given mapping, analogous to a dictionary's update method.
576576
577577
Args:
578-
other (Mapping[str, Any]): A mapping containing key-value pairs to update the RedisDict.
578+
dic (Mapping[str, Any]): A mapping containing key-value pairs to update the RedisDict.
579579
"""
580580
with self.pipeline():
581581
for key, value in dic.items():
@@ -746,13 +746,13 @@ def get_redis_info(self) -> Dict[str, Any]:
746746
def get_ttl(self, key: str) -> Optional[int]:
747747
"""
748748
Get the Time To Live (TTL) in seconds for a given key. If the key does not exist or does not have an
749-
associated expire, return None.
749+
associated `expire`, return None.
750750
751751
Args:
752752
key (str): The key for which to get the TTL.
753753
754754
Returns:
755-
Optional[int]: The TTL in seconds if the key exists and has an expire set; otherwise, None.
755+
Optional[int]: The TTL in seconds if the key exists and has an expiry set; otherwise, None.
756756
"""
757757
val = self.redis.ttl(self._format_key(key))
758758
if val < 0:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
long_description=long_description,
1818
long_description_content_type='text/markdown',
1919

20-
version='2.5.0',
20+
version='2.5.1',
2121
py_modules=['redis_dict'],
2222
install_requires=['redis',],
2323
license='MIT',

tests.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def test_dict_method_pop_default(self):
279279
self.assertEqual(len(dic), len(input_items) - i)
280280
self.assertEqual(len(redis_dic), len(input_items) - i)
281281

282-
expected = "defualt item"
282+
expected = "default item"
283283
self.assertEqual(dic.pop("item", expected), expected)
284284
self.assertEqual(redis_dic.pop("item", expected), expected)
285285

@@ -696,18 +696,18 @@ def test_set_and_get_multiple(self):
696696
self.assertEqual(self.r['foobar1'], 'barbar1')
697697
self.assertEqual(self.r['foobar2'], 'barbar2')
698698

699-
def test_get_nonexisting(self):
699+
def test_get_non_existing(self):
700700
"""Test that retrieving a non-existing key raises a KeyError."""
701701
with self.assertRaises(KeyError):
702-
_ = self.r['nonexistingkey']
702+
_ = self.r['non_existing_key']
703703

704704
def test_delete(self):
705705
"""Test deleting a key."""
706-
self.r['foobargone'] = 'bars'
706+
key = 'foobar_gone'
707+
self.r[key] = 'bar'
707708

708-
del self.r['foobargone']
709-
710-
self.assertEqual(self.redisdb.get('foobargone'), None)
709+
del self.r[key]
710+
self.assertEqual(self.redisdb.get(key), None)
711711

712712
def test_contains_empty(self):
713713
"""Tests the __contains__ function with no keys set."""
@@ -729,17 +729,21 @@ def test_repr_empty(self):
729729

730730
def test_repr_nonempty(self):
731731
"""Tests the __repr__ function with keys set."""
732-
self.r['foobars'] = 'barrbars'
733-
expected_repr = str({'foobars': 'barrbars'})
734-
actual_repr = repr(self.r)
735-
self.assertEqual(actual_repr, expected_repr)
732+
key = 'foobar'
733+
val = 'bar'
734+
self.r[key] = val
735+
expected = str({key: val})
736+
result = repr(self.r)
737+
self.assertEqual(result, expected)
736738

737739
def test_str_nonempty(self):
738740
"""Tests the __repr__ function with keys set."""
739-
self.r['foobars'] = 'barrbars'
740-
expected_str = str({'foobars': 'barrbars'})
741-
actual_str = str(self.r)
742-
self.assertEqual(actual_str, expected_str)
741+
key = 'foobar'
742+
val = 'bar'
743+
self.r[key] = val
744+
expected = str({key: val})
745+
result = str(self.r)
746+
self.assertEqual(result, expected)
743747

744748
def test_len_empty(self):
745749
"""Tests the __repr__ function with no keys set."""
@@ -820,15 +824,15 @@ def test_chain_del_2(self):
820824
_ = self.r.chain_get(['foo', 'bar'])
821825

822826
def test_expire_context(self):
823-
"""Test adding keys with an expire value by using the contextmanager."""
827+
"""Test adding keys with an `expire` value by using the contextmanager."""
824828
with self.r.expire_at(3600):
825829
self.r['foobar'] = 'barbar'
826830

827831
actual_ttl = self.redisdb.ttl('{}:foobar'.format(TEST_NAMESPACE_PREFIX))
828832
self.assertAlmostEqual(3600, actual_ttl, delta=2)
829833

830834
def test_expire_context_timedelta(self):
831-
""" Test adding keys with an expire value by using the contextmanager. With timedelta as argument. """
835+
""" Test adding keys with an `expire` value by using the contextmanager. With timedelta as argument. """
832836
timedelta_one_hour = timedelta(hours=1)
833837
timedelta_one_minute = timedelta(minutes=1)
834838
hour_in_seconds = 60 * 60
@@ -845,15 +849,15 @@ def test_expire_context_timedelta(self):
845849
self.assertAlmostEqual(minute_in_seconds, actual_ttl, delta=2)
846850

847851
def test_expire_keyword(self):
848-
"""Test adding keys with an expire value by using the expire config keyword."""
852+
"""Test adding keys with an `expire` value by using the `expire` config keyword."""
849853
r = self.create_redis_dict(expire=3600)
850854

851855
r['foobar'] = 'barbar'
852856
actual_ttl = self.redisdb.ttl('{}:foobar'.format(TEST_NAMESPACE_PREFIX))
853857
self.assertAlmostEqual(3600, actual_ttl, delta=2)
854858

855859
def test_expire_keyword_timedelta(self):
856-
""" Test adding keys with an expire value by using the expire config keyword. With timedelta as argument."""
860+
""" Test adding keys with an `expire` value by using the `expire` config keyword. With timedelta as argument."""
857861
timedelta_one_hour = timedelta(hours=1)
858862
timedelta_one_minute = timedelta(minutes=1)
859863
hour_in_seconds = 60 * 60
@@ -1153,13 +1157,13 @@ def setUp(self):
11531157
self.clear_test_namespace()
11541158

11551159
def test_unicode_key(self):
1156-
# Test handling of unicode keys
1160+
# Test handling of Unicode keys
11571161
unicode_key = '你好'
11581162
self.r[unicode_key] = 'value'
11591163
self.assertEqual(self.r[unicode_key], 'value')
11601164

11611165
def test_unicode_value(self):
1162-
# Test handling of unicode values
1166+
# Test handling of Unicode values
11631167
unicode_value = '世界'
11641168
self.r['key'] = unicode_value
11651169
self.assertEqual(self.r['key'], unicode_value)
@@ -1486,7 +1490,7 @@ def test_preserve_expiration(self):
14861490
value = "bar"
14871491
redis_dict[key] = value
14881492

1489-
# Ensure the TTL (time-to-live) of the "foo" key is approximately the global expire time.
1493+
# Ensure the TTL (time-to-live) of the "foo" key is approximately the global `expire` time.
14901494
actual_ttl = redis_dict.get_ttl(key)
14911495
self.assertAlmostEqual(3600, actual_ttl, delta=1)
14921496

@@ -1502,7 +1506,7 @@ def test_preserve_expiration(self):
15021506
actual_ttl_foo = redis_dict.get_ttl(key)
15031507
self.assertAlmostEqual(3600 - time_sleeping, actual_ttl_foo, delta=1)
15041508

1505-
# Ensure the TTL of the "bar" key is also approximately the global expire time.
1509+
# Ensure the TTL of the "bar" key is also approximately the global `expire` time.
15061510
actual_ttl_bar = redis_dict.get_ttl(new_key)
15071511

15081512
self.assertAlmostEqual(3600, actual_ttl_bar, delta=1)
@@ -1518,7 +1522,7 @@ def test_preserve_expiration_not_used(self):
15181522
value = "bar"
15191523
redis_dict[key] = value
15201524

1521-
# Ensure the TTL (time-to-live) of the "foo" key is approximately the global expire time.
1525+
# Ensure the TTL (time-to-live) of the "foo" key is approximately the global `expire` time.
15221526
actual_ttl = redis_dict.get_ttl(key)
15231527
self.assertAlmostEqual(3600, actual_ttl, delta=1)
15241528

@@ -1534,12 +1538,12 @@ def test_preserve_expiration_not_used(self):
15341538
actual_ttl_foo = redis_dict.get_ttl(key)
15351539
self.assertAlmostEqual(3600, actual_ttl_foo, delta=1)
15361540

1537-
# Ensure the TTL of the "bar" key is also approximately the global expire time.
1541+
# Ensure the TTL of the "bar" key is also approximately the global `expire` time.
15381542
actual_ttl_bar = redis_dict.get_ttl(new_key)
15391543

15401544
self.assertAlmostEqual(3600, actual_ttl_bar, delta=1)
15411545

1542-
# Ensure the difference between the TTLs of "foo" and "bar" is no more then 1 seconds.
1546+
# Ensure the difference between the TTLs of "foo" and "bar" is no more than one second.
15431547
self.assertTrue(abs(actual_ttl_foo - actual_ttl_bar) <= 1)
15441548

15451549

0 commit comments

Comments
 (0)