Example #1
0
    async def TYPE(self, count):
        if count != 1:
            return Resp.error('wrong number of arguments for TYPE command')

        key = await self.get_key()

        return Resp.ok(self.db.type_(key))
Example #2
0
    async def MSET(self, count):
        if count % 2:
            return Resp.error('wrong number of arguments for MSET')

        mapping = await self.get_key_value(count // 2)

        self.db.set(**mapping)
        return Resp.ok()
Example #3
0
    async def SET(self, count):
        if count < 2:
            return Resp.error('wrong number of arguments for SET command')
        key = await self.get_key()
        val = await self.get_key()

        cmd = [await self.get_key() for _ in range(count - 2)]

        if not cmd:
            self.db.set(**{key: val})
            return Resp.ok()

        if len(cmd) == 2 and cmd[0].lower() == 'ex':
            try:
                sec = int(cmd[1])
            except ValueError:
                return Resp.error('value is not an integer')
            self.db.set(**{key: val})
            self.db.expire(key, sec)
            TIME.expire(key)
            return Resp.ok()
        return Resp.error('syntax error')
Example #4
0
    async def LSET(self, count):
        if count != 3:
            return Resp.error('wrong number of arguments for LSET command')

        key = await self.get_key()
        index = await self.get_key()

        try:
            index = int(index)
        except ValueError:
            return Resp.error('value is not an integer')

        value = await self.get_key()

        ret = self.db.lset(key, index, value)

        if ret == 0:
            return Resp.ok()
        if ret == 1:
            return Resp.error('index out of range')
        if ret == -1:
            return Resp.encode(False)
Example #5
0
 async def BGSAVE(self, *args):
     self.db.bgsave()
     return Resp.ok('Background saving started')
Example #6
0
 async def SAVE(self, *args):
     self.db.save()
     return Resp.ok()