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


Python _compat.b函数代码示例

本文整理汇总了Python中redis._compat.b函数的典型用法代码示例。如果您正苦于以下问题:Python b函数的具体用法?Python b怎么用?Python b使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_sort_all_options

    def test_sort_all_options(self, r):
        r["user:1:username"] = "zeus"
        r["user:2:username"] = "titan"
        r["user:3:username"] = "hermes"
        r["user:4:username"] = "hercules"
        r["user:5:username"] = "apollo"
        r["user:6:username"] = "athena"
        r["user:7:username"] = "hades"
        r["user:8:username"] = "dionysus"

        r["user:1:favorite_drink"] = "yuengling"
        r["user:2:favorite_drink"] = "rum"
        r["user:3:favorite_drink"] = "vodka"
        r["user:4:favorite_drink"] = "milk"
        r["user:5:favorite_drink"] = "pinot noir"
        r["user:6:favorite_drink"] = "water"
        r["user:7:favorite_drink"] = "gin"
        r["user:8:favorite_drink"] = "apple juice"

        r.rpush("gods", "5", "8", "3", "1", "2", "7", "6", "4")
        num = r.sort(
            "gods",
            start=2,
            num=4,
            by="user:*:username",
            get="user:*:favorite_drink",
            desc=True,
            alpha=True,
            store="sorted",
        )
        assert num == 4
        assert r.lrange("sorted", 0, 10) == [b("vodka"), b("milk"), b("gin"), b("apple juice")]
开发者ID:Krave-n,项目名称:redis-py,代码行数:32,代码来源:test_commands.py

示例2: test_zunionstore_sum

 def test_zunionstore_sum(self, r):
     r.zadd('a', a1=1, a2=1, a3=1)
     r.zadd('b', a1=2, a2=2, a3=2)
     r.zadd('c', a1=6, a3=5, a4=4)
     assert r.zunionstore('d', ['a', 'b', 'c']) == 4
     assert r.zrange('d', 0, -1, withscores=True) == \
         [(b('a2'), 3), (b('a4'), 4), (b('a3'), 8), (b('a1'), 9)]
开发者ID:pepijndevos,项目名称:redis-py,代码行数:7,代码来源:test_commands.py

示例3: test_zunionstore_min

 def test_zunionstore_min(self, r):
     r.zadd('a', a1=1, a2=2, a3=3)
     r.zadd('b', a1=2, a2=2, a3=4)
     r.zadd('c', a1=6, a3=5, a4=4)
     assert r.zunionstore('d', ['a', 'b', 'c'], aggregate='MIN') == 4
     assert r.zrange('d', 0, -1, withscores=True) == \
         [(b('a1'), 1), (b('a2'), 2), (b('a3'), 3), (b('a4'), 4)]
开发者ID:pepijndevos,项目名称:redis-py,代码行数:7,代码来源:test_commands.py

示例4: test_zscan

 def test_zscan(self, r):
     r.zadd('a', 'a', 1, 'b', 2, 'c', 3)
     cursor, pairs = r.zscan('a')
     assert cursor == b('0')
     assert set(pairs) == set([(b('a'), 1), (b('b'), 2), (b('c'), 3)])
     _, pairs = r.zscan('a', match='a')
     assert set(pairs) == set([(b('a'), 1)])
开发者ID:pepijndevos,项目名称:redis-py,代码行数:7,代码来源:test_commands.py

示例5: test_sinterstore

 def test_sinterstore(self, r):
     r.sadd('a', '1', '2', '3')
     assert r.sinterstore('c', 'a', 'b') == 0
     assert r.smembers('c') == set()
     r.sadd('b', '2', '3')
     assert r.sinterstore('c', 'a', 'b') == 2
     assert r.smembers('c') == set([b('2'), b('3')])
开发者ID:pepijndevos,项目名称:redis-py,代码行数:7,代码来源:test_commands.py

示例6: pack_command

    def pack_command(self, *args):
        "Pack a series of arguments into the Redis protocol"
        output = []
        # the client might have included 1 or more literal arguments in
        # the command name, e.g., 'CONFIG GET'. The Redis server expects these
        # arguments to be sent separately, so split the first argument
        # manually. All of these arguements get wrapped in the Token class
        # to prevent them from being encoded.
        command = args[0]
        if ' ' in command:
            args = tuple([Token(s) for s in command.split(' ')]) + args[1:]
        else:
            args = (Token(command),) + args[1:]

        buff = SYM_EMPTY.join(
            (SYM_STAR, b(str(len(args))), SYM_CRLF))

        for arg in imap(self.encode, args):
            # to avoid large string mallocs, chunk the command into the
            # output list if we're sending large values
            if len(buff) > self._buffer_cutoff or \
               len(arg) > self._buffer_cutoff:
                buff = SYM_EMPTY.join(
                    (buff, SYM_DOLLAR, b(str(len(arg))), SYM_CRLF))
                output.append(buff)
                output.append(arg)
                buff = SYM_CRLF
            else:
                buff = SYM_EMPTY.join((buff, SYM_DOLLAR, b(str(len(arg))),
                                       SYM_CRLF, arg, SYM_CRLF))
        output.append(buff)
        return output
开发者ID:joshowen,项目名称:redis-py,代码行数:32,代码来源:connection.py

示例7: test_decr

 def test_decr(self, r):
     assert r.decr('a') == -1
     assert r['a'] == b('-1')
     assert r.decr('a') == -2
     assert r['a'] == b('-2')
     assert r.decr('a', amount=5) == -7
     assert r['a'] == b('-7')
开发者ID:pepijndevos,项目名称:redis-py,代码行数:7,代码来源:test_commands.py

示例8: test_script_object_in_pipeline

    def test_script_object_in_pipeline(self, r):
        multiply = r.register_script(multiply_script)
        precalculated_sha = multiply.sha
        assert precalculated_sha
        pipe = r.pipeline()
        pipe.set('a', 2)
        pipe.get('a')
        multiply(keys=['a'], args=[3], client=pipe)
        assert r.script_exists(multiply.sha) == [False]
        # [SET worked, GET 'a', result of multiple script]
        assert pipe.execute() == [True, b('2'), 6]
        # The script should have been loaded by pipe.execute()
        assert r.script_exists(multiply.sha) == [True]
        # The precalculated sha should have been the correct one
        assert multiply.sha == precalculated_sha

        # purge the script from redis's cache and re-run the pipeline
        # the multiply script should be reloaded by pipe.execute()
        r.script_flush()
        pipe = r.pipeline()
        pipe.set('a', 2)
        pipe.get('a')
        multiply(keys=['a'], args=[3], client=pipe)
        assert r.script_exists(multiply.sha) == [False]
        # [SET worked, GET 'a', result of multiple script]
        assert pipe.execute() == [True, b('2'), 6]
        assert r.script_exists(multiply.sha) == [True]
开发者ID:cola1129,项目名称:redis-py,代码行数:27,代码来源:test_scripting.py

示例9: test_zscan

 def test_zscan(self, r):
     r.zadd("a", "a", 1, "b", 2, "c", 3)
     cursor, pairs = r.zscan("a")
     assert cursor == 0
     assert set(pairs) == set([(b("a"), 1), (b("b"), 2), (b("c"), 3)])
     _, pairs = r.zscan("a", match="a")
     assert set(pairs) == set([(b("a"), 1)])
开发者ID:Krave-n,项目名称:redis-py,代码行数:7,代码来源:test_commands.py

示例10: test_sdiffstore

 def test_sdiffstore(self, r):
     r.sadd("a", "1", "2", "3")
     assert r.sdiffstore("c", "a", "b") == 3
     assert r.smembers("c") == set([b("1"), b("2"), b("3")])
     r.sadd("b", "2", "3")
     assert r.sdiffstore("c", "a", "b") == 1
     assert r.smembers("c") == set([b("1")])
开发者ID:Krave-n,项目名称:redis-py,代码行数:7,代码来源:test_commands.py

示例11: test_sscan

 def test_sscan(self, r):
     r.sadd("a", 1, 2, 3)
     cursor, members = r.sscan("a")
     assert cursor == 0
     assert set(members) == set([b("1"), b("2"), b("3")])
     _, members = r.sscan("a", match=b("1"))
     assert set(members) == set([b("1")])
开发者ID:Krave-n,项目名称:redis-py,代码行数:7,代码来源:test_commands.py

示例12: test_incr

 def test_incr(self, r):
     assert r.incr("a") == 1
     assert r["a"] == b("1")
     assert r.incr("a") == 2
     assert r["a"] == b("2")
     assert r.incr("a", amount=5) == 7
     assert r["a"] == b("7")
开发者ID:Krave-n,项目名称:redis-py,代码行数:7,代码来源:test_commands.py

示例13: test_script_object_in_pipeline

    def test_script_object_in_pipeline(self, r):
        multiply = r.register_script(multiply_script)
        assert not multiply.sha
        pipe = r.pipeline()
        pipe.set('a', 2)
        pipe.get('a')
        multiply(keys=['a'], args=[3], client=pipe)
        # even though the pipeline wasn't executed yet, we made sure the
        # script was loaded and got a valid sha
        assert multiply.sha
        assert r.script_exists(multiply.sha) == [True]
        # [SET worked, GET 'a', result of multiple script]
        assert pipe.execute() == [True, b('2'), 6]

        # purge the script from redis's cache and re-run the pipeline
        # the multiply script object knows it's sha, so it shouldn't get
        # reloaded until pipe.execute()
        r.script_flush()
        pipe = r.pipeline()
        pipe.set('a', 2)
        pipe.get('a')
        assert multiply.sha
        multiply(keys=['a'], args=[3], client=pipe)
        assert r.script_exists(multiply.sha) == [False]
        # [SET worked, GET 'a', result of multiple script]
        assert pipe.execute() == [True, b('2'), 6]
开发者ID:baranbartu,项目名称:redis-py-cluster,代码行数:26,代码来源:test_scripting.py

示例14: test_zinterstore_sum

 def test_zinterstore_sum(self, r):
     r.zadd('a{foo}', a1=1, a2=1, a3=1)
     r.zadd('b{foo}', a1=2, a2=2, a3=2)
     r.zadd('c{foo}', a1=6, a3=5, a4=4)
     assert r.zinterstore('d{foo}', ['a{foo}', 'b{foo}', 'c{foo}']) == 2
     assert r.zrange('d{foo}', 0, -1, withscores=True) == \
         [(b('a3'), 8), (b('a1'), 9)]
开发者ID:baranbartu,项目名称:redis-py-cluster,代码行数:7,代码来源:test_commands.py

示例15: test_pipeline_no_transaction

 def test_pipeline_no_transaction(self):
     with self.client.pipeline(transaction=False) as pipe:
         pipe.set('a', 'a1').set('b', 'b1').set('c', 'c1')
         self.assertEquals(pipe.execute(), [True, True, True])
         self.assertEquals(self.client['a'], b('a1'))
         self.assertEquals(self.client['b'], b('b1'))
         self.assertEquals(self.client['c'], b('c1'))
开发者ID:SLilac,项目名称:redis-py,代码行数:7,代码来源:pipeline.py


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