Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mmzeeman/rrets

Round Robin Erlang Term Storage
https://github.com/mmzeeman/rrets

Last synced: about 16 hours ago
JSON representation

Round Robin Erlang Term Storage

Awesome Lists containing this project

README

        

# RRets - Round Robin Erlang Term Storage #

Copyright (c) 2014 MM Zeeman, All Rights Reserved.

### Introduction ###

The RRets packages allows for an easy way to store erlang terms into a round robin database. The
terms are stored until the storage has reached a predefined maximum and are then overwritten by newer items.

Each term added to the storage gets a second resolution unix_time timestamp attached to it.
The storage can be used to easily, and quickly, store terms. Example usage:

* Logs
* System statistics
* Audit logs

The storage can be queried with a match specification which allows quick, and streaming, access
to your data.

For example:

```erlang

MatchSpec = ets:fun2ms(fun({Timestamp, {example, 2, X}}) -> {Timestamp, {example, 2, X}} end),
Continuation = rrets_reader:open("my_storage", MatchSpec),
{Records, Continuation1} = rrets_reader:match(Continuation),
...
```

After opening a reader a continuation is returned. This continuation can be used to repeatedly
receive lists with matching records. In this case, all tuples matching `{example, 2, _}` terms
are retrieved from the storage. Each matching record is returned with the timestamp when the term
was stored.

### Opening a rrets storage ###

RRets storages can be opened by using a name, filename and a specification on how large the
storage files need to become. The name can later be used add terms to the storage.

```erlang

Storage = rrets:open([{name, my_storage}, {file, "my_storage"}, {size, {10475520, 10}}]).
```

### Storing a term ###

```erlang

Ts = rrets:log(my_storage, {nasi, 3})
````

### Closing the storage ###

It is important that the storage is properly closed.

```erlang

rrets:close(my_storage)
````