예제 #1
0
    def test_map_to_list(self):
        self.mapper.map(query=self.query).to_list(key_pattern='list:{0}', \
                transform=take_nth(1))
        self.mapper.run()

        self.common_asserts()
        self.redis.pipeline().lpush.assert_any_call('list:1', 'A')
        self.redis.pipeline().lpush.assert_any_call('list:2', 'B')
예제 #2
0
    def test_map_to_string(self):
        self.mapper.map(query=self.query).to_string(key_pattern='row:{id}',
                transform = take_nth(1))
        self.mapper.run()

        self.common_asserts()
        self.redis.pipeline().set.assert_any_call('row:1', 'A')
        self.redis.pipeline().set.assert_any_call('row:2', 'B')
예제 #3
0
    def test_map_to_sorted_set_by_score_value(self):
        self.mapper.map(query=self.query) \
                .to_sorted_set(key_pattern='zset:{id}', \
                transform=take_nth(1), score=2.0)
        self.mapper.run()

        self.common_asserts()
        self.redis.pipeline().zadd.assert_any_call('zset:1', 2.0, 'A')
        self.redis.pipeline().zadd.assert_any_call('zset:2', 2.0, 'B')
예제 #4
0
    def test_map_to_sorted_set_by_score_column_number(self):
        self.db = mock_db(('id', 'name', 'salary'), \
                [(1, 'A', 5), (2, 'B', 6), None])
        self.mapper = Db2RedisMapper(self.db, self.redis)

        self.mapper.map(query=self.query) \
                .to_sorted_set(key_pattern='zset:{id}', \
                transform=take_nth(1), score=2)
        self.mapper.run()

        self.common_asserts()
        self.redis.pipeline().zadd.assert_any_call('zset:1', 5, 'A')
        self.redis.pipeline().zadd.assert_any_call('zset:2', 6, 'B')