Open source Redis ORM
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
redact
tests
.gitignore
.travis.yml
LICENSE
README.markdown
setup.py
tox.ini

README.markdown

#redact-py Redact is a KISS ORM for python with transaction support.

Build Status

##License MIT license, see LICENSE.

##Performance Run tests/perf/perf.py to get results for your machine.

Here are the results running on my machine (Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz, Arch linux) :

10000 writes completed in 1.83789205551 seconds
10000 reads completed in 2.32537603378 seconds
10000 updates completed in 4.12392377853 seconds
10000 deletes completed in 1.30714297295 seconds

##Basic Usage ###Defining models:

import redact

class Prisoner(redact.BaseModel):
	def __init__(self, key, name=None, password=None):
		super(Prisoner, self).__init__(key)
		self.name = redact.KeyValueField('n', name)
		self.password = redact.KeyValueField('p', password)

###Creating models:

prisoner = Prisoner('num_6', "Patrick McGoohan", "iamnotanumber6")
redact.save(prisoner)

###Loading models:

prisoner = Prisoner('num_6')
redact.load(prisoner)
print("Name : {}".format(prisoner.name))  # Prints "Name : Patrick McGoohan"

##Advanced usage ###Transactions: Delays all writes and deletes until the end of the wrapped function:

prisoner = Prisoner('num_1', "??", "popgoesthewheasel")
redact.save(prisoner)
prisoner = Prisoner('num_2', "Colin Gordon", "The General")
redact.save(prisoner)

@redact.transaction
def delete_number_1_and_2():
    number_1 = Prisoner('num_1')
	redact.load(number_1)
	number_2 = Prisoner('num_2')
	redact.load(number_2)
	redact.delete(number_1)  # Not actually deleted until end of function
	redact.delete(number_2)
	
delete_number_1_and_2()

###Data structures ####Sorted Set

sorted_set = redact.SortedSet('prisoner_zset')
sorted_set.zadd("num_6", 6, "num_1", 1, "num_2", 2)
result = sorted_set.zrangebyscore(0, 5)  # Get first 5 prisoner IDs
print(result[0])  # Prints "num_1"
print(result[1])  # Prints "num_2"
print(len(result))  # Prints "2"

####Set

set_a = redact.Set('prisoner_set_a')
set_a.add("num_1")
set_a.add("num_2")

set_b = redact.Set('prisoner_set_b')
set_b.add("num_2")
set_b.add("num_6")

set_a.difference_update(set_b)
print set_a.smembers()  # Prints "set(['num_1'])"

####Hashset

prisoner_hash = redact.Hashset('prisoner_hashset')
prisoner_hash['num_6'] = 'uncooperative'
print 'num_6' in prisoner_hash  # Prints "True"

####List

prisoner_list = redact.List('prisoner_list')
prisoner_list.lpush('num_1')
prisoner_list.rpush('num_5', 'num_6')
print prisoner_list.rpop()  # Prints "num_6"
print prisoner_list.lpop()  # Prints "num_1"