Skip to main content

A session library using redis

Project description

memory_oc

pypi version Custom License

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

[ top / contents ]

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.

[ top / contents ]

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

[ top / contents ]

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.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()

[ top / contents ]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memory_oc-1.0.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

memory_oc-1.0.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file memory_oc-1.0.2.tar.gz.

File metadata

  • Download URL: memory_oc-1.0.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for memory_oc-1.0.2.tar.gz
Algorithm Hash digest
SHA256 04fd4f2b7d9398240941d88290241ad3fb19f4ffa48a90c0ff724998b65b7e3e
MD5 39c60d6dde26cc3363e09a9ea814772c
BLAKE2b-256 fc4635581e53e8a0813fcb528dc60cdef9b77e94d8c5765a0204e5d76482b9b9

See more details on using hashes here.

File details

Details for the file memory_oc-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: memory_oc-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for memory_oc-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 89865a25ffdca42f51f32ec8de08a893646666d75400a09f485320bef87ee725
MD5 c0f82a64227370c29cb76e0254f1e638
BLAKE2b-256 ac17222e46665c3583fd4685da8fbcb42dbe6762bac4b1cea12047e243275540

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page