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))
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()
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')
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)
async def BGSAVE(self, *args): self.db.bgsave() return Resp.ok('Background saving started')
async def SAVE(self, *args): self.db.save() return Resp.ok()