On 10 November 2011 08:54, ionic drive <[email protected]> wrote:

> Hello django friends,
>
> Problems:
> --------
> 1) MemcachedKeyCharacterError: Control characters not allowed
> 2) MemcachedKeyLengthError: Key length is > 250
>
>
The obvious solution is not to generate keys with these properties.


>    def _smart_key(self, key):
>        "Truncate all keys to 250 or less and remove control characters"
>        return smart_str(''.join([c for c in key
>                                    if ord(c) > 32 and ord(c) !=
> 127]))[:250]
>
>
That looks like a very dangerous, and not very smart key function. Since
you're truncating the key, two keys that should be different could end up
pointing to the same place. That will result in very difficult to track
down bugs.

If you really have values that are longer than 255 characters, I'd suggest
running it through a hash function (e.g. MD5) that has a low probability of
collision, and then use that.

E.g. if the key was "poll:question:choice:a very long choice here that
takes up 255 characters" I'd turn it into
"poll:question:choice:<MD5 hash of choice text>"

Malcolm

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to