jaysonsantos / django-bmemcached Goto Github PK
View Code? Open in Web Editor NEWA django cache backend to use bmemcached module which supports memcached binary protocol with authentication.
License: MIT License
A django cache backend to use bmemcached module which supports memcached binary protocol with authentication.
License: MIT License
get_or_set()
doesn't appear to work as expected.
When the key already exists it returns the value as expected. However when the key is being set, it will return a tuple of (value, _something)
. Similar seems to happen when calling cache.get()
with a default.
I can't entirely follow whats happening but it looks like maybe the default is accidentally passed through to the get_cas
param on the client.
When using set_many, if any of the values are non-strings, I get an error. I can loop through the set, and it works fine however. For example:
from django_bmemcached import BMemcached
client = BMemcached('127.0.0.1:11211', {})
client.set('single', 1) # no error
client.set_many({'many': 1}) # struct.error: argument for 's' must be a bytes object
for key, value in {'many_loop': 1}.items():
client.set(key, value) # no error
My fix is to just do the loop, but would rather for performance use set_many. Happy to help if you can point me to the right place to fix.
Since version 1.5.13, Memcached supports TLS.
Since version 0.29.0, python-binary-memecached supports TLS.
Hi. I'm testing django-memcached in Heroku. But i have a problem today, because heroku memcached server go down. My app failed with exception below.
I try to catch this exception but i cant. Theres a way to avoid this behaviour ?
Thanks.
2011-12-11T17:23:49+00:00 app[web.1]: Traceback (most recent call last):
2011-12-11T17:23:49+00:00 app[web.1]: File "/app/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 70, in handle
2011-12-11T17:23:49+00:00 app[web.1]: self.handle_request(req, client, addr)
2011-12-11T17:23:49+00:00 app[web.1]: File "/app/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 96, in handle_request
2011-12-11T17:23:49+00:00 app[web.1]: respiter = self.wsgi(environ, resp.start_response)
2011-12-11T17:23:49+00:00 app[web.1]: File "/app/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 68, in call
2011-12-11T17:23:49+00:00 app[web.1]: return self.application(environ, start_response)
2011-12-11T17:23:49+00:00 app[web.1]: File "/app/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 275, in call
2011-12-11T17:23:49+00:00 app[web.1]: signals.request_finished.send(sender=self.class)
2011-12-11T17:23:49+00:00 app[web.1]: File "/app/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send
2011-12-11T17:23:49+00:00 heroku[router]: Error H13 (Connection closed without response) -> POST l3b.herokuapp.com/tabBuilder/html/1/ dyno=web.1 queue= wait= service= status=503 bytes=
2011-12-11T17:23:49+00:00 app[web.1]: response = receiver(signal=self, sender=sender, *_named)
2011-12-11T17:23:49+00:00 app[web.1]: File "/app/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 83, in close
2011-12-11T17:23:49+00:00 app[web.1]: self._cache.disconnect_all()
2011-12-11T17:23:49+00:00 app[web.1]: File "/app/lib/python2.7/site-packages/django_bmemcached/memcached.py", line 37, in _cache
2011-12-11T17:23:49+00:00 app[web.1]: self._options.get('password', None))
2011-12-11T17:23:49+00:00 app[web.1]: File "/app/lib/python2.7/site-packages/bmemcached/init.py", line 19, in init
2011-12-11T17:23:49+00:00 app[web.1]: self.set_servers(servers)
2011-12-11T17:23:49+00:00 app[web.1]: File "/app/lib/python2.7/site-packages/bmemcached/init.py", line 23, in set_servers
2011-12-11T17:23:49+00:00 app[web.1]: self.password) for server in servers]
2011-12-11T17:23:49+00:00 app[web.1]: File "/app/lib/python2.7/site-packages/bmemcached/init.py", line 147, in init
2011-12-11T17:23:49+00:00 app[web.1]: self.connection.connect((host, port))
2011-12-11T17:23:49+00:00 app[web.1]: File "/usr/local/lib/python2.7/socket.py", line 224, in meth
2011-12-11T17:23:49+00:00 app[web.1]: return getattr(self._sock,name)(_args)
2011-12-11T17:23:49+00:00 app[web.1]: error: [Errno 113] No route to host
This package doesn't support python 3. It would be great if it did! Issue I'm hitting is with the relative vs. absolute import syntax in init.py.
Im not sure if this is the right place for this issue tbh, as memcache in django involves lots of layers.
Djangos cache.get
call usually respects default values, cache.get('non_existent_key', 'default_value')
to give it a dict like experience when using.
Though that doesnt happen with this library, as https://github.com/jaysonsantos/python-binary-memcached/blob/master/bmemcached/client/replicating.py#L51 does not deal with default values in the get
method.
I am using another very popular library (Django Rest Framework) that is failing because of this, see https://github.com/encode/django-rest-framework/blob/master/rest_framework/throttling.py#L123
As it expects the default value to be returned when the cache key is not present, but it never is.
If this issue has been raised in the wrong place, perhaps you could direct me to the right place ?
Thanks in advance
Switching from django.core.cache.backends.memcached.MemcachedCache to django_bmemcached.memcached.BMemcached, we noticed the number of open connections to the database being used and to the cache memory increases significantly. (from 3 to > 30)
Is there a known reason for this and can It be changed?
has_key()
returns True
for all keys.Presumably something to do with django/django@bb64b99 -- adding _missing_key = None
makes it work correctly.
Was testing with python-binary-memcached==0.29
, will try newer version and see if that supports default values in get()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.