示例#1
0
 def type(self, key):
     if self._db.get(KEY_CODEC.encode_string(key)) is not None:
         return 'string'
     if self._db.get(KEY_CODEC.encode_set(key)) is not None:
         return 'set'
     if self._db.get(KEY_CODEC.encode_hash(key)) is not None:
         return 'hash'
     if self._db.get(KEY_CODEC.encode_zset(key)) is not None:
         return 'zset'
     return 'none'
示例#2
0
文件: keyspace.py 项目: Yipit/dredis
 def rename(self, old_name, new_name):
     if self.exists(old_name):
         if old_name == new_name:
             return
         # replace the key that holds the key ID and don't touch the rest
         key_type = self.type(old_name)
         if key_type == 'zset':
             old_db_key = KEY_CODEC.encode_zset(old_name)
             new_db_key = KEY_CODEC.encode_zset(new_name)
         elif key_type == 'hash':
             old_db_key = KEY_CODEC.encode_hash(old_name)
             new_db_key = KEY_CODEC.encode_hash(new_name)
         elif key_type == 'set':
             old_db_key = KEY_CODEC.encode_set(old_name)
             new_db_key = KEY_CODEC.encode_set(new_name)
         elif key_type == 'string':
             old_db_key = KEY_CODEC.encode_string(old_name)
             new_db_key = KEY_CODEC.encode_string(new_name)
         else:
             raise DredisError("invalid key type")
         self._replace_db_key(new_db_key, old_db_key)
     else:
         raise NoKeyError()
示例#3
0
 def delete(self, *keys):
     result = 0
     for key in keys:
         if self._db.get(KEY_CODEC.encode_string(key)) is not None:
             self._delete_db_string(key)
             result += 1
         elif self._db.get(KEY_CODEC.encode_set(key)) is not None:
             self._delete_db_set(key)
             result += 1
         elif self._db.get(KEY_CODEC.encode_hash(key)) is not None:
             self._delete_db_hash(key)
             result += 1
         elif self._db.get(KEY_CODEC.encode_zset(key)) is not None:
             self._delete_db_zset(key)
             result += 1
     return result
示例#4
0
 def set(self, key, value):
     self._db.put(KEY_CODEC.encode_string(key), value)
示例#5
0
 def get(self, key):
     return self._db.get(KEY_CODEC.encode_string(key))
示例#6
0
 def _delete_db_string(self, key):
     # there is one set of db keys for strings:
     # * string
     self._db.delete(KEY_CODEC.encode_string(key))