当前位置: 首页>>代码示例>>Python>>正文


Python RedisPool.get方法代码示例

本文整理汇总了Python中point.util.redispool.RedisPool.get方法的典型用法代码示例。如果您正苦于以下问题:Python RedisPool.get方法的具体用法?Python RedisPool.get怎么用?Python RedisPool.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在point.util.redispool.RedisPool的用法示例。


在下文中一共展示了RedisPool.get方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: comments_count

# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import get [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
开发者ID:artss,项目名称:point-core,代码行数:33,代码来源:post.py

示例2: last_published

# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import get [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())
开发者ID:isqua-test,项目名称:point-core,代码行数:30,代码来源:__init__.py

示例3: user_sessions

# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import get [as 别名]
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 []
开发者ID:isqua-test,项目名称:point-core,代码行数:10,代码来源:sessions.py

示例4: login_key

# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import get [as 别名]
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))
开发者ID:artss,项目名称:point-www-new,代码行数:17,代码来源:auth.py

示例5: reset_password

# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import get [as 别名]
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
开发者ID:postman0,项目名称:point-core,代码行数:17,代码来源:users.py

示例6: User

# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import get [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):
#.........这里部分代码省略.........
开发者ID:isqua-test,项目名称:point-core,代码行数:103,代码来源:user.py

示例7: reg_invite

# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import get [as 别名]
def reg_invite(key):
    redis = RedisPool(settings.storage_socket)
    if not redis.get('invite:%s' % key):
        return 'Invalid key'

    return reg_invite_set_login(key)
开发者ID:radjah,项目名称:point-xmpp,代码行数:8,代码来源:users.py

示例8: cache_get

# 需要导入模块: from point.util.redispool import RedisPool [as 别名]
# 或者: from point.util.redispool.RedisPool import get [as 别名]
def cache_get(key):
    log.debug("cache_get %s" % key)
    redis = RedisPool(settings.cache_socket)
    data = redis.get(key)
    if data:
        return json.loads(data)
开发者ID:isqua-test,项目名称:point-core,代码行数:8,代码来源:__init__.py


注:本文中的point.util.redispool.RedisPool.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。