memory_oc
Provides methods for creating and managing sessions in body_oc projects.
Please see LICENSE for further information.
See Releases for changes from release to release.
Contents
Module Install
Requires
memory_oc requires python 3.10 or higher
Install via pip
pip install memory_oc
Configuration
Memory requires the use of a config_oc config.json file. See config_oc for more info.
{
"memory": {
"redis": "session"
},
"redis": {
"session": {
"host": "redis.mydomain.com",
"db": 1
}
}
}
The redis section lists Redis connections by name and details to connect. Then
memory.redis specifies which connection to use to create the sessions on.
Methods
Memory comes with three methods, to close, create, and load sessions.
close
Immediately closes and deletes a session from Redis.
example
import memory
# Closes the session by key
memory.close(somekey)
create
Creates a new session. Takes 3 optional arguments
| Argument | Type | Description |
|---|---|---|
key |
str | The key to use to create the session in Redis. |
ttl |
unsigned integer | The time to live in seconds for the session. |
data |
dict | The initial data to be stored in the session. |
example
import memory
# Creates a 10 minutes session
session = memory.create(ttl = 600, data = {
'email': 'sam@somedomain.com',
'name': 'Sam'
})
# Stores it in Redis
session.save()
# Returns the generated session key
return session.key()
load
Loads a session from a passed key.
example
import memory
# Loads the session data from Redis
session = memory.load(somekey)
# Change data
session['name'] = 'Samuel'
# Store it in Redis
session.save()
Class
The class is what is returned from the create and load methods.
instance.close
Closes the session in Redis, making it no longer available to anyone.
example
import memory
# Load the session
session = memory.load(somekey)
# Close the session
session.close()
instance.extend
Extends the TTL of the session by the initial TTL given.
exmaple
import memory
# Load the session
session = memory.load(somekey)
# Extend the session
session.extend()
instance.key
Returns the key of the session.
example
import memory
# Create the session
session = memory.create()
# Print the key
print(session.key())
instance.save
Stores changes in Redis after updates.
example
import memory
# Load a session
session = memory.load(somekey)
# Make changes
session['name'] = 'Samuel'
# Save changes
session.save()
instance.ttl
Getter / Setter for the TTL on the session.
example
Set
import memory
# Load session
session = memory.load(somekey)
# Returns the current ttl
session.ttl()
# Updates the ttl to 5 minutes and refreshes the session
session.ttl(300)
instance.update
Works the same as dict update() so you can store multiple keys at once
example
import memory
# Load session
session = memory.load(somekey)
# Update multiple fields
session.update({
'name': 'Samuel',
'phone': '(555) 123-4567'
})
# Save changes
session.save()
Metadata
Release files for memory-oc 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| memory_oc-1.0.3.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| memory_oc-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / memory_oc-1.0.3.tar.gz
| Download URL | memory_oc-1.0.3.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dba59631e64c67e6361ec1467efc9a1995cc68d5af61d54d9dcd9f5277df4de4
|
|
BLAKE2b-256 checksum How to use checksums |
b1598426bc7f46b9ee11defc6861ed973417062693c69eaae39546d4808a7fb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / memory_oc-1.0.3-py3-none-any.whl
| Download URL | memory_oc-1.0.3-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c14ce8056450856e6f5861a40d34b95528c12f24d0f5585c40716c0e88c233e8
|
|
BLAKE2b-256 checksum How to use checksums |
c59c7ce54b82a553bda688df6f3e5e2ab1e5860d57111cb7da6941c928aa8c9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|