Beispiel #1
0
    def Persist(self):
        from Database import Redis
        r = Redis(use_pipeline=True)

        self._id = str(r.increment(Challenge.primary_key,True))
        r.add_to_set(Challenge.set_key + ':not_awarded', Challenge.key +':'+self._id)

        r.set(Challenge.key + ':' + self._id + ':challenged', self.challenged)
        r.set(Challenge.key + ':' + self._id + ':points', self.points)
        r.set(Challenge.key + ':' + self._id + ':message', self.message)
        r.set(Challenge.key + ':' + self._id + ':awarded', self.awarded)

        r.execute_pipe()
Beispiel #2
0
    def GetAll():
        from Database import Redis
        r = Redis(use_pipeline=True)

        challenges = r.get_set(Challenge.set_key +':not_awarded',True)

        for challenge in challenges:
            r.echo(challenge.partition(':')[2])
            r.get(challenge +':challenged')
            r.get(challenge +':points')
            r.get(challenge +':message')

        challenge_objs = r.execute_pipe()
        print challenge_objs
        list_of_challenges = list()
        i =0
        c = None
        for row in challenge_objs:
            if i % 4 == 0:
                if c != None:
                    list_of_challenges.append(c)
                c = Challenge()
                c._id = row
            elif i % 4 == 1:
                c.challenged = row
            elif i % 4 == 2:
                c.points = row
            elif i % 4 == 3:
                c.message = row

            i = i+1
        if c != None:
            list_of_challenges.append(c)

        return list_of_challenges