本文整理汇总了Python中point.util.redispool.RedisPool类的典型用法代码示例。如果您正苦于以下问题:Python RedisPool类的具体用法?Python RedisPool怎么用?Python RedisPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RedisPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Queue
class Queue(object):
def __init__(self, _id, addr=None, blocking=True, channels=True):
self._id = _id
self.queue = RedisPool(addr)
self.blocking = blocking
self.channels = channels
log.debug('queue %s connected using %s' % (_id, addr))
def pop(self):
if self.blocking:
data = self.queue.brpop(self._id, settings.queue_timeout)
else:
data = self.queue.rpop(self._id)
if not data:
return None
try:
if self.channels:
data = data[1]
log.debug('POP %s: %s' % (self._id, data))
return json.loads(data)
except ValueError:
return None
def push(self, data):
log.debug('PUSH %s: %s' % (self._id, json.dumps(data)))
self.queue.lpush(self._id, json.dumps(data))
示例2: reg_invite_set_login
def reg_invite_set_login(value):
sess = env.user.session()
if not sess.data():
env.user.session(reg_invite_set_login, key=value)
return 'Please enter your nickname'
if not sess['key']:
env.user.session_destroy()
return 'Fail'
env.user.session_destroy()
if value.startswith('@'):
value = value[1:]
if not validate_nickname(value):
return xmpp_template('reg_invalid')
try:
users.register(login=value, accounts=[('xmpp', env.jid)])
redis = RedisPool(settings.storage_socket)
redis.delete('invite:%s' % sess['key'])
return xmpp_template('reg_ok', login=value)
except UserExists:
return 'User @%s already exists.' % value
except UserError, e:
log.error('%s: %s' % (e.__class__.__name__, e.message))
return e.message
示例3: comments_count
def comments_count(self):
if self._comments_count is not None:
return self._comments_count
if not self.id:
raise PostNotFound(None)
redis = RedisPool(settings.storage_socket)
cnt = redis.get('cmnt_cnt.%s' % unb26(self.id))
if cnt is not None:
try:
self._comments_count = int(cnt)
except (TypeError, ValueError):
self._comments_count = 0
return self._comments_count
try:
cnt = db.fetchone("SELECT count(comment_id)::int "
"FROM posts.comments "
"WHERE post_id=%s;",
[unb26(self.id)])[0]
except IndexError:
cnt = 0
redis.set('cmnt_cnt.%s' % unb26(self.id), int(cnt))
try:
self._comments_count = int(cnt)
except (TypeError, ValueError):
self._comments_count = 0
return self._comments_count
示例4: __init__
def __init__(self):
log.info('ws: pubsub init')
pool = RedisPool(settings.pubsub_socket)
pubsub = pool.pubsub()
pubsub.subscribe(['msg', 'msg.self', 'sub', 'rec', 'confirm'])
for msg in pubsub.listen():
self.handle_message(msg)
示例5: user_sessions
def user_sessions(user):
redis = RedisPool(settings.session_socket)
try:
sessions = json.loads(redis.get(_sessions_key(user.id)))
print '>>>>>>> sessions', sessions
return sessions
except (TypeError, ValueError):
return []
示例6: login
def login():
key = sha1('%s%s' % (randint(1000000, 9999999),
datetime.now().isoformat())).hexdigest()
redis = RedisPool(settings.storage_socket)
redis.set('login:%s'%key, env.user.id)
redis.expire('login:%s'%key, settings.login_key_expire)
return 'https://%s/login/%s' % (settings.domain, key)
示例7: delete
def delete(self):
res = db.fetchone("DELETE FROM posts.comments "
"WHERE post_id=%s AND comment_id=%s "
"RETURNING files;",
[unb26(self.post.id), self.id])
if res and res['files']:
for f in res['files']:
remove_attach(f)
redis = RedisPool(settings.storage_socket)
redis.decr('cmnt_cnt.%s' % unb26(self.post.id))
示例8: cache_store
def cache_store(key, data, expire=None):
log.debug("cache_store %s" % key)
redis = RedisPool(settings.cache_socket)
redis.set(key, json.dumps(data))
if not expire:
try:
expire = settings.cache_expire_max
except AttributeError:
expire = 3600 * 24 # day
redis.expire(key, expire)
示例9: __init__
def __init__(self):
proctitle('sender-queue')
log.info('sender queue started with PID=%s' % os.getpid())
self.xsq = Queue('xsq', settings.queue_socket)
pool = RedisPool(settings.pubsub_socket)
pubsub = pool.pubsub()
pubsub.subscribe(['msg', 'sub', 'rec', 'confirm', 'remember'])
for msg in pubsub.listen():
self.xsq.push("%s %s" % (msg['channel'], msg['data']))
示例10: last_published
def last_published(self, ts=None):
if not self.id:
return None
redis = RedisPool(settings.storage_socket)
key = "feed:last_published:%s" % self.id
if ts is None:
if not self.id:
if not self._posts:
return None
ts = max([ p.created for p in self._posts ])
redis.set(key, ts.isoformat())
return ts
ts = redis.get(key)
if ts:
return dateutil.parser.parse(ts)
res = db.fetchone("SELECT max(created) FROM posts.posts "
"WHERE author=%s;", [self.id])
if not res or not res[0]:
return None
redis.set(key, res[0].isoformat())
return res[0]
redis.set(key, ts.isoformat())
示例11: __init__
def __init__(self):
proctitle('support-worker')
log.info('support worker started with PID=%s' % os.getpid())
pool = RedisPool(settings.pubsub_socket)
pubsub = pool.pubsub()
pubsub.subscribe(['msg'])
for msg in pubsub.listen():
try:
data = json.loads(msg['data'])
except TypeError:
continue
if data['a'] in ('post', 'post_edited'):
gevent.spawn(self.handle_post, data)
示例12: reset_password
def reset_password(code, password):
redis = RedisPool(settings.storage_socket)
key = 'reset-password:%s' % code
print key
id = redis.get(key)
if not id:
raise UserNotFound
try:
user = User(int(id))
except ValueError:
raise UserNotFound
user.set_password(password)
user.save()
redis.delete(key)
return user
示例13: login_key
def login_key(key):
if env.user.id:
env.user.logout()
redis = RedisPool(settings.storage_socket)
try:
user_id = int(redis.get("login:%s" % key))
except (TypeError, ValueError):
raise NotFound
redis.delete("login:%s" % key)
env.user = WebUser(user_id)
env.user.authenticate()
return Response(redirect="%s://%s/" % (env.request.protocol, settings.domain))
示例14: request_password
def request_password(user):
if not user.id:
raise UserNotFound
address = user.get_active_account('xmpp')
if not address:
raise AddressNotFound
code = sha256('%s%s' % (datetime.now(), randint(1000000, 9999999))).hexdigest()
key = 'reset-password:%s' % code
redis = RedisPool(settings.storage_socket)
redis.set(key, user.id)
redis.expire(key, 60 * 60 * 24)
publish('remember', {'type': 'xmpp', 'address': address, 'code': code})
示例15: __init__
def __init__(self, _id, addr=None, blocking=True, channels=True):
self._id = _id
self.queue = RedisPool(addr)
self.blocking = blocking
self.channels = channels
log.debug('queue %s connected using %s' % (_id, addr))