Skip to main content

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

This version

1

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

Uploaded Source

Built Distribution

pyinmem-1-py3-none-any.whl (8.9 kB view hashes)

Uploaded Python 3

Supported by

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