是否可以使用multi.incr(value)
和multi.hmset
?Redis - 在交易中使用Incr值
我的意思是:
var name = 'Josh';
var multi = client.multi();
multi.incr('id'); // incr => 1
multi.hmset('user:' + <need incr value here>, 'username', name);
// I want multi.hmset('user:1', 'username', 'Josh');
multi.exec(function(err,data){ .. });
我的目標是增加「ID」,然後將其設置爲一個交易的用戶ID。我已閱讀,我需要做client.watch('id')
,但我不明白如何使用它。
PD:請用後的代碼你的回答,是最好的方式:)
這應該是公認的答案 –
@GeigeV完全 - 很樂意刪除我的,如果OP不接受它 –
@ItamarHaber好的,讓我接受這個答案,但是,當我在2015年問這個問題時,你是唯一一個誰回答了我的問題,而且這些代碼也起作用。一如既往:Toda&Shalom! – robe007