本文整理汇总了Python中point.util.redispool.RedisPool.expire方法的典型用法代码示例。如果您正苦于以下问题:Python RedisPool.expire方法的具体用法?Python RedisPool.expire怎么用?Python RedisPool.expire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类point.util.redispool.RedisPool
的用法示例。
在下文中一共展示了RedisPool.expire方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import expire [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)
示例2: cache_store
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import expire [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)
示例3: gen_invite
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import expire [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
示例4: request_password
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import expire [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})
示例5: User
# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import expire [as 别名]
#.........这里部分代码省略.........
[self.id, res['type'], res['address']])
except IntegrityError:
log.error("%s %s already exists" % (res['type'], res['address']))
return False
cache_del("addr_id_login:%s" % res['address'])
return True
def del_account(self, type, address):
self.accounts_del.append((type, address))
cache_del("addr_id_login:%s" % address)
def set_active_account(self, type, address):
if not self.id:
return
if type not in ACCOUNT_TYPES:
return
self.redis.set('active.%d' % self.id,
json.dumps({'type':type, 'addr': address}))
def get_active_account(self, type=None):
if not self.id:
return None
data = self.redis.get('active.%d' % self.id)
if data:
data = json.loads(data)
else:
_type = type if type else 'xmpp'
res = db.fetchone("SELECT type, address FROM users.accounts WHERE "
"user_id=%s AND type=%s;", [self.id, _type])
if not res:
self.redis.set('active.%d' % self.id, '{}')
self.redis.expire('active.%d' % self.id, 60)
return None
self.redis.set('active.%d' % self.id,
json.dumps({'type': _type, 'addr': res['address']}))
data = {'type': res['type'], 'addr': res['address']}
if not type:
return data
try:
if data['type'] == type:
return data['addr']
except KeyError:
return None
return None
_profile_table = 'users.profile'
_profile = {
'private': {'type': 'bool', 'default': False},
'lang': {'type': 'str', 're': re.compile(r'^[a-z]{2}$'),
'default':settings.lang},
'tz': {'type': 'int', 'default': settings.timezone},
'deny_anonymous': {'type': 'bool', 'default': False}
}
def set_profile(self, param, value):
def check(p, param, value):
if p[param]['type'] == 'bool':
if isinstance(value, (str, unicode)):
if value.lower() in ['no', 'false', 'none', 'null', '0']:
value = False
else:
value = True