Store Library

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

 

Check out our Store doc for more information about the Medium One Store.

Import

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

import Store

 

Set global data

Store.set_global_data(keydatattl=0)

Sets the data for a global key.

Credit cost: 1

Parameters

  • keystr|unicode name of key to store
  • datastr|unicode data string to store
  • ttlint time to live for the key in seconds. (-1 for infinite TTL, 0 for a week)

Return Value

None

Example

  • Sample Code:
    • import Store
      
      val = IONode.get_input('in1')['event_data']['value'] Store.set_global_data("max_value", str(val))

Exceptions

  • DataValidationStoreException
    • Data is null or exceeds length limit
  • InvalidTTLException
    • Non-positive TTL
  • KeyNameException
    • Key name is null, empty, or exceeds length limit
  • StoreException
    • Maximum number of per-user keys reached
    • Maximum number of global keys reached
    • Invalid increment (non-integer)
  • Exception
    • Any other error


Set user data

Store.set_data(keydatattl=0)

Sets the data for a per-user key.

Credit cost: 1

Parameters

  • keystr|unicode name of key to store
  • datastr|unicode data string to store
  • ttlint time to live for the key in seconds. (-1 for infinite TTL, 0 for a week)

Return Value

None

Example

  • Sample Code
    • import Store

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

      Store.set_data("my_max_value", str(val), -1)

Exceptions

  • DataValidationStoreException
    • Data is null or exceeds length limit
  • InvalidTTLException
    • Non-positive TTL
  • KeyNameException
    • Key name is null, empty, or exceeds length limit
  • StoreException
    • Maximum number of per-user keys reached
    • Maximum number of global keys reached
    • Invalid increment (non-integer)
  • Exception
    • Any other error

Increment global data

Store.incr_global(key, value)

Increment existing value (or set to 0 if doesn't exist) by specified value.

Credit cost: 1

Parameters

  • keystr|unicode name of key to store
  • valuestr|unicode amount to increment key by

Return Value

None

Example

  • Sample Code:
    • import Store
      
      val = IONode.get_input('in1')['event_data']['value'] Store.incr_global("max_value", val)

Exceptions

  • InvalidTTLException
    • Non-positive TTL
  • KeyNameException
    • Key name is null, empty, or exceeds length limit
  • JedisDataException
    • Internal server error
  • Exception
    • Any other error

Increment user data

Store.incr(key, value)

Increment existing value (or set to 0 if doesn't exist) by specified value.

Credit cost: 1

Parameters

  • keystr|unicode name of key to store
  • valuestr|unicode amount to increment key by

Return Value

None

Example

  • Sample Code:
    • import Store
      
      val = IONode.get_input('in1')['event_data']['value'] Store.incr("max_value", val)

Exceptions

  • InvalidTTLException
    • Non-positive TTL
  • KeyNameException
    • Key name is null, empty, or exceeds length limit
  • JedisDataException
    • Internal server error
  • Exception
    • Any other error

Get global data

Store.get_global(key)

Get a previously stored global string.

Credit cost: 1

Parameters

  • keystr|unicode name of key to fetch

Return Value

unicode data string that was previously set, or None if the key had never been set, was deleted, or had timed out.

Example

  • 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)

Exceptions

  • KeyNameException
    • Key name is null, empty, or exceeds length limit
  • StoreException
    • Maximum number of per-user keys reached
    • Maximum number of global keys reached
    • Invalid increment (non-integer)
  • Exception
    • Any other error


Get user data

Store.get(key)

Get a previously stored per-user string.

Credit cost: 1

Parameters

  • keystr|unicode name of key to fetch

Return Value

unicode data string that was previously set, or None if the key had never been set, was deleted, or had timed out.

Example

  • Sample Code:
    • import Store
      
      val = IONode.get_input('in1')['event_data']['value']
      
      max_value = Store.get("my_max_value")
      if max_value is None:
          max_value = val
      else:
          max_value = max(int(max_value), val)

Exceptions

  • KeyNameException
    • Key name is null, empty, or exceeds length limit
  • StoreException
    • Maximum number of per-user keys reached
    • Maximum number of global keys reached
    • Invalid increment (non-integer)
  • Exception
    • Any other error


Get global keys

Store.get_global_keys()

Get a list of active global keys.

Credit cost: 1

Parameters

None

Return Value

set set of active global key names.

Example

  • Sample Code:
    • import Store
      
      all_keys = Store.get_global_keys()
  • Return Value:
    • ["max_value", "test_key"]

Exceptions

  • StoreException
    • Maximum number of per-user keys reached
    • Maximum number of global keys reached
    • Invalid increment (non-integer)
  • Exception
    • Any other error


Get user keys

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

Parameters

None

Return Value

  • set set of active per user key names.

Example

  • Sample Code:
    • import Store
      
      all_keys = Store.get_keys()
  • Return Value:
    • ["my_max_value", "test_key_1", "test_key_2"]

Exceptions

  • StoreException
    • Maximum number of per-user keys reached
    • Maximum number of global keys reached
    • Invalid increment (non-integer)
  • Exception
    • Any other error


Get global TTL

Store.get_global_TTL(key)

Get the time to live (expiration time) of the given global key in seconds.

Credit cost: 1

Parameters

  • keystr|unicode name of key to get its TTL

Return Value

double time to live for the given global key in seconds

Example

  • Sample Code:
    • import Store
      
      ttl = Store.get_global_TTL("max_value")
  • Return Value:
    • 600000

Exceptions

  • KeyNameException
    • Key name is null, empty, or exceeds length limit

Get user TTL

Store.get_TTL(key) 

Get the time to live (expiration time) of the given per-user key in seconds.

Credit cost: 1

Parameters

  • keystr|unicode name of key to get its TTL

Return Value

double time to live for the given per-user key in seconds.

Example

  • Sample Code:
    • import Store
      
      ttl = Store.get_TTL("my_max_value")
  • Return Value:
    • -1

Exceptions

  • KeyNameException
    • Key name is null, empty, or exceeds length limit

Delete global key

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

  • keystr|unicode name of key to delete

Return Value

None

Example

  • Sample Code:
    • import Store

      Store.delete_global("max_value")

Exceptions

  • KeyNameException
    • Key name is null, empty, or exceeds length limit
  • StoreException
    • Maximum number of per-user keys reached
    • Maximum number of global keys reached
    • Invalid increment (non-integer)
  • Exception
    • Any other error


Delete user key

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

  • keystr|unicode name of key to delete

Return Value

None

Example

  • Sample Code:
    • import Store

      Store.delete("my_max_value")

Exceptions

  • KeyNameException
    • Key name is null, empty, or exceeds length limit
  • StoreException
    • Maximum number of per-user keys reached
    • Maximum number of global keys reached
    • Invalid increment (non-integer)
  • Exception
    • Any other error