Beispiel #1
0
def load():
    ds.flushdb()

    c1 = create_city('Reixte', True)
    c2 = create_city('Damtoo', True)
    c3 = create_city('Toynbe', False)
    create_connection(c1, c2)
    create_connection(c1, c3)

    f1 = create_fighter('Alice', 20, 107.44, 1400000002)
    f2 = create_fighter('Bob', 23, 102.923, 1400000001)

    g1 = create_gang('Ghetto Warriors', f1)
    add_member(g1, f1)
    add_member(g1, f2)
    add_gang_city(g1, c1)
    add_gang_city(g1, c3)
    g2 = create_gang('Midnight Club', Fighter.by_id(0))

    # add weapons to fighter; weapons are owned (owned = True on the
    # SortedSetField), so we attach weapon writer to fighter weapons writer
    weapon_writer = ModelWriter(Weapon)
    fighter_weapons_writer = SortedSetFieldWriter(Fighter.weapons, weapon_writer)
    w1 = Weapon(description = 'second', power = 50.5)
    w2 = Weapon(description = 'third', power = 34.2)
    w3 = Weapon(description = 'first', power = 50.7)
    for w in w1, w2, w3:
        fighter_weapons_writer.append(f1.weapons, w)

    # skills
    skill_writer = ModelWriter(Skill)
    sk1 = Skill(category = 1, name = 'Strength', description = 'Strength...')
    sk2 = Skill(category = 3, name = 'Karate', description = 'Karate...')
    map(skill_writer.create, [sk1, sk2])

    fighter_skill_list_writer = ModelWriter(FighterSkillList)
    f1skills = FighterSkillList()
    f2skills = FighterSkillList()
    fighter_skill_list_writer.create(f1skills, f1)
    fighter_skill_list_writer.create(f2skills, f2)

    # can do this if and only if owned = True in the ListField
    skill_instance_writer = ModelWriter(SkillInstance)
    fighter_skills_writer = ListFieldWriter(FighterSkillList.skills, element_writer = skill_instance_writer)
    ski1 = SkillInstance(skill = sk1.handle(), value = 21)
    ski2 = SkillInstance(skill = sk2, value = 15)
    fighter_skills_writer.append(f1skills.skills, ski1)
    fighter_skills_writer.append(f1skills.skills, ski2)

    ski1 = SkillInstance(skill = sk1, value = 27)
    ski2 = SkillInstance(skill = sk2, value = 91)
    fighter_skills_writer.append(f2skills.skills, ski1)
    fighter_skills_writer.append(f2skills.skills, ski2)
Beispiel #2
0
from redmodel.models import Model, Attribute, IntegerField, ListField
from redmodel.models import ModelWriter, ListFieldWriter
from redmodel.containers import List

# clean all data
from redmodel import connection
connection.flushdb()

# define Color class
class Color(Model):
    name = Attribute(unique = True)
    rgb = IntegerField()

# define Person class
class Person(Model):
    name = Attribute(unique = True)
    fave_colors = ListField(Color, indexed = True)

# create writer objects
color_writer = ModelWriter(Color)
person_writer = ModelWriter(Person)
fave_colors_writer = ListFieldWriter(Person.fave_colors)

# create some colors
c1 = Color(name = 'red', rgb = 0xff0000)
c2 = Color(name = 'green', rgb = 0x00ff00)
c3 = Color(name = 'blue', rgb = 0x0000ff)

# save the colors in Redis
map(color_writer.create, [c1, c2, c3])
Beispiel #3
0
 def setUp(self):
     ds.flushdb()