當前位置: 首頁>>代碼示例>>Python>>正文


Python StrictRedis.pipeline方法代碼示例

本文整理匯總了Python中redis.client.StrictRedis.pipeline方法的典型用法代碼示例。如果您正苦於以下問題:Python StrictRedis.pipeline方法的具體用法?Python StrictRedis.pipeline怎麽用?Python StrictRedis.pipeline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.client.StrictRedis的用法示例。


在下文中一共展示了StrictRedis.pipeline方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: details

# 需要導入模塊: from redis.client import StrictRedis [as 別名]
# 或者: from redis.client.StrictRedis import pipeline [as 別名]
def details(topic, pages):
    client = StrictRedis()
    with client.pipeline(transaction=False) as pipeline:
        pipeline.hgetall(topic)
        pipeline.zcard('{}/pages'.format(topic))
        pipeline.zrange('{}/pages'.format(topic), pages * -1, -1, withscores=True)
        results = pipeline.execute()

    def header(label):
        return '\n'.join(('-' * 80, label, '-' * 80))

    print header('CONFIGURATION')
    print tabulate.tabulate(results[0].items(), headers=('key', 'value'))

    print ''

    print header('PAGES ({} total)'.format(results[1]))
    print tabulate.tabulate(results[2], headers=('page', 'offset'))
開發者ID:tkaemming,項目名稱:kafkaesque,代碼行數:20,代碼來源:__main__.py

示例2: RedisCache

# 需要導入模塊: from redis.client import StrictRedis [as 別名]
# 或者: from redis.client.StrictRedis import pipeline [as 別名]
class RedisCache(CacheBase):
    def __init__(self, config, section):
        from redis.client import StrictRedis
        self.conn = StrictRedis(
            config.get(section, 'redis-server'),
            config.getint(section, 'redis-port'),
            config.getint(section, 'redis-db'),
            decode_responses=True
        )

    def check_password(self, user, password):
        """Check the given user and password.

        Returns None on cache miss, True if password matches, False if not.
        """
        cached = self.conn.get(self.prefix('%s-pass' % user))
        if cached is None:
            return cached
        else:
            return cached == self.hash(password, cached)

    def set_password(self, user, password):
        self.conn.set(self.prefix('%s-pass' % user), self.hash(password, None), ex=self.expire)

    def in_groups(self, user, groups):
        key = self.prefix('%s-groups' % user)
        if not self.conn.exists(key):
            return None

        return not self.conn.smembers(key).isdisjoint(groups)

    def set_groups(self, user, groups):
        key = self.prefix('%s-groups' % user)
        pipe = self.conn.pipeline()
        pipe.sadd(key, *groups).expire(key, self.expire)
        pipe.execute()
開發者ID:RestAuth,項目名稱:apache2-extauth,代碼行數:38,代碼來源:restauth-extauth.py

示例3: RedisStore

# 需要導入模塊: from redis.client import StrictRedis [as 別名]
# 或者: from redis.client.StrictRedis import pipeline [as 別名]
class RedisStore():
    def __init__(self, db_host, db_port, db_num, db_pw):
        self.pool = ConnectionPool(max_connections=2, db=db_num, host=db_host, port=db_port, password=db_pw,
                                   decode_responses=True)
        self.redis = StrictRedis(connection_pool=self.pool)
        self.redis.ping()
        self._object_map = WeakValueDictionary()

    def create_object(self, dbo_class, dbo_dict, update_timestamp=True):
        dbo_class = get_dbo_class(getattr(dbo_class, 'dbo_key_type', dbo_class))
        if not dbo_class:
            return
        try:
            dbo_id = dbo_dict['dbo_id']
        except KeyError:
            dbo_id, dbo_dict = dbo_dict, {}
        if dbo_id is None or dbo_id == '':
            warn("create_object called with empty dbo_id")
            return
        dbo_id = str(dbo_id).lower()
        if self.object_exists(dbo_class.dbo_key_type, dbo_id):
            raise ObjectExistsError(dbo_id)
        dbo = dbo_class()
        dbo.dbo_id = dbo_id
        dbo.hydrate(dbo_dict)
        dbo.db_created()
        if dbo.dbo_set_key:
            self.redis.sadd(dbo.dbo_set_key, dbo.dbo_id)
        self.save_object(dbo, update_timestamp)
        return dbo

    def save_object(self, dbo, update_timestamp=False, autosave=False):
        if update_timestamp:
            dbo.dbo_ts = int(time.time())
        if dbo.dbo_indexes:
            self._update_indexes(dbo)
        self._clear_old_refs(dbo)
        save_root, new_refs = dbo.to_db_value()
        self.redis.set(dbo.dbo_key, json_encode(save_root))
        if new_refs:
            self._set_new_refs(dbo, new_refs)
        debug("db object {} {}saved", dbo.dbo_key, "auto" if autosave else "")
        self._object_map[dbo.dbo_key] = dbo
        return dbo

    def save_raw(self, key, raw):
        self.redis.set(key, json_encode(raw))

    def load_raw(self, key, default=None):
        json = self.redis.get(key)
        if json:
            return json_decode(json)
        return default

    def load_cached(self, dbo_key):
        return self._object_map.get(dbo_key)

    def load_object(self, dbo_key, key_type=None, silent=False):
        if key_type:
            try:
                key_type = key_type.dbo_key_type
            except AttributeError:
                pass
            try:
                dbo_key, dbo_id = ':'.join([key_type, dbo_key]), dbo_key
            except TypeError:
                if not silent:
                    exception("Invalid dbo_key passed to load_object", stack_info=True)
                return
        else:
            key_type, _, dbo_id = dbo_key.partition(':')
        cached_dbo = self._object_map.get(dbo_key)
        if cached_dbo:
            return cached_dbo
        json_str = self.redis.get(dbo_key)
        if not json_str:
            if not silent:
                warn("Failed to find {} in database", dbo_key)
            return
        return self.load_from_json(json_str, key_type, dbo_id)

    def load_from_json(self, json_str, key_type, dbo_id):
        dbo_dict = json_decode(json_str)
        dbo = get_mixed_type(key_type, dbo_dict.get('mixins'))()
        dbo.dbo_id = dbo_id
        self._object_map[dbo.dbo_key] = dbo
        dbo.hydrate(dbo_dict)
        return dbo

    def object_exists(self, obj_type, obj_id):
        return self.redis.exists('{}:{}'.format(obj_type, obj_id))

    def load_object_set(self, dbo_class, set_key=None):
        key_type = dbo_class.dbo_key_type
        if not set_key:
            set_key = dbo_class.dbo_set_key
        results = set()
        keys = deque()
        pipeline = self.redis.pipeline()
        for key in self.fetch_set_keys(set_key):
#.........這裏部分代碼省略.........
開發者ID:cookiezeater,項目名稱:Lampost-Mud,代碼行數:103,代碼來源:redisstore.py


注:本文中的redis.client.StrictRedis.pipeline方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。