Sorted TTL List

Travis Build Status Windows Tests Coveralls Coverage

Hex.pm Version Deps Status Hex.pm

A ets based list with an expire feature. So you can push keys to the list that will expire after a gven time. An example use case could be a user online list with additional data.

Installation

If available in Hex, the package can be installed as:

  1. Add sorted_ttl_list to your list of dependencies in mix.exs:

    def deps do
      [{:sorted_ttl_list, "~> 0.1.0"}]
    end
  2. Ensure sorted_ttl_list is started before your application:

    def application do
      [applications: [:sorted_ttl_list]]
    end

Basic usage

START

Create the table

{ :ok, tid } = SortedTtlList.start_link( "my_tablename" )

PUSH / UPDATE

Add elements to the list or update existing keys

:ok = SortedTtlList.push( "my_tablename", "element_key", 1480592547, 60, %{ additional: "data" } )

GET

get a single element by key

{ "element_key", 1480592547, 1480592607, %{ additional: "data" } } = SortedTtlList.get( "my_tablename", "element_key" )

LIST

get the sorted list

[ { "another_key", 1337, 1480622607, %{ another: "data" } }, { "element_key", 1480592547, 1480592607, %{ additional: "data" } } ] = SortedTtlList.list( "my_tablename" )

or sorted fron high to low

[ { "another_key", 1337, 1480622607, %{ another: "data" } }, { "element_key", 1480592547, 1480592607, %{ additional: "data" } } ] = SortedTtlList.list( "my_tablename", true )

DELETE

delete a element

:ok = SortedTtlList.list( "my_tablename", "element_key" )

SIZE

get the size of the list

2 = SortedTtlList.size( "my_tablename" )

EXISTS

check of the list is started and the ets table exists

true = SortedTtlList.exists( "my_tablename" )
false = SortedTtlList.exists( "nobody" )

Release History

VersionDateDescription
0.1.22016-12-01removed io inspect
0.1.12016-12-01added reverse option for list
0.1.02016-12-01added exists method and optimized docs
0.0.12016-11-28Minimal elixir version
0.0.12016-11-28first alpha version …

The MIT License (MIT)

Copyright © 2016 M. Peter, http://www.tcs.de

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.