0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ecto.Modelをシリアライズする方法

Posted at

状況

DBから取得したModelをRedisにキャッシュするためにシリアライズしたかった。

環境

Elixir 1.3.1

解決方法

シリアライズには:erlang.binary_to_term/1を使う。

model = App.Repo.get(App.Post, id)
:erlang.binary_to_term(model)

デシリアライズには:erlang.term_to_binary/1を使う。

model = :erlang.term_to_binary(serialized_data)

やっていることは、erlangで利用されているETFに変換している模様。これについてはしっかり理解できていないので、どこかのタイミングで理解したい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?