def test_cappedsortedset_normal(): conn = Redis(db=1) conn.flushall() cs = CappedSortedSet('test', 5, conn=conn) for member, score in [(1, 1), (3, 3), (5, 5), (7, 7), (9, 9), (2, 2), (4, 4), (6, 6)]: cs.zadd(member, score) assert cs.zrange(0, -1) == ['4', '5', '6', '7', '9']
def test_cappedsortedset_shard(): conn = ShardRedis(conns=[Redis(db=1), Redis(db=2), Redis(db=3), Redis(db=4)]) conn.flushall() cs = CappedSortedSet('test', 5, conn=conn, skey='test') for member, score in [(1, 1), (3, 3), (5, 5), (7, 7), (9, 9), (2, 2), (4, 4), (6, 6)]: cs.zadd(member, score) assert cs.zrange(0, -1) == ['4', '5', '6', '7', '9']
def test_cappedsortedset_shard(): conn = ShardRedis( conns=[Redis(db=1), Redis( db=2), Redis( db=3), Redis(db=4)]) conn.flushall() cs = CappedSortedSet('test', 5, conn=conn, skey='test') for member, score in [(1, 1), (3, 3), (5, 5), (7, 7), (9, 9), (2, 2), (4, 4), (6, 6)]: cs.zadd(member, score) assert cs.zrange(0, -1) == ['4', '5', '6', '7', '9']
def incrindex(self, cate1, cate2, field, monorday, itemid, amount): zkey = ItemIndex.itemindex.format(self.date, cate1, cate2, field, monorday) p = self.conn if self.pipeline is None else self.pipeline CappedSortedSet(zkey, 1000, p, skey=self.make_skey(cate1, cate2)).zadd(itemid, amount)
def addhots(self, brand, cate2, itemid, shopid, sales): p = self.conn if self.pipeline is None else self.pipeline zkey1 = BrandIndex.brandhotitems.format(self.date, brand, cate2) zkey2 = BrandIndex.brandhotshops.format(self.date, brand, cate2) CappedSortedSet(zkey1, 10, p, skey=zkey1).zadd(itemid, sales) CappedSortedSet(zkey2, 10, p, skey=zkey2).zadd(shopid, sales)
def setindex(self, brand, cate1, cate2, sales): p = self.conn if self.pipeline is None else self.pipeline c12 = self.make_skey(cate1, cate2) zkey = BrandIndex.brandindex.format(self.date, cate1, cate2, 'sales') CappedSortedSet(zkey, 1000, p, skey=c12).zadd(brand, sales)
def addhotitems(self, shopid, itemid, sales): zkey = ShopIndex.shophotitems.format(self.date, shopid) p = self.conn if self.pipeline is None else self.pipeline # equals to p.zadd(zkey, itemid, sales), capped to 10, shared by skey CappedSortedSet(zkey, 10, p, skey=zkey).zadd(itemid, sales)