shahryarjb
Im going to use GenServer first time, the map that I need to save is:
%{
"_csrf_token" => "DhA3FRwIGxQNQiYGfC4GJgAAKSOdf2fsdPDFCqZ5lOAydRPnEmmA==",
"_utf8" => "✓",
"ersal" => "hozori",
"name_family" => "مجتبی ناصری",
"number" => "9922365",
"phone_number" => "0911333333",
"price_of_card" => "1320",
"price_of_text" => "200",
"receive" => "person",
"writing-kind" => "1"
}
I use UUID to create Genserver PID for each user that needs to save their maps like that.
after that work my GenServer maps are:
%{
"793edde3-bcc0-4719-9738-c527f168163e": %{
"_csrf_token" => "DhA3FRwIGxQNQiYGfC4GJgAAKSOdf2fsdPDFCqZ5lOAydRPnEmmA==",
"_utf8" => "✓",
"ersal" => "hozori",
"name_family" => "مجتبی ناصری",
"number" => "9922365",
"phone_number" => "0911333333",
"price_of_card" => "1320",
"price_of_text" => "200",
"receive" => "person",
"writing-kind" => "1"
},
"963018d7-6e03-4f8d-a6f4-31298fc89128": %{
"_csrf_token" => "DhA3FRwIGxQNQiYGfC4GJgAAKSOdf2fsdPDFCqZ5lOAydRPnEmmA==",
"_utf8" => "✓",
"ersal" => "hozori",
"name_family" => "مجتبی نصیری",
"number" => "46513",
"phone_number" => "0921433333",
"price_of_card" => "13۶0",
"price_of_text" => "200",
"receive" => "person",
"writing-kind" => "1"
}
}
My GenServer module:
defmodule WeddingCard.Db.Invoice.InvoiceGenserver do
use GenServer
# client api
def start_link(init_param) do
GenServer.start_link(__MODULE__, init_param, name: __MODULE__, debug: [:trace])
end
def init(init_param) do
{:ok, init_param}
end
def load_all_params do
GenServer.call(__MODULE__, :load_all)
end
# uuid
def load_one_params(uuid) do
GenServer.call(__MODULE__, {:load_one, uuid})
end
def save_params(uuid,params) do
GenServer.cast(__MODULE__, {:save, uuid ,params})
end
def delete_one_params(uuid) do
GenServer.cast(__MODULE__, {:delete_one, uuid})
end
def delete_all_params do
GenServer.cast(__MODULE__, :delete_all)
end
#===============================================
#server api
def handle_call(:load_all, _from, init_param) do
{:reply, init_param, init_param}
end
def handle_call({:load_one, uuid}, _from, init_param) do
new_state = Map.get(init_param, String.to_atom(uuid))
{:reply, new_state, init_param}
end
def handle_cast({:save, uuid, params}, init_param) do
new_state = Map.update(
init_param ,
String.to_atom(uuid) ,
params, fn _old_map -> params end
)
IO.inspect new_state;
{:noreply, new_state }
end
# uuid
def handle_cast({:delete_one, uuid}, init_param) do
new_state = Map.delete(init_param, String.to_atom(uuid))
{:noreply, new_state }
end
def handle_cast(:delete_all, _init_param) do
{:noreply, %{}}
end
end
I have added my Genserver in application.ex module
def start(_type, _args) do
children = [
{WeddingCard.Db.Invoice.InvoiceGenserver, %{}}
]
end
Now I have 2 questions ,
- is my way true and is my each user maps value isolate?
- I need after the time concerned , it will be deleted, how can I do this ?
Save function:
InvoiceGenserver.save_params(uuid, params)
Thanks
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
shahryarjb
To delete after the time concerned , I found these pages
send_after
and
https://rob.conery.io/2016/02/16/red4-store-part-3/
tty
What are your actual requirements ?
From the basic description you gave I wouldn’t have use a GenServer, instead I would have tucked the information into
:etsorRegistrykokolegorille
It might also be a good use case for Cachex.
shahryarjb
@tty @kokolegorille Hello you two and Thank you, I just want to learn OTP especially GenServer, Now I just want to know, is it my way right or not ?