Skip to content

Commit

Permalink
Merge pull request #7 from TamarLabs/dehydrator_type
Browse files Browse the repository at this point in the history
README update
  • Loading branch information
daTokenizer committed Nov 15, 2016
2 parents fdaa503 + abe24fd commit 81836dc
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Using this system it is also possible to craft a self cleaning "claims check", t

You can read further on the algorithm behind this module [here](Algorithm.md).

The module works by adding a new type to Redis -`DehydratorType`. It will be ceated automatically when you call a push command on it, and it can be deleted using the `DEL` command like any other key.

![a gif that shows basic usage](redehy-basics.gif)

## What it includes:
Expand All @@ -22,9 +24,13 @@ In this repository there are two python files that exemplify the usage of the mo
* [helloworld.py](helloworld.py) - very simple usage example of all the functions exposed by the module
* [test.py](test.py) - run internal as well as external functional tests, load test and print it all to stdout.

### 3. LibRMUtil
### 3. klib [khash](khash.h)

A set of macros to create the hash maps used to implement the dehydrator type.

From [Redis Modules SDK](https://github.com/RedisLabs/RedisModulesSDK) Readme:
### 4. LibRMUtil

From [Redis Modules SDK](https://github.com/RedisLabs/RedisModulesSDK) README:

A small library of utility functions and macros for module developers, including:

Expand All @@ -50,7 +56,6 @@ The dehydrator is an effective 'snooze button' for events, you push an event int
* `DEHYDRATOR.LOOK` - search the dehydrator for an element with the given id and if found return it's payload (without pulling).

**The module also includes 2 assistive commands:**
* `DEHYDRATOR.CLEAR` - remove all the elements from the dehydrator.
* `DEHYDRATOR.TEST` - a set of unit tests of the above commands.

### time complexity
Expand All @@ -59,7 +64,6 @@ The dehydrator is an effective 'snooze button' for events, you push an event int
* `DEHYDRATOR.PULL` - O(N) where N is the number of dehydrating elements with the same TTL.
* `DEHYDRATOR.POLL` - O(N) where N is the number of expired elements, please notice we regard # of different TTLs << # of dehydrated elements in the system.
* `DEHYDRATOR.LOOK` - O(1)
* `DEHYDRATOR.CLEAR` - O(N) where N is the total number of dehydrating elements.
* `DEHYDRATOR.TEST` - Fixed time (~11 seconds) - this function uses `sleep` (dios mio, No! &#x271e;&#x271e;&#x271e;).

### Quick Start Guide
Expand All @@ -73,47 +77,46 @@ Here's what you need to do to build this module:
Now run `redis-cli` and try the commands:

```
127.0.0.1:9979> DEHYDRATOR.CLEAR
OK
127.0.0.1:9979> DEHYDRATOR.PUSH id1 world 15
127.0.0.1:9979> DEHYDRATOR.PUSH some_dehy id1 world 15
OK
127.0.0.1:9979> DEHYDRATOR.PUSH id2 hello 1
127.0.0.1:9979> DEHYDRATOR.PUSH some_dehy id2 hello 1
OK
127.0.0.1:9979> DEHYDRATOR.PUSH id3 goodbye 2
127.0.0.1:9979> DEHYDRATOR.PUSH some_dehy id3 goodbye 2
OK
127.0.0.1:9979> DEHYDRATOR.PULL id3
127.0.0.1:9979> DEHYDRATOR.PULL some_dehy id3
"goodbye"
127.0.0.1:9979> DEHYDRATOR.POLL
127.0.0.1:9979> DEHYDRATOR.POLL some_dehy
1) "hello"
127.0.0.1:9979> DEHYDRATOR.POLL
127.0.0.1:9979> DEHYDRATOR.POLL some_dehy
(empty list or set)
127.0.0.1:6379> DEHYDRATOR.LOOK id1
"hello"
127.0.0.1:6379> DEHYDRATOR.LOOK id2
(nil)
127.0.0.1:6379> DEHYDRATOR.PULL id2
(nil)
127.0.0.1:6379> DEHYDRATOR.LOOK some_dehy id2
ERROR: No Such Element
127.0.0.1:6379> DEHYDRATOR.LOOK some_dehy id1
"world"
127.0.0.1:6379> DEHYDRATOR.PULL some_dehy id2
ERROR: No Such Element
```

This `(empty list or set)` reply from `DEHYDRATOR.POLL` means that the there are no more items to pull right now, so we'll have to wait until enough time passes for our next element to be ready (15 seconds in this case). Then we can run:

```
127.0.0.1:9979> DEHYDRATOR.POLL
127.0.0.1:9979> DEHYDRATOR.POLL some_dehy
1) "world"
127.0.0.1:9979> DEHYDRATOR.TEST
PASS
(11.00s)
127.0.0.1:9979> DEL some_dehy
OK
```

Enjoy!


## Future work

* extend usage of Redis` low-level APIs
* add UPDATE command
* add pub/sub mechanism to POLL
* add ability to have several different dehydrators (maybe as a new type)
* "time to next element" command
* add pub/sub mechanism to POLL
* a whole lot more

## About This Module
Expand Down

0 comments on commit 81836dc

Please sign in to comment.