项目作者: devfacet

项目描述 :
An in-memory key-value caching application with RESTful API
高级语言: JavaScript
项目地址: git://github.com/devfacet/memcing.git
创建时间: 2014-04-07T07:30:24Z
项目社区:https://github.com/devfacet/memcing

开源协议:MIT License

下载


Memcing

NPM Build Status

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

Installation

  1. npm install memcing

Usage

Interactive mode

  1. npm start

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

Help

  1. ./memcing -help
  1. Options:
  2. -i : Enable interactive mode.
  3. -listen-http : Listen HTTP requests. Default; 0.0.0.0:12080
  4. -load-file : Load a command file.
  5. -cache-limit : Cache size limit in bytes. Default (128MB); 134217728
  6. -entry-limit : Entry size limit in bytes. Default (1KB); 1024
  7. -vacuum-delay : Delay in seconds for vacuum. Default; 30
  8. -eviction : Enable eviction mode.
  9. -debug : Enable debug mode.
  10. -verbose : Set verbose message level. Default; 1
  11. -help : Display help and exit.
  12. stdin:
  13. -cmd : Enable command mode for stdin.
  14. -csv : Enable CSV mode for stdin.
  15. -csv-delimiter : CSV delimiter (char or `tab`). Default; ,
  16. -csv-field-key : Key field index on CSV. Default; 1
  17. -csv-field-filter : Include fields on CSV. Default (all); null
  18. Example; -csv-field-filter 1,2
  19. Interactive mode commands:
  20. get key
  21. set key value [expire = 0]
  22. add key value [expire = 0]
  23. increment key [amount = 1]
  24. decrement key [amount = 1]
  25. delete key
  26. drop
  27. dump
  28. stats
  29. vacuum
  30. exit

Examples

Interactive Mode

  1. ./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;

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

Postal Code Service Example

You can easily create a postal code service;

  1. wget -qO zip-codes.zip http://download.geonames.org/export/zip/US.zip && \
  2. unzip -p zip-codes.zip US.txt | \
  3. cat | \
  4. ./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

  1. {
  2. "key":"78729",
  3. "val":"[\"US\",\"Austin\",\"Texas\",\"TX\",\"Williamson\",\"30.4521\",\"-97.7688\"]",
  4. "ts":1401417873489,
  5. "expTS":0
  6. }

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

  1. /entries/{KEY}

PUT method represent the set command.

Examples:

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

POST

  1. /entries/{KEY}

POST method represent the add command.

Examples:

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

GET

  1. /entries
  2. /entries/{KEY}

GET method represent the get command.

Examples:

  1. curl http://localhost:12080/entries
  2. curl http://localhost:12080/entries/hello

DELETE

  1. /entries
  2. /entries/{KEY}

DELETE method represent the delete or the drop command.

Examples:

  1. curl -X DELETE http://localhost:12080/entries/hello
  2. 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.