Skip to content

Data storage interface¤

Push data into storage¤

Example

from redast import Storage, Memory

storage = Storage(Memory())

key = storage.push(b"hello world")
print(key)
021ced8799296ceca557832ab941a50b4a11f83478cf141f51f933f653ab9fbcc05a037cddbed06e309bf334942c4e58cdf1a46e237911ccd7fcf9787cbc7fd0

Pull data from storage¤

Example

from redast import Storage, Memory

storage = Storage(Memory())

data = storage.load(key)
print(data)
b'hello world'

Check for data in storage¤

Example

from redast import Storage, Memory

storage = Storage(Memory())

key = storage.push(b"hello world")
ok = storage.exists(key)
bad = storage.exists("brokenkey")
print(ok, bad)
True False

Pop data from storage¤

Example

from redast import Storage, Memory

storage = Storage(Memory())

key = storage.push(b"hello world")
data = storage.pop(key)
exist = storage.exists(key)
print(data, exist)
b'hello world' False

The link method links the saved data to the user identifier.

Example

from redast import Storage, Memory

storage = Storage(Memory())

storage.link("hello").push(b"hello world")
data = storage.link("hello").load()
print(data)
b'hello world'

Any python object can act as an identifier, even a lambda function.

Example

from redast import Storage, Memory

storage = Storage(Memory())

key = lambda x: x**2
storage.link(key).push(b"squaring")
qrt = storage.link(key).load()
print(qrt)
b'squaring'

A sequence of objects can be used as an identifier.

Example

from redast import Storage, Memory

storage = Storage(Memory())

storage.link("hello", "world").push(b"hello world")
data = storage.link("hello", "world").pop()
print(data)
b'hello world'