Skip to content

Script Development / Simple Storage DFF.STORE

DataFlux Func includes a built-in simple persistent storage feature DFF.STORE. For scenarios that require data storage but are not complex, you can directly use this built-in storage feature.

The storage feature follows a Scope-Key-Value structure, allowing the same Key to exist under different namespaces.

Simple Storage Preserves Original Data Types

When operating on simple storage, the data written is automatically serialized; when reading, it is automatically deserialized.

Therefore, there is no need to manually handle serialization.

DFF.STORE.set(...)

Store data, with the following parameters:

Parameter Type Required / Default Description
key str Required Key name
value Any JSON-serializable object Required Data
expires / expire int None Expiration time.
Unit: seconds
None means never expires
not_exists bool False Write only if data does not exist
scope str Current script name Namespace
Example
1
DFF.STORE.set('user:user-001', { 'name': 'User A' }, scope='users')

DFF.STORE.mset(...)

Added in version 6.0.6

Batch store data, with the following parameters:

Parameter Type Required / Default Description
key_values dict Required Key-data dictionary
expires / expire int None Expiration time.
Unit: seconds
None means never expires
not_exists bool False Write only if data does not exist
scope str Current script name Namespace
Example
1
2
3
4
5
data = {
  'user:user-001': { 'name': 'User A' },
  'user:user-002': { 'name': 'User B' }
}
DFF.STORE.mset(data, scope='users')

DFF.STORE.keys(...)

Get a list of Keys, with the following parameters:

Parameter Type Required / Default Description
pattern str "*" Key name matching pattern
Supports * wildcard
scope str Current script name Namespace
Example
1
2
3
4
DFF.STORE.set('user:user-001', { 'name': 'User A' }, scope='users')
DFF.STORE.set('user:user-002', { 'name': 'User B' }, scope='users')
DFF.STORE.keys('user:user-*')
# ['user:user-001', 'user:user-002']

DFF.STORE.get(...)

Get stored data, with the following parameters:

Parameter Type Required / Default Description
key str Required Key name
scope str Current script name Namespace
Example
1
2
3
DFF.STORE.set('user:user-001', { 'name': 'User A' }, scope='users')
DFF.STORE.get('user:user-001', scope='users')
# {'name': 'User A'}

DFF.STORE.mget(...)

Added in version 6.0.6

Batch get stored data, with the following parameters:

Parameter Type Required / Default Description
keys list Required List of Key names
scope str Current script name Namespace
Example
1
2
3
4
5
DFF.STORE.set('user:user-001', { 'name': 'User A' }, scope='users')
DFF.STORE.set('user:user-002', { 'name': 'User B' }, scope='users')

DFF.STORE.mget([ 'user:user-001', 'user:user-002' ], scope='users')
# {'user:user-001': {'name': 'User A'}, 'user:user-002': {'name': 'User B'}}

DFF.STORE.getall(...)

Added in version 6.0.6

Get all stored data, with the following parameters:

Parameter Type Required / Default Description
scope str Current script name Namespace
Example
1
2
3
4
5
DFF.STORE.set('user:user-001', { 'name': 'User A' }, scope='users')
DFF.STORE.set('user:user-002', { 'name': 'User B' }, scope='users')

DFF.STORE.getall(scope='users')
# {'user:user-001': {'name': 'User A'}, 'user:user-002': {'name': 'User B'}}

DFF.STORE.get_pattern(...)

Added in version 6.0.6

Get stored data based on a key name matching pattern, with the following parameters:

Parameter Type Required / Default Description
pattern str "*" Key name matching pattern
Supports * wildcard
scope str Current script name Namespace
Example
1
2
3
4
5
DFF.STORE.set('user:user-001', { 'name': 'User A' }, scope='users')
DFF.STORE.set('user:user-002', { 'name': 'User B' }, scope='users')

DFF.STORE.get_pattern('*-001', scope='users')
# {'user:user-001': {'name': 'User A'}}

DFF.STORE.delete(...)

Delete stored data, with the following parameters:

Parameter Type Required / Default Description
key str Required Key name
scope str Current script name Namespace
Example
1
DFF.STORE.delete('user:user-001', scope='users')

DFF.STORE.delete_pattern(...)

Added in version 6.0.6

Delete stored data based on a key name matching pattern, with the following parameters:

Parameter Type Required / Default Description
pattern str "*" Key name matching pattern
Supports * wildcard
scope str Current script name Namespace
Example
1
2
3
4
DFF.STORE.set('user:user-001', { 'name': 'User A' }, scope='users')
DFF.STORE.set('user:user-002', { 'name': 'User B' }, scope='users')

DFF.STORE.delete_pattern('*:user-001', scope='users')