Resources

Renesas IoT Sandbox Documentation

Store Library

These functions provide access to persistent, but not durable, storage.

Store functions associate string data, and only string data, with key names. If it's desired to store other data such as numbers, that data should be converted to a string before writing and back after reading. String function inputs can be either str or unicode objects, but the return from the get functions will be unicode, even if the previous set was with a str type. If necessary to convert the unicode object back to a str object, this can be done with the latin-1 codec. Ex:

Store.set_global_data("key_name", "\xff")
val = Store.get_global("key_name")
encoded = val.encode("latin-1")
assert isinstance(val, unicode)
assert "\xff" == encoded
assert isinstance(encoded, str)

Keys can either be global for all users or specific to a particular user. Each key has a time to live that is refreshed whenever the key is set. When the time to live expires, the value of the key is set to None. Currently the default time to live is one week. To change it to infinite, set ttl=-1. Key names also have a maximum length of 1000 characters. Data length is limited to 10000 characters. There's a limit of 100 global keys and 100 unique user keys, tracked separately. For example, if there's the global key "key 1" set, and user 1 has the per user keys "key 2" and "key 3" set and user 2 has the per user keys "key 3" and "key 4" set, then the global key count is 1 and the unique user key count is 3. If any of the limits are exceeded, an exception is thrown. Also note, that while it is possible to name a global key and a per user key the same name, this may be confusing when maintaining code.


Import


To use this library and its functions, you must use the import line at the beginning of your Base Python code.

import Store


Functions


Store.set_global_data

Usage: Store.set_global_data(key, data, ttl=0)

Sets the data for a global key.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to store
    • data: str|unicode Data string to store
    • ttl: int Time to live for the key in seconds. (-1 for infinite TTL, 0 for a week)
  • Returns: None



Store.set_data

Usage: Store.set_data(key, data, ttl=0)

Sets the data for a per user key.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to store
    • data: str|unicode Data string to store
    • ttl: int Time to live for the key in seconds. (-1 for infinite TTL, 0 for a week)
  • Returns: None



Store.delete_global

Usage: Store.delete_global(key)

Deletes a global key, which reduces the number of keys counted against the global key quota. Does nothing if the key had never been set or was already deleted.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to delete
  • Returns: None



Store.delete

Usage: Store.delete(key)

Deletes a per user key. Does nothing if the key had never been set or was already deleted.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to delete
  • Returns: None



Store.get_global

Usage: Store.get_global(key)

Get a previously stored global string.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to fetch
  • Returns:
    • unicode Data string that was previously set, or None if the key had never been set, was deleted or had timed out.



Store.get

Usage: Store.get(key)

Get a previously stored per user string.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to fetch
  • Returns:
    • unicode Data string that was previously set, or None if the key had never been set, was deleted or had timed out.



Store.get_global_keys

Usage: Store.get_global_keys()

Get a list of active global keys.

  • Credit cost: 1
  • Returns:
    • set Set of active global key names.



Store.get_keys

Usage: Store.get_keys()

Get a list of active per user keys. This is the list of the keys that have been set for all users. This does not indicate that the current user have values for these keys.

  • Credit cost: 1
  • Returns:
    • set Set of active per user key names.



Store.get_global_TTL

Usage: Store.get_global_TTL(key)

Get the Time To Live or expiration time of the given global key in seconds.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to get its TTL
  • Returns:
    • double The Time To Live for the given global key in seconds.



Store.get_TTL

Usage: Store.get_TTL(key) Get the Time To Live or expiration time of the given user key in seconds.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to get its TTL
  • Returns:
    • double The Time To Live for the given user key in seconds.



Sample Code


import Store

val = IONode.get_input('in1')['event_data']['value']

max_value = Store.get_global("max_value")
if max_value is None:
    max_value = val
else:
    max_value = max(int(max_value), val)
Store.set_global_data("max_value", str(max_value))
IONode.set_output('out1', {'value': max_value})

min_value = Store.get_global("min_value")
if min_value is None:
    min_value = val
else:
    min_value = min(int(min_value), val)
Store.set_global_data("min_value", str(min_value))
IONode.set_output('out2', {'value': min_value})

Getting Started
User Roles & Permissions
Streams, Tags, & Data Types
Dashboard Widgets
API
Workflow Studio
Workflow Libraries
Metering
Special Characters
Third Party Integration
Mobile
API Explorer

Store Library

These functions provide access to persistent, but not durable, storage.

Store functions associate string data, and only string data, with key names. If it's desired to store other data such as numbers, that data should be converted to a string before writing and back after reading. String function inputs can be either str or unicode objects, but the return from the get functions will be unicode, even if the previous set was with a str type. If necessary to convert the unicode object back to a str object, this can be done with the latin-1 codec. Ex:

Store.set_global_data("key_name", "\xff")
val = Store.get_global("key_name")
encoded = val.encode("latin-1")
assert isinstance(val, unicode)
assert "\xff" == encoded
assert isinstance(encoded, str)

Keys can either be global for all users or specific to a particular user. Each key has a time to live that is refreshed whenever the key is set. When the time to live expires, the value of the key is set to None. Currently the default time to live is one week. To change it to infinite, set ttl=-1. Key names also have a maximum length of 1000 characters. Data length is limited to 10000 characters. There's a limit of 100 global keys and 100 unique user keys, tracked separately. For example, if there's the global key "key 1" set, and user 1 has the per user keys "key 2" and "key 3" set and user 2 has the per user keys "key 3" and "key 4" set, then the global key count is 1 and the unique user key count is 3. If any of the limits are exceeded, an exception is thrown. Also note, that while it is possible to name a global key and a per user key the same name, this may be confusing when maintaining code.


Import


To use this library and its functions, you must use the import line at the beginning of your Base Python code.

import Store


Functions


Store.set_global_data

Usage: Store.set_global_data(key, data, ttl=0)

Sets the data for a global key.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to store
    • data: str|unicode Data string to store
    • ttl: int Time to live for the key in seconds. (-1 for infinite TTL, 0 for a week)
  • Returns: None



Store.set_data

Usage: Store.set_data(key, data, ttl=0)

Sets the data for a per user key.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to store
    • data: str|unicode Data string to store
    • ttl: int Time to live for the key in seconds. (-1 for infinite TTL, 0 for a week)
  • Returns: None



Store.delete_global

Usage: Store.delete_global(key)

Deletes a global key, which reduces the number of keys counted against the global key quota. Does nothing if the key had never been set or was already deleted.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to delete
  • Returns: None



Store.delete

Usage: Store.delete(key)

Deletes a per user key. Does nothing if the key had never been set or was already deleted.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to delete
  • Returns: None



Store.get_global

Usage: Store.get_global(key)

Get a previously stored global string.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to fetch
  • Returns:
    • unicode Data string that was previously set, or None if the key had never been set, was deleted or had timed out.



Store.get

Usage: Store.get(key)

Get a previously stored per user string.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to fetch
  • Returns:
    • unicode Data string that was previously set, or None if the key had never been set, was deleted or had timed out.



Store.get_global_keys

Usage: Store.get_global_keys()

Get a list of active global keys.

  • Credit cost: 1
  • Returns:
    • set Set of active global key names.



Store.get_keys

Usage: Store.get_keys()

Get a list of active per user keys. This is the list of the keys that have been set for all users. This does not indicate that the current user have values for these keys.

  • Credit cost: 1
  • Returns:
    • set Set of active per user key names.



Store.get_global_TTL

Usage: Store.get_global_TTL(key)

Get the Time To Live or expiration time of the given global key in seconds.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to get its TTL
  • Returns:
    • double The Time To Live for the given global key in seconds.



Store.get_TTL

Usage: Store.get_TTL(key) Get the Time To Live or expiration time of the given user key in seconds.

  • Credit cost: 1
  • Parameters:
    • key: str|unicode Name of key to get its TTL
  • Returns:
    • double The Time To Live for the given user key in seconds.



Sample Code


import Store

val = IONode.get_input('in1')['event_data']['value']

max_value = Store.get_global("max_value")
if max_value is None:
    max_value = val
else:
    max_value = max(int(max_value), val)
Store.set_global_data("max_value", str(max_value))
IONode.set_output('out1', {'value': max_value})

min_value = Store.get_global("min_value")
if min_value is None:
    min_value = val
else:
    min_value = min(int(min_value), val)
Store.set_global_data("min_value", str(min_value))
IONode.set_output('out2', {'value': min_value})