Python in-memory database
Project description
PyInMemStore
PyInMemStore is a lightweight, in-memory data store written in Python. It provides a simple way to store and manipulate data structures such as strings, lists, sets, and sorted sets. The store offers thread-safe operations and supports key expiry, similar to Redis.
Features
- Basic data types: Strings, Lists, Sets, and Sorted Sets.
- Thread-safe operations.
- Key expiry functionality.
- Dynamic method dispatching based on data type.
- Easy extensibility for additional data types and operations.
Data Types and Operations
String
set(key, value, ttl=None): Set a string value under a key. Optionally, specify a Time-To-Live (TTL) in seconds.get(key): Retrieve the string value for a given key.
List
lpush(key, value): Push a value to the beginning of a list at a given key.rpop(key): Pop a value from the end of a list at a given key.llen(key): Get the length of the list at a given key.
Set
sadd(key, *values): Add one or more values to a set at a given key.srem(key, *values): Remove one or more values from a set at a given key.smembers(key): Get all the members of the set at a given key.sis_member(key, value): Check if a value is a member of the set at a given key.
Sorted Set
zadd(key, scores): Add one or more member-score pairs to a sorted set at a given key.zrange(key, start, stop): Get a range of members from a sorted set at a given key, sorted by score.zscore(key, member): Get the score of a member in a sorted set at a given key.
Usage
from pyinmemstore import PyInMemStore
store = PyInMemStore(save_data=True)
store.set('hello', 'world')
print(store.get('hello'))
store.lpush('mylist', 'hello')
store.lpush('mylist', 'world')
print(store.rpop('mylist'))
store.sadd('myset', 'hello', 'world')
print(store.smembers('myset'))
store.zadd('my_sorted_set', {'Alice': 100, 'Bob': 90})
print(store.zrange('my_sorted_set', 0, -1))
print(store.zscore('my_sorted_set', 'Alice'))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyinmem-1.tar.gz
(7.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
pyinmem-1-py3-none-any.whl
(8.9 kB
view details)
File details
Details for the file pyinmem-1.tar.gz.
File metadata
- Download URL: pyinmem-1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da71c021310e5f544f32947a664ea4193feb751c8be0eb491ee99d8390eb856d
|
|
| MD5 |
99f28fc6f804bb78936784fec699fefc
|
|
| BLAKE2b-256 |
61707c520d947f60fb622ca6d76071785da47c251526f281abb6ef6dc34b1f96
|
File details
Details for the file pyinmem-1-py3-none-any.whl.
File metadata
- Download URL: pyinmem-1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c38461168371d03e42c2d7f9204351ff1c623b7a1f3144d47d8f732b741e4e40
|
|
| MD5 |
7d33c72ebf596858e864b077357a0c84
|
|
| BLAKE2b-256 |
91a891910419c2a42f7196c5267b34c8bb97151be1bd310a38e93e1d0d70ae0d
|