utils/storage
Tag 3
Key-Value Store Service
  Published by utils on Wednesday, May 31st, 2017, 12:58:46 AM
  # StdLib Key-Value Storage This is a highly available backend key-value storage service. As with all StdLib services, it is available in [Node](https://github.com/stdlib/lib-node), [Python](https://github.com/stdlib/lib-python), [Ruby](https://github.com/stdlib/lib-ruby), and [JavaScript (Web)](https://github.com/stdlib/lib-js). All keys are converted to strings, and values must be JSON-serializable. Arrays will be converted into Objects with numeric indices. Your storage is scoped to the active StdLib user account based on the Library Token you used to authenticate. ## Usage You **must** be authenticated with a StdLib Library Token to use this service. You can do that by initializing `lib` like this: ```javascript // Retrieve your Library Token on the StdLib Dashboard const lib = require('lib')({token: STDLIB_LIBRARY_TOKEN}); ``` You can find your token in your [dashboard](https://dashboard.stdlib.com/dashboard). ### storage.set Setting key-value pairs is easy. `storage.set` accepts JSON-serializable objects, base types including string, number, boolean and null, and will convert Arrays into Objects with numeric indices. ```javascript // Set a String lib.utils.storage.set('key', 'value', (err, value) => { // Do something with result }); // Or set an Object value lib.utils.storage.set('key', {content: 1}, (err) => { // Do something with result }); ``` ### storage.get To retrieve a previously set key-value pair, use `storage.get`. Note that this method will **return an error if the key-value pair has not previously been set**. ```javascript // Get a key's value lib.utils.storage.get('key', (err, value) => { // Do something with result }); ``` ### storage.clear To clear a previously set key, use `storage.clear`. Note that this method will **return an error if the key-value pair has not previously been set**. ```javascript lib.utils.storage.clear('key', (err, value) => { // Do something with result }); ```
# StdLib Key-Value Storage This is a highly available backend key-value storage service. As with all StdLib services, it is available in [Node](https://github.com/stdlib/lib-node), [Python](https://github.com/stdlib/lib-python), [Ruby](https://github.com/stdlib/lib-ruby), and [JavaScript (Web)](https://github.com/stdlib/lib-js). All keys are converted to strings, and values must be JSON-serializable. Arrays will be converted into Objects with numeric indices. Your storage is scoped to the active StdLib user account based on the Library Token you used to authenticate. ## Usage You **must** be authenticated with a StdLib Library Token to use this service. You can do that by initializing `lib` like this: ```javascript // Retrieve your Library Token on the StdLib Dashboard const lib = require('lib')({token: STDLIB_LIBRARY_TOKEN}); ``` You can find your token in your [dashboard](https://dashboard.stdlib.com/dashboard). ### storage.set Setting key-value pairs is easy. `storage.set` accepts JSON-serializable objects, base types including string, number, boolean and null, and will convert Arrays into Objects with numeric indices. ```javascript // Set a String lib.utils.storage.set('key', 'value', (err, value) => { // Do something with result }); // Or set an Object value lib.utils.storage.set('key', {content: 1}, (err) => { // Do something with result }); ``` ### storage.get To retrieve a previously set key-value pair, use `storage.get`. Note that this method will **return an error if the key-value pair has not previously been set**. ```javascript // Get a key's value lib.utils.storage.get('key', (err, value) => { // Do something with result }); ``` ### storage.clear To clear a previously set key, use `storage.clear`. Note that this method will **return an error if the key-value pair has not previously been set**. ```javascript lib.utils.storage.clear('key', (err, value) => { // Do something with result }); ```
  info
context
enabled
bg
info
  parameters (click to modify)
{string}
key
= ""
(no description)
  code
  info
context
enabled
bg
info
  parameters (click to modify)
{string}
key
= ""
(no description)
  code
  info
context
enabled
bg
info
  parameters (click to modify)
{string}
key
= ""
(no description)
{any}
value
(required)
(no description)
  code