Redis Entities
Project description
RedisEntities
How to install it?
You can install RedisEntites from this Github repository with python3 setup.py install
,
or just install it directly from pypi with pip3 install redis_entities
.
What is it?
Redis Entities is a small library that allows you to map represent certain entities in Redis. An Entity could be for example a Hashmap type and stores information about one User that currently requested a password reset. Each Entity has a predefined Prefix used to differentiate the different types of Entities you create. There are 4 different RedisEntities you can use:
RedisListEntity
RedisSetEntity
RedisHashmapEntity
RedisSecureHashmapEntity
RedisSecureHahmapEntity
is a subclass of RedisHashmapEntity
that provides Integrity protection to all of the
contained data in this hashmap.
How does it work?
To create an own Entity, just subclass from one of the Provided RedisEntity Base classes.
Note, that every Entity has to set the redis_client
Class Attribute to an instance of Redis
from redis-py
, or
a class that supports all methods that Redis
from redis-py
does.
RedisListEntity
import redis
from redis_entities import RedisListEntity
class JobQueueEntity(RedisListEntity):
redis_client = redis.Redis(...)
Prefix = "JobQueue"
JobQueueEntity.lpush("Worker1", "command1")
assert JobQueueEntity.length("Worker1") == 1
Supported Methods are:
lpush
brpop
get
length
clear
RedisSetEntity
import redis
from redis_entities import RedisSetEntity
class AccessTokensEntity(RedisSetEntity):
redis_client = redis.Redis(...)
Prefix = "AccessTokens"
AccessTokensEntity.add("User1", "Token1")
AccessTokensEntity.add("User2", "Token1")
assert AccessTokensEntity.exists("User1", "Token1") is True
Supported Methods are:
add
delete
clear
exists
list_all
length
RedisHashmapEntity
import redis
from redis_entities import RedisHashmapEntity
class VerifyEmailTokens(RedisHashmapEntity):
redis_client = redis.Redis(...)
Prefix = "VerifyEmailTokens"
Contents = (
"MandatoryKey1",
"MandatoryKey2"
)
Expire = 180
VerifyEmailTokens.store("test@example.com", MandatoryKey1="Value1", MandatoryKey2="Value2")
loaded_entity = VerifyEmailTokens.load("test@example.com")
assert loaded_entity.MandatoryKey1 == b"Value1"
assert loaded_entity.MandatoryKey1 == b"Value2"
assert VerifyEmailTokens.exists("test@example.com") is True
Supported Methods are:
store
load
exists
length
delete
length
All Keys are stored as strings, all values are stored as bytes.
RedisSecureHashmapEntity
import redis
from redis_entities import RedisSecureHashmapEntity
class VerifyEmailTokens(RedisSecureHashmapEntity):
redis_client = redis.Redis(...)
Prefix = "VerifyEmailTokens"
Contents = (
"MandatoryKey1",
"MandatoryKey2"
)
HMACKey = b"A" * 64
Expire = 180
_, secret_information, = VerifyEmailTokens.store("test@example.com", MandatoryKey1="Value1", MandatoryKey2="Value2")
assert isinstance(secret_information, RedisSecureHashmapEntity.SecureIntegrityEntityInformation)
loaded_entity = VerifyEmailTokens.load("test@example.com")
assert loaded_entity.MandatoryKey1 == b"Value1"
assert loaded_entity.MandatoryKey1 == b"Value2"
Supported Methods are:
- the same as
RedisHashmapEntity
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
Built Distribution
Hashes for redis_entities-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c21086eceb1808ca7ea81767063d348984af24db7c17b586865e396af767c112 |
|
MD5 | 65a6c381c49f3ea6ffec892a28d2ceda |
|
BLAKE2b-256 | 0783884f8d5e717823523513c3cd7e511cbba3c6c260b35f9d7c8aebd77439e8 |