다음은 redis에 쓰기 요청에서 비 차단 방법으로 다시 시도하는 코드입니다. 또한 아래 오류가 발생합니다. 500 오류입니다. 나는 사이클론과 함께 배송 된 txredisapi에 대한 문서를 이해하지 못합니다.초보자가 트위스트 및 사이클론에 - 간단한 요청을 받기 위해 redis 콜백을 얻는 방법
redisPixelWrite(remote_ip).addcallback()
인상 AttributeError
: 그것은
import cyclone.web
import sys
from twisted.internet import reactor
from twisted.python import log
import cyclone.redis as redis
from twisted.internet import defer
from twisted.internet import reactor
@defer.inlineCallbacks
def redisPixelWrite(remote_ip):
rc = yield redis.Connection()
yield rc.set("foo", 'itwodasdfred')
v = yield rc.get("foo")
print "foo:", v
yield rc.disconnect()
class Application(cyclone.web.Application):
def __init__(self):
handlers = [
(r"/", MainHandler),
]
settings = {"xheaders": True,"static_path": "./static"}
cyclone.web.Application.__init__(self, handlers, **settings)
class MainHandler(cyclone.web.RequestHandler):
def get(self):
remote_ip = self.request.remote_ip
redisPixelWrite(remote_ip).addcallback()
self.set_header('Content-Type', 'text/html')
self.write(remote_ip)
def main():
log.startLogging(sys.stdout)
reactor.listenTCP(8051, Application(), interface="127.0.0.1")
reactor.run()
if __name__ == "__main__":
main()
2012-05-07 21:12:10+0800 [-] Log opened.
2012-05-07 21:12:10+0800 [-] Application starting on 8051
2012-05-07 21:12:10+0800 [-] Starting factory <__main__.Application instance at 0x228af38>
2012-05-07 21:12:14+0800 [HTTPConnection,0,127.0.0.1] Starting factory <cyclone.redis.RedisFactory instance at 0x261a680>
2012-05-07 21:12:14+0800 [HTTPConnection,0,127.0.0.1] Uncaught exception GET/(127.0.0.1) :: HTTPRequest(protocol='http', host='127.0.0.1:8051', method='GET', uri='/', version='HTTP/1.1', remote_ip='127.0.0.1', body='', headers={'Connection': 'keep-alive', 'Accept-Language': 'en-us,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Cache-Control': 'max-age=0', 'Host': '127.0.0.1:8051', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0'})
2012-05-07 21:12:14+0800 [HTTPConnection,0,127.0.0.1] 500 GET/(127.0.0.1) 2.07ms
2012-05-07 21:12:14+0800 [RedisProtocol,client] foo: itwodasdfred
2012-05-07 21:12:14+0800 [RedisProtocol,client] Stopping factory <cyclone.redis.RedisFactory instance at 0x261a680>
"하지만 앱은 무엇입니까? –