summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Reifschneider <jafo@tummy.com>2009-04-02 12:42:46 -0600
committerSean Reifschneider <jafo@tummy.com>2009-04-02 12:42:46 -0600
commitcdea413e1b23dcefc285262d496d63e03ec424b3 (patch)
tree5f0a122545b831c9568f198bcae87b89f7d63fc7
parent74dbc2476fb1aadf64081e9a3c5f18a41268773a (diff)
downloadpython-memcached-cdea413e1b23dcefc285262d496d63e03ec424b3.tar.gz
Moving length check after the compression.
-rw-r--r--memcache.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/memcache.py b/memcache.py
index df0be58..2d7f666 100644
--- a/memcache.py
+++ b/memcache.py
@@ -622,18 +622,21 @@ class Client(local):
pickler.persistent_id = self.persistent_id
pickler.dump(val)
val = file.getvalue()
- # silently do not store if value length exceeds maximum
- if len(val) >= SERVER_MAX_VALUE_LENGTH: return(0)
lv = len(val)
- # We should try to compress if min_compress_len > 0 and we could import zlib and this string is longer than our min threshold.
+ # We should try to compress if min_compress_len > 0 and we could
+ # import zlib and this string is longer than our min threshold.
if min_compress_len and _supports_compress and lv > min_compress_len:
comp_val = compress(val)
- #Only retain the result if the compression result is smaller than the original.
+ # Only retain the result if the compression result is smaller
+ # than the original.
if len(comp_val) < lv:
flags |= Client._FLAG_COMPRESSED
val = comp_val
+ # silently do not store if value length exceeds maximum
+ if len(val) >= SERVER_MAX_VALUE_LENGTH: return(0)
+
return (flags, len(val), val)
def _set(self, cmd, key, val, time, min_compress_len = 0):