Visitar URL original
🐛 Restore str value support in append and prepend wrappers · aisk/python-memcache@498896d · GitHub
Skip to content

Commit 498896d

Browse files
committed
🐛 Restore str value support in append and prepend wrappers
1 parent 9dd6f9e commit 498896d

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎memcache/async_memcache.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,14 @@ async def replace(
145145
result = await self._meta.set(key, value, ttl=expire, mode="replace")
146146
return result.status is MutationStatus.STORED
147147

148-
async def append(self, key: bytes | str, value: Any) -> bool:
148+
async def append(self, key: bytes | str, value: bytes | str) -> bool:
149+
if isinstance(value, str):
150+
value = value.encode()
149151
return (await self._meta.append(key, value)).status is MutationStatus.STORED
150152

151-
async def prepend(self, key: bytes | str, value: Any) -> bool:
153+
async def prepend(self, key: bytes | str, value: bytes | str) -> bool:
154+
if isinstance(value, str):
155+
value = value.encode()
152156
return (await self._meta.prepend(key, value)).status is MutationStatus.STORED
153157

154158
async def get_many(self, keys: list[bytes | str]) -> dict[str, Any]:

‎memcache/memcache.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,14 @@ def replace(
138138
result = self._meta.set(key, value, ttl=expire, mode="replace")
139139
return result.status is MutationStatus.STORED
140140

141-
def append(self, key: bytes | str, value: Any) -> bool:
141+
def append(self, key: bytes | str, value: bytes | str) -> bool:
142+
if isinstance(value, str):
143+
value = value.encode()
142144
return self._meta.append(key, value).status is MutationStatus.STORED
143145

144-
def prepend(self, key: bytes | str, value: Any) -> bool:
146+
def prepend(self, key: bytes | str, value: bytes | str) -> bool:
147+
if isinstance(value, str):
148+
value = value.encode()
145149
return self._meta.prepend(key, value).status is MutationStatus.STORED
146150

147151
def get_many(self, keys: list[bytes | str]) -> dict[str, Any]:

0 commit comments

Comments
 (0)