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(table, key)

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(table, key)

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(table)

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(table, key, score, ttl, data \\ nil)

Push a element to the list

Parameters

  • table (Binary|Atom) The table name. Make sure to start the table before
  • key (Binary) The key used to save this element
  • score (Integer) The score to sort the list.
  • ttl (Integer) The time to live in seconds for this key
  • data (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
size(table)

Get the size of the table

Parameters

  • table (Binary|Atom) The table to list the elements.

Examples

iex>{:ok, tid} = SortedTtlList.start_link( "test_table" )
...>0 = SortedTtlList.size( tid )
...>:ok = SortedTtlList.push( tid, "mykey", 23, 3600, nil )
...>SortedTtlList.size( tid )
1
start_link(tablename)