Open2

Redisについてメモ

zakkyzakky

Redisにおけるトランザクション

SETEX命令は、SETとEXPIREをAtomicに行う命令。
Atomicをどうやって実現しているかというと、SETとEXPIREの処理をMULTIとEXECというトランザクション開始〜終了を示す命令で囲うことで実現している。

トランザクションの中でエラーが起きた場合

It's important to note that even when a command fails, all the other commands in the queue are processed – Redis will not stop the processing of commands.
ロールバックの機能はないので本番環境でエラーを出さないよう気をつける必要がある

MULTI と WATCH

MULTIを使ったトランザクションは悲観的ロックを取得する
WATCHを使うと楽観的ロックを取得する
参考:
https://redis.io/topics/transactions#cas

zakkyzakky

便利なAPI

from_now

1.week.from_now
=> Tue, 20 Apr 2021 20:04:09 UTC +00:00