sorted_ttl_list v0.0.2 SortedTtlList
Summary
Functions
delete a key from the list
get a single key
list the element in the table sorted by score
Push a element to the list
Get the size of the table
Functions
delete a key from the list
Parameters
table
(Binary|Atom) The table name.key
(Binary) The key used to save this element
Examples
iex>{:ok, _tid} = SortedTtlList.start_link( "test_table" )
...>:ok = SortedTtlList.push( "test_table", "mykey", 23, 3600, %{ some: "additional", data2: "save" } )
...>:ok = SortedTtlList.delete( "test_table", "mykey" )
...>SortedTtlList.size( "test_table" )
0
get a single key
Parameters
table
(Binary|Atom) The table name.key
(Binary) The key to get
Examples
iex>{:ok, _tid} = SortedTtlList.start_link( "test_table" )
...>:ok = SortedTtlList.push( "test_table", "mykey", 23, 3600, %{ some: "additional", data2: "save" } )
...>{ "mykey", 23, _expire_timestamp, %{ some: "additional", data2: "save" } } = SortedTtlList.get( "test_table", "mykey" )
...>SortedTtlList.size( "test_table" )
1
iex>{:ok, _tid} = SortedTtlList.start_link( "test_table" )
...>:ok = SortedTtlList.push( "test_table", "mykey", 23, 2, %{ some: "additional", data2: "save" } )
...>{ "mykey", 23, _expire_timestamp, %{ some: "additional", data2: "save" } } = SortedTtlList.get( "test_table", "mykey" )
...>:timer.sleep( 2000 )
...>nil = SortedTtlList.get( "test_table", "mykey" )
...>SortedTtlList.size( "test_table" )
0
list the element in the table sorted by score
Parameters
table
(Binary|Atom) The table to list the elements.
Examples
iex>{:ok, tid} = SortedTtlList.start_link( "test_table" )
...>:ok = SortedTtlList.push( tid, "mykeyA", 23, 3600, nil )
...>:ok = SortedTtlList.push( tid, "mykeyB", 13, 3600, nil )
...>[ { "mykeyB", 13, _tsA, nil }, { "mykeyA", 23, _tsB, nil } ] = SortedTtlList.list( tid )
...>SortedTtlList.size( tid )
2
Push a element to the list
Parameters
table
(Binary|Atom) The table name. Make sure to start the table beforekey
(Binary) The key used to save this elementscore
(Integer) The score to sort the list.ttl
(Integer) The time to live in seconds for this keydata
(Map) optional Additional data that belongs to this key
Examples
iex>{:ok, tid} = SortedTtlList.start_link( "test_table" )
...>:ok = SortedTtlList.push( tid, "mykey", 23, 3600, %{ some: "additional", data2: "save" } )
...>SortedTtlList.size( tid )
1