def compact_bucket(db, buck_key, limit):
<EOL>records = db.lrange(str(buck_key), <NUM_LIT:0>, -<NUM_LIT:1>)<EOL>loader = limits.BucketLoader(limit.bucket_class, db, limit,<EOL>str(buck_key), records, stop_summarize=True)<EOL>buck_record = msgpack.dumps(dict(bucket=loader.bucket.dehydrate(),<EOL>uuid=str(uuid.uuid4())))<EOL>result = db.linsert(str(buck_key), '<STR_LIT>', loader.last_summarize_rec,<EOL>buck_record)<EOL>if result < <NUM_LIT:0>:<EOL><INDENT>LOG.warning("<STR_LIT>" % buck_key)<EOL>return<EOL><DEDENT>db.ltrim(str(buck_key), loader.last_summarize_idx + <NUM_LIT:1>, -<NUM_LIT:1>)<EOL>
Perform the compaction operation.  This reads in the bucket
information from the database, builds a compacted bucket record,
inserts that record in the appropriate place in the database, then
removes outdated updates.

:param db: A database handle for the Redis database.
:param buck_key: A turnstile.limits.BucketKey instance containing
                 the bucket key.
:param limit: The turnstile.limits.Limit object corresponding to
              the bucket.