您的购物车目前是空的!
排序集合:
# Rename the key newkey = "gc:hashes:" + redis.INCR("gc:index") redis.RENAME("my.zset.key", newkey) # Delete members from the sorted set in batche of 100s while redis.ZCARD(newkey) > 0 redis.ZREMRANGEBYRANK(newkey, 0, 99) end
集合:
# Rename the key newkey = "gc:hashes:" + redis.INCR("gc:index") redis.RENAME("my.set.key", newkey) # Delete members from the set in batches of 100 cursor = 0 loop cursor, members = redis.SSCAN(newkey, cursor, "COUNT", 100) if size of members > 0 redis.SREM(newkey, members) end if cursor == 0 break end end
列表:
# Rename the key newkey = "gc:hashes:" + redis.INCR("gc:index") redis.RENAME("my.list.key", newkey) # Trim off elements in batche of 100s while redis.LLEN(newkey) > 0 redis.LTRIM(newkey, 0, -99) end
Hash:
# Rename the key newkey = "gc:hashes:" + redis.INCR( "gc:index" ) redis.RENAME("my.hash.key", newkey) # Delete fields from the hash in batche of 100s cursor = 0 loop cursor, hash_keys = redis.HSCAN(newkey, cursor, "COUNT", 100) if hash_keys count > 0 redis.HDEL(newkey, hash_keys) end if cursor == 0 break end end
logger@BIGD1TMP:~> redis-benchmark -q -r 100000 -n 1000000 -c 50 PING_INLINE: 90155.07 requests per second PING_BULK: 92302.02 requests per second SET: 85070.18 requests per second GET: 86184.61 requests per second logger@BIGD1TMP:~> redis-benchmark -q -r 100000 -n 1000000 -c 50 -P 10 PING_INLINE: 558035.69 requests per second PING_BULK: 668002.69 requests per second SET: 275027.50 requests per second GET: 376647.84 requests per second logger@BIGD1TMP:~> redis-benchmark -q -r 100000 -n 1000000 -c 50 -P 20 PING_INLINE: 705716.25 requests per second PING_BULK: 869565.25 requests per second SET: 343406.59 requests per second GET: 459347.72 requests per second logger@BIGD1TMP:~> redis-benchmark -q -r 100000 -n 1000000 -c 50 -P 50 PING_INLINE: 940733.81 requests per second PING_BULK: 1317523.00 requests per second SET: 380807.31 requests per second GET: 523834.47 requests per second logger@BIGD1TMP:~> redis-benchmark -q -r 100000 -n 1000000 -c 50 -P 100 PING_INLINE: 999000.94 requests per second PING_BULK: 1440922.12 requests per second SET: 386996.88 requests per second GET: 602046.94 requests per second logger@BIGD1TMP:~> redis-benchmark -q -r 100000 -n 1000000 -c 50 -P 200 PING_INLINE: 1078748.62 requests per second PING_BULK: 1381215.50 requests per second SET: 379218.81 requests per second GET: 537634.38 requests per second
一个场景是一个购物车的设计,一般的设计思路是:
在获取购物车内部货品时,不使用pipeline会很低效:
可以修改为: