def _bump_timestamp(self, collection_id, parent_id, record=None,
modified_field=None, last_modified=None):
key = '{0}.{1}.timestamp'.format(collection_id, parent_id)
while 1:
with self._client.pipeline() as pipe:
try:
pipe.watch(key)
previous = pipe.get(key)
pipe.multi()
# XXX factorize code from memory and redis backends.
is_specified = (record is not None and
modified_field in record or
last_modified is not None)
if is_specified:
# If there is a timestamp in the new record,
# try to use it.
if last_modified is not None:
current = last_modified
else:
current = record[modified_field]
else:
current = utils.msec_time()
if previous and int(previous) >= current:
collection_timestamp = int(previous) + 1
else:
collection_timestamp = current
# Return the newly generated timestamp as the current one
# only if nothing else was specified.
is_equal = previous and int(previous) == current
if not is_specified or is_equal:
current = collection_timestamp
pipe.set(key, collection_timestamp)
pipe.execute()
return current
except redis.WatchError: # pragma: no cover
# Our timestamp has been modified by someone else, let's
# retry.
# XXX: untested.
continue
评论列表
文章目录