| 383 | has_run = [] |
| 384 | |
| 385 | def my_transaction(pipe): |
| 386 | a_value = pipe.get(f"{hashkey}:a") |
| 387 | assert a_value in (b"1", b"2") |
| 388 | b_value = pipe.get(f"{hashkey}:b") |
| 389 | assert b_value == b"2" |
| 390 | |
| 391 | # silly run-once code... incr's "a" so WatchError should be raised |
| 392 | # forcing this all to run again. this should incr "a" once to "2" |
| 393 | if not has_run: |
| 394 | r.incr(f"{hashkey}:a") |
| 395 | has_run.append("it has") |
| 396 | |
| 397 | pipe.multi() |
| 398 | pipe.set(f"{hashkey}:c", int(a_value) + int(b_value)) |
| 399 | |
| 400 | result = r.transaction(my_transaction, f"{hashkey}:a", f"{hashkey}:b") |
| 401 | assert result == [b"OK"] |