python访问redis数据库

#!/usr/env/bin python

import redis

r=redis.Redis(host='localhost',port=6379,db=0)

with r.pipeline() as pipe:

    while 1:

        try:

            pipe.watch('OUR-SEQUENCE-KEY')

            current_value=pipe.get('OUR-SEQUENCE-KEY')

            next_value=int(current_value)+1

            pipe.multi()

            pipe.set('OUR-SEQUENCE-KEY',next_value)

            pipe.execute()

            break

        except WatchError:

            continue

你可能感兴趣的:(python访问redis数据库)