Хабр Курсы для всех
РЕКЛАМА
Большая витрина: от крупнейших школ до частных авторов. Сравнивайте по цене, длительности, формату и выбирайте самый подходящий курс!
$value = $rediska->get('test_value');The first try may be the following:
val = GET mykey val = val + 1 SET mykey $val
This will work reliably only if we have a single client performing the operation in a given time…
Thanks to WATCH we are able to model the problem very well:
WATCH mykey val = GET mykey val = val + 1 MULTI SET mykey $val EXEC
Using the above code, if there are race conditions and another client modifies the result of val in the time between our call to WATCH and our call to EXEC, the transaction will fail.
# -*- coding: utf-8 -*-
import redis
r = redis.StrictRedis(host='localhost', port=6379, db=0)
# Test
for i in xrange(1, 10001):
print r.incr('test-key')
python test.py &
python test.py &
python test.py &
python test.py &
Как же работают транзакции в Redis