Permalink
Browse files

abstract redis connection

  • Loading branch information...
cedricporter committed Sep 1, 2014
1 parent 1f4cd45 commit ea0655f5530b181578c7c2d29201c8ea1d5f17b2
Showing with 20 additions and 7 deletions.
  1. +2 −1 .gitignore
  2. +4 −6 main.py
  3. +1 −0 model/__init__.py
  4. +13 −0 model/connection.py.sample
View
@@ -5,4 +5,5 @@ log.log
webscan_360_cn.html
google7a32e07f62c143af.html
reload.sh
-log/
+log/
+model/connection.py
View
10 main.py
@@ -13,19 +13,18 @@
import tornado.web
import tornadoredis
+import model
+from model.connection import CONNECTION_POOL
+
from etc import config, const
from base import util
define("port", default=config.PORT, help="run on the given port", type=int)
-CONNECTION_POOL = tornadoredis.ConnectionPool(max_connections=10,
- wait_for_available=True)
-
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render("templates/short.html")
- # self.redirect(config.MAIN_PAGE_REDIRECT)
class ExpandUrlHandler(tornado.web.RequestHandler):
@@ -51,7 +50,7 @@ def post(self):
self.write("not a valid url")
self.finish()
return
-
+
key = util.gen_cache_key(const.CACHE_KEY_PREFIX.REVERSE_URL, url)
short_id = redis_short_id = yield tornado.gen.Task(c.get, key)
@@ -83,4 +82,3 @@ def post(self):
http_server = tornado.httpserver.HTTPServer(application, xheaders=True)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
-
View
@@ -0,0 +1 @@
+
View
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# By Hua Liang[Stupid ET]
+
+import tornadoredis
+
+
+MAX_CONNECTIONS = 10
+UNIX_SOCKET_PATH = "/var/run/redis/redis-163gs.sock"
+
+CONNECTION_POOL = tornadoredis.ConnectionPool(max_connections=MAX_CONNECTIONS,
+ unix_socket_path=UNIX_SOCKET_PATH,
+ wait_for_available=True)

0 comments on commit ea0655f

Please sign in to comment.