本文整理汇总了Python中point.util.redispool.RedisPool.set方法的典型用法代码示例。如果您正苦于以下问题:Python RedisPool.set方法的具体用法?Python RedisPool.set怎么用?Python RedisPool.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类point.util.redispool.RedisPool
的用法示例。
在下文中一共展示了RedisPool.set方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: comments_count
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import set [as 别名]
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
示例2: login
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import set [as 别名]
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)
示例3: cache_store
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import set [as 别名]
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)
示例4: gen_invite
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import set [as 别名]
def gen_invite():
redis = RedisPool(settings.storage_socket)
icnt = redis.decr('icnt:%s' % env.user.id)
if icnt < 0:
return 'Invitation limit exceeded'
key = sha1('%s%s' % (randint(1000000, 9999999),
datetime.now().isoformat())).hexdigest()
redis.set('invite:%s' % key, 1)
redis.expire('invite:%s' % key, 3600*48)
return key
示例5: request_password
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import set [as 别名]
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})
示例6: last_published
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import set [as 别名]
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())
示例7: comments
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import set [as 别名]
def comments(self, last=False, all=False, offset=None, limit=None,
cuser=None):
if last:
lim = " LIMIT %d" % limit if limit else ''
offset = 0
order = ' DESC'
elif all:
lim = ''
offset = 0
order = ' ASC'
else:
if not offset:
offset = 0
lim = " LIMIT %d" % limit if limit else ''
order = ' ASC'
if isinstance(cuser, User) and cuser.id:
res = db.fetchall("SELECT c.comment_id, c.to_comment_id,"
"c.author AS user_id, "
"CASE WHEN c.anon_login IS NOT NULL "
"THEN c.anon_login ELSE u1.login END AS login,"
"c.created at time zone %%s AS created, "
"c.text, c.files, "
"c.updated at time zone %%s AS updated, "
"CASE WHEN rc.comment_id IS NOT NULL "
"THEN true ELSE false END AS is_rec, "
"ur.user_id AS recommended, "
"ub.user_id AS bookmarked, "
"ui1.name, ui1.avatar "
"FROM posts.comments c "
"JOIN users.logins u1 ON c.author=u1.id "
"LEFT OUTER JOIN users.info ui1 "
"ON ui1.id=c.author "
"LEFT OUTER JOIN posts.recommendations rc "
"ON rc.post_id=c.post_id "
"AND rc.rcid=c.comment_id "
"LEFT OUTER JOIN posts.recommendations ur "
"ON ur.user_id=%%s "
"AND ur.post_id=c.post_id "
"AND ur.comment_id=c.comment_id "
"LEFT OUTER JOIN posts.bookmarks ub "
"ON ub.user_id=%%s "
"AND ub.post_id=c.post_id "
"AND ub.comment_id=c.comment_id "
"WHERE c.post_id=%%s AND c.comment_id>=%%s "
"ORDER BY c.created%s%s;" % (order, lim),
[self.tz, self.tz, cuser.id, cuser.id, unb26(self.id),
offset])
else:
res = db.fetchall("SELECT c.comment_id, c.to_comment_id,"
"c.author AS user_id, ui1.name,"
"CASE WHEN c.anon_login IS NOT NULL "
"THEN c.anon_login ELSE u1.login END AS login,"
"c.created at time zone %%s AS created, "
"c.text, c.files, "
"c.updated at time zone %%s AS updated, "
"CASE WHEN rc.comment_id IS NOT NULL "
"THEN true ELSE false END AS is_rec, "
"false AS recommended, "
"false AS bookmarked, "
"ui1.avatar "
"FROM posts.comments c "
"JOIN users.logins u1 ON c.author=u1.id "
"LEFT OUTER JOIN users.info ui1 "
"ON ui1.id=c.author "
"LEFT OUTER JOIN posts.recommendations rc "
"ON rc.post_id=c.post_id "
"AND rc.rcid=c.comment_id "
"WHERE c.post_id=%%s AND c.comment_id>=%%s "
"ORDER BY c.created%s%s;" % (order, lim),
[self.tz, self.tz, unb26(self.id), offset])
if last:
res.reverse()
if cuser:
unr = db.fetchall("SELECT comment_id FROM posts.unread_comments "
"WHERE user_id=%s AND post_id=%s;",
[cuser.id, unb26(self.id)])
unread = { r['comment_id']: 1 for r in unr }
else:
unread = {}
comments = []
for c in res:
author = User.from_data(c['user_id'], c['login'],
info={'name': c['name'], 'avatar': c['avatar']})
unr = True if c['comment_id'] in unread else False
comment = Comment.from_data(self, id=c['comment_id'],
to_comment_id=c['to_comment_id'],
author=author,
created=c['created'],
text=c['text'],
recommended=c['recommended'],
bookmarked=c['bookmarked'],
is_rec=c['is_rec'],
files=c['files'],
updated=c['updated'],
unread=unr)
comments.append(comment)
#.........这里部分代码省略.........
示例8: User
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import set [as 别名]
class User(object):
type = 'user'
def __init__(self, field, value=None):
self.id = None
self.login = None
self.accounts = []
self.accounts_add = []
self.accounts_del = []
self.profile = {}
self.profile_upd = {}
self.info = {}
self.info_upd = {}
self.password = None
self._private = None
self.redis = RedisPool(settings.storage_socket)
if isinstance(field, (int, long)):
self.id = field
self.login = cache_get('login:%s' % field)
if not self.login:
res = db.fetchone("SELECT login FROM users.logins WHERE id=%s;",
[field])
if not res:
raise UserNotFound
self.login = res[0]
cache_store('login:%s' % field, self.login)
return
if not value:
#raise UserNotFound
# empty user
return
if field == 'login':
r = cache_get('id_login:%s' % value.lower())
if r:
try:
self.id, self.login, self.type = r
except ValueError:
self.id, self.login = r
self.type = 'user'
else:
res = db.fetchone("SELECT id, login, type FROM users.logins "
"WHERE lower(login)=%s;",
[str(value).lower()])
if not res:
raise UserNotFound(value)
self.id, self.login, self.type = res
cache_store('id_login:%s' % value.lower(), [res[0], res[1], res[2]])
return
r = cache_get('addr_id_login:%s' % value.lower())
if r:
self.id, self.login = r
else:
res = db.fetchone("SELECT u.id, u.login FROM users.accounts a "
"JOIN users.logins u ON u.id=a.user_id "
"WHERE a.type=%s AND a.address=%s;",
[field, value]) #, _cache=3600)
if res:
self.id, self.login = res
cache_store('addr_id_login:%s' % value.lower(),[res[0], res[1]])
def __repr__(self):
return "<User: id=%s login=%s>" % (self.id, self.login)
def __cmp__(self, other):
if not isinstance(other, User):
raise TypeError
if not self.id or not other.id:
return False
return self.id - other.id
@classmethod
def from_data(cls, id, login, **kwargs):
self = cls(None, None)
self.id = id
self.login = login
if 'accounts' in kwargs:
for type, address in kwargs['accounts']:
if type in ACCOUNT_TYPES and not parse_email(address):
raise ValueError(address)
self.accounts = kwargs['accounts']
if 'profile' in kwargs:
self.profile = kwargs['profile']
if 'info' in kwargs:
self.info = kwargs['info']
if 'password' in kwargs and kwargs['password']:
self.set_password(kwargs['password'])
#self.info = {}
return self
@staticmethod
def _passhash(password):
#.........这里部分代码省略.........
示例9: save_sessions
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import set [as 别名]
def save_sessions(user, sessions):
redis = RedisPool(settings.session_socket)
redis.set(_sessions_key(user.id), json.dumps(sessions))