1.0.0 • Published 7 years ago

memcing v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Memcing

NPM Build Status

Memcing is an in-memory key-value caching application with RESTful API.

Installation

npm install memcing

Usage

Interactive mode

npm start

Add an entry (add hello world) and see http://localhost:12080/entries/hello

Help

./memcing -help
  Options:
    -i                 : Enable interactive mode.
    -listen-http       : Listen HTTP requests. Default; 0.0.0.0:12080
    -load-file         : Load a command file.

    -cache-limit       : Cache size limit in bytes. Default (128MB); 134217728
    -entry-limit       : Entry size limit in bytes. Default (1KB); 1024
    -vacuum-delay      : Delay in seconds for vacuum. Default; 30
    -eviction          : Enable eviction mode.

    -debug             : Enable debug mode.
    -verbose           : Set verbose message level. Default; 1
    -help              : Display help and exit.

  stdin:
    -cmd               : Enable command mode for stdin.
    -csv               : Enable CSV mode for stdin.
    -csv-delimiter     : CSV delimiter (char or `tab`). Default; ,
    -csv-field-key     : Key field index on CSV. Default; 1
    -csv-field-filter  : Include fields on CSV. Default (all); null
                         Example; -csv-field-filter 1,2

  Interactive mode commands:
    get key
    set key value [expire = 0]
    add key value [expire = 0]
    increment key [amount = 1]
    decrement key [amount = 1]
    delete key
    drop
    dump
    stats
    vacuum
    exit

Examples

Interactive Mode

./memcing -load-file ../test/cmds-lf.txt -i -listen-http

Reads commands from cmds-lf.txt then switch to interactive mode and listen ttp requests. The cached data will be available for REPL and RESTful API.

For RESTful API performance tests;

ab -n 10000 http://localhost:12080/entries/hello
ab -n 10000 -c 100 http://localhost:12080/entries/hello

Postal Code Service Example

You can easily create a postal code service;

wget -qO zip-codes.zip http://download.geonames.org/export/zip/US.zip && \
unzip -p zip-codes.zip US.txt | \
cat | \
./memcing -listen-http -csv -csv-delimiter tab -csv-field-key 2 -csv-field-filter 1,3,4,5,6,10,11

See http://localhost:12080/entries/78729

{
  "key":"78729",
  "val":"[\"US\",\"Austin\",\"Texas\",\"TX\",\"Williamson\",\"30.4521\",\"-97.7688\"]",
  "ts":1401417873489,
  "expTS":0
}

If you want to include other countries see http://download.geonames.org/export/zip/ and change the part (US.zip and US.txt) of the command at above.

RESTful API

RESTful API is still under development. For the current implementations see Implementations

  • Use application/x-www-form-urlencoded for request method.
  • Use val query parameter for value.
  • Use exp query parameter for expiration.

PUT

/entries/{KEY}

PUT method represent the set command.

Examples:

curl -X PUT -d "val=world" http://localhost:12080/entries/hello
curl -X PUT -d "val=world&exp=10" http://localhost:12080/entries/bye

POST

/entries/{KEY}

POST method represent the add command.

Examples:

curl -X POST -d "val=1" http://localhost:12080/entries/counter

GET

/entries
/entries/{KEY}

GET method represent the get command.

Examples:

curl http://localhost:12080/entries
curl http://localhost:12080/entries/hello

DELETE

/entries
/entries/{KEY}

DELETE method represent the delete or the drop command.

Examples:

curl -X DELETE http://localhost:12080/entries/hello
curl -X DELETE http://localhost:12080/entries

Notes

  • It is 'originally' developed for code exercise. The requirements were; non-persistent, non-durable and supporting eviction.

Implementations

  • Interactive mode
  • RESTful API
    • GET
      • Collection (/entries)
      • Element (/entries/{KEY})
    • PUT
      • Collection (/entries)
      • Element (/entries/{KEY})
    • POST
      • Collection (/entries)
      • Element (/entries/{KEY})
    • DELETE
      • Collection (/entries)
      • Element (/entries/{KEY})

###License

Licensed under The MIT License (MIT)
For the full copyright and license information, please view the LICENSE.txt file.

1.0.0

7 years ago

0.2.10

9 years ago

0.2.9

9 years ago

0.2.8

10 years ago

0.2.7

10 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago