How to implement Redis db without caching in django - django

I want to implement the Redis Database and Postgres in the Django cache, but I need to implement them separately. means I need to check the Redis manually and not through the Django caching.
Could any help me implement this?

Related

Using mysql and mongodb together for Django

Can I use both relational-database(eg : mysql) and non-relational database(eg : mongodb) together as bacekend dbs for a Django project? If possible then how?
I use Django version 1.11
Yes, kind of. MongoDB is not supported as a backend for Django's ORM, however, you can use through MongoDB Python.
What I would do, in this case, is use MySQL as your default database in your DATABASES setting. I would use MySQL for all of my Django ORM functions, and only use MongoDB where I need it. You can then connect to MongoDB for non-ORM connections via Python. See here for connecting to MongoDB via Python: https://api.mongodb.com/python/3.4.0/
There used to be a Mongo backend - again, without much ORM support - but last I saw, it hasn't been updated in several years: https://github.com/django-nonrel
Good luck!

In Django, how do I make a model that queries my legacy SQL Server and Oracle databases and sends that to the view?

I have a lot of old vbscript webpages using Classis ASP. Those ASP pages have lots of different databases queries to different databases all inside a given .asp file. I want to write those in Python and use Django as the framework. Will I be able to do this? I'm not sure how to start after I install Django. Sure, I can make a demo work, but that's not what I'm after. I will use the normal database "things" in MySQL or PostgreSQL, but sooner or later I have to hit those other databases and bring them back into Django, using Django's templating and so on.
Will I be able to do this? How do I make a model that queries my legacy SQL Server and Oracle database and send that to the view? Am I "fighting the framework" to accomplish this?
Just to be clear. I am not interested in messing with the stock database that Django uses for it's settings. That can stay as it is. I want to use that part for plugins, security (ldap), etc.
Thanks.
You can query different databases in your ORM calls by leveraging the using statement: https://docs.djangoproject.com/en/1.5/ref/models/querysets/#using
This would allow you to set up as many database definitions as you need in settings.py, then specify which DB to query at the view level. That way, you wouldn't have to change your model definition should you decide to consolidate your databases, etc.
Have you reviewed the Django multiple databases documentation?
Django has a built-in Oracle back end, so that should be fairly straightforward.
SQL Server can work through django-pyodbc but I found it fairly painful to set up. If you already have a generally working ODBC connection to your legacy SQL Server database connection from your Django environment it's no big deal, but it took me some trouble to get things set up to where I could use tsql to connect to my SQL Server database.
I also had some trouble with Unicode data from the SQL Server database until I forced it to use the appropriate (later) version of TDS. I just needed it for a script or two, so I set the 'TDSVER' environment variable and left it at that, but in theory there are other places you can set that.

What is the best way to run Django on Tornado Web Server to have async + django admin + django orm possibilities?

I would like to have django admin panel with tornado backends, which will process requests from online game. I dont know at the moment, is it a good idea to load django app in the next way:
wsgi_app = tornado.wsgi.WSGIContainer(
django.core.handlers.wsgi.WSGIHandler())
tornado_app = tornado.web.Application(
[
('/hello-tornado', HelloHandler),
('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
])
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
HelloHandler is going to be a backend parser.
Will I loose some performance in combining wsgi + ioloop ?
If its a bad solution, its possible to run 2 apps: django admin and tornado web. Could you answer how can I use Django ORM with Tornado App?
Just take this equation and solve it.
You want to have non-blocking IO - X.
You want to have django ORM - Y.
You want to have django admin - Z.
Now, move point by point:
For X - tornado is enough itself.
For Z - django is enough itself. I don't think, you want to have
thousands of administrators, that manage your site at one time.
For Y it is harder. Django ORM is blocking itself.
Best way here - not to use Django ORM with tornado.
Second way - you can dive deeper and integrate it directly in tornado, if you are sure that it will not block whole application. Take solution from this answer.
Third way - you can convert your django application to service, that makes heavy work with ORM, and you can access this service with AsyncHTTPCLient from tornado.
Fourth way - integrate tornado web server into your django application. Actually, it will give you small performance boost.
Fifth way - use two tornado web servers. Sounds crazy, yes. Use one with Django ORM integrated, and second with AsyncHTTPClient.
I believe, that you can take best of 2 worlds.
Django is not asynchronous, so running Django in Tornado will remove most of the performance benefits you might get from Tornado.
If you want maximum async performance, you should use Tornado with a non-blocking database (I'm assuming you want Django admin for use with a SQL database).
If you want maximum ease of development, use Django, with it's ORM system and admin tools.
You can't just mix the best of both worlds, unfortunately.
So, yes, you will lose performance. In this situation I would probably use Tornado and give up on Django admin. If you're dead set on a compromise you could write two apps, sharing a database, but that will mean you need to maintain two data access layers.

Django and SphinxQL - how to disable transactions?

I have to use a SphinxQL in Django, but SphinxQL seems doesn't support transaction. How to disable transactions for SphinxQL connection? Is it possible? I replaced Django MySQL backend with MySQLdb and it works, but I prefer using native Django components.
You could manage that via
set autocommit=0
insert
...
commit
set autocommit=1

Can I Use MemcacheDB to Replace Memcached in django?

I want to use MemcacheDB instead of Memcached because I don't have a lot of RAM for Memcached.
Will it work with django's cache framework?
Is there anything additional I would need to do?
Yes, I think this should just work. The whole idea of MemcacheDB is to give a BDB backend through existing and tested memcache client libraries. Django just sits on top of that.