예제 #1
0
 def setUp(self):
     super(GRedisTest, self).setUp()
     self.client = AsyncRedis(
         "192.168.1.50",
         6379,
         encoding="utf8",
         decode_responses=True,
     )
예제 #2
0
 def setUp(self):
     super(GRedisTest, self).setUp()
     self.client = AsyncRedis(decode_responses=True)
예제 #3
0
#   Author  :   cold
#   E-mail  :   [email protected]
#   Date    :   15/04/18 13:21:25
#   Desc    :   A Chat Demo written with gredis
#
""" A chat demo based on list type of Redis, written with gredis """
from __future__ import absolute_import, print_function, division, with_statement

import uuid

from tornado import gen
from tornado import web
from tornado import ioloop
from gredis.client import AsyncRedis

client = AsyncRedis("192.168.1.50")

CHAT_PEER_KEY = "chat::peer"


class ChatHandler(web.RequestHandler):
    @gen.coroutine
    def get(self, chat_id=None):
        if not chat_id:
            chat_id = uuid.uuid1().get_hex()
            dist_id = uuid.uuid1().get_hex()
            yield client.hmset(CHAT_PEER_KEY, {chat_id: dist_id})
            yield client.hmset(CHAT_PEER_KEY, {dist_id: chat_id})
            self.redirect("/chat/{0}".format(chat_id))
        else:
            dist_id = yield client.hget(CHAT_PEER_KEY, chat_id)
예제 #4
0
파일: nserv.py 프로젝트: utyf/nserv
import os.path
import logging
from ConfigParser import ConfigParser

from gredis.client import AsyncRedis
from tornado.ioloop import IOLoop
from tornado import gen
from tornado.websocket import WebSocketHandler, WebSocketClosedError
from tornado.web import (Application, StaticFileHandler, url)

config = ConfigParser()
config.read('nserv.ini')
logging.basicConfig(level=config.get('logging', 'level'))

redis = AsyncRedis(
    config.get('redis', 'host'),
    config.get('redis', 'port'),
)


class NotificationHandler(WebSocketHandler):
    """
    Websocket handler for "pushing" notifications to the client
    """
    @gen.coroutine
    def open(self):
        logging.debug('Client connected to NotificationHandler')
        pubsub = redis.pubsub()
        yield pubsub.subscribe(config.get('redis', 'channel'))

        while True:
            message = yield pubsub.get_message(True)
예제 #5
0
파일: test.py 프로젝트: PlumpMath/gredis
 def setUp(self):
     super(GRedisTest, self).setUp()
     self.client = AsyncRedis("192.168.1.50", 6379)