View Source Conion.Store.Bucket (conion v0.1.0)

A Bucket is a key/value store in a supervised GenServer. Use Conion.Store.new_bucket/1 to start a bucket. The Server will use Conion.Store.BucketSupervisor.start_child/1 to do so.

Summary

Functions

Return the bucket name of the bucket at pid

safely call the GenServer.callback return an error tuple if the bucket is not alive

safely cast the GenServer.callback return an error tuple if the bucket is not alive

Returns a specification to start this module under a supervisor.

Retrun true if the bucket is not stored permanently

removes all entries from the bucket

Return the entry at id from the bucket

Returns the state of a server. You can pass an atom or pid.

Overridable

{:ok, {new_id,etry}}, {:error, :bucket_not_exist}

Return all entry from the bucket

Persist a bucket

return the bucket's persistor

{:ok, {id,etry}}, {:error, :bucket_not_exist | :id_not_found}

{:ok, {id,etry}}, {:error, :bucket_not_exist | :id_not_found}

Start the server with either

Functions

bucket_name(pid)

Return the bucket name of the bucket at pid

call(pid_or_name, message)

safely call the GenServer.callback return an error tuple if the bucket is not alive

call_or_error(bool, name_or_pid, message)

cast(pid_or_name, message)

safely cast the GenServer.callback return an error tuple if the bucket is not alive

cast_or_error(bool, name_or_pid, message)

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

dirty?(bucket)

Retrun true if the bucket is not stored permanently

drop!(pid)

removes all entries from the bucket

get(bucket, id)

Return the entry at id from the bucket

get_state(pid_or_atom)

Returns the state of a server. You can pass an atom or pid.

initial_state(state)

Overridable:

Prepares, validates, formats the given state to be passed to init()

insert(bucket, entry)

{:ok, {new_id,etry}}, {:error, :bucket_not_exist}

list(bucket)

Return all entry from the bucket

persist(bucket)

Persist a bucket

persistor(pid_or_name)

return the bucket's persistor

prepare_state_to_start(opts)

Overridable:

Should return the args passed to start_link. For a named server it extracts the :initial_state from the opts. For unnamed processes it takes opts as the initial state.

remove(bucket, id)

{:ok, {id,etry}}, {:error, :bucket_not_exist | :id_not_found}

replace(bucket, id, entry)

{:ok, {id,etry}}, {:error, :bucket_not_exist | :id_not_found}

start_link(opts)

Start the server with either

MyServer.start_link(initial_state) ... start an unregistered server with the given 
                                       initial state.

MyServer.start_link(name: :registered_as_whatever, initial_state: any) ...
                                       start a registered server with `initial_state` as it's state.