예제 #1
0
파일: pie.py 프로젝트: stargazer/Red-Pie
 def dbsize(self):
     """ Returns the number of keys in the currently selected database
     
         @return: Integer reply            
     """
     self.connect()
     self.sock.sendall(comm.constructMessage("DBSIZE"))
     return self.handleResponse()
예제 #2
0
파일: pie.py 프로젝트: stargazer/Red-Pie
    def flushdb(self):
        """ Remove all keys from the current database.

            @return: Status code reply.
        """
        self.connect()
        self.sock.sendall(comm.constructMessage("FLUSHDB"))
        return self.handleResponse()
예제 #3
0
파일: pie.py 프로젝트: stargazer/Red-Pie
    def select(self, index):
        """ Selects the DB which has the specified zero-based
            numeric index.

            @return: Status code reply. OK if connection was successful
        """
        self.connect()
        self.sock.sendall(comm.constructMessage("SELECT",[index]))
        return self.handleResponse()
예제 #4
0
파일: pie.py 프로젝트: stargazer/Red-Pie
    def hget(self, key, field):
        """ Returns the value associated with field, in the hash at key.

            @return: Bulk reply.
            The value associated with field, or None if field is not present or
            key does not exist
        """ 
        self.connect()
        self.sock.sendall(comm.constructMessage("HGET", [key,field]))
        return self.handleResponse()
예제 #5
0
파일: pie.py 프로젝트: stargazer/Red-Pie
    def hset(self, key, field, value):
        """  Sets the field in the hash stored at key, to value.

            @return: Integer reply. 
            1 if field is new and the value was set.
            0 if field already exists in the hash and the value was updated.
        """  
        self.connect()
        self.sock.sendall(comm.constructMessage("HSET", [key, field, value]))
        return self.handleResponse()
예제 #6
0
파일: pie.py 프로젝트: stargazer/Red-Pie
    def get(self, key):
        """ Get the value of a key. If the key does not exist, the special 
            value nil is returned. 

            @return: Bulk reply. 
            The value of key, or None when key does not exist.
        """ 
        self.connect()
        self.sock.sendall(comm.constructMessage("GET", [key]))
        return self.handleResponse()
예제 #7
0
파일: pie.py 프로젝트: stargazer/Red-Pie
 def set(self,key,value):           
     """ Set the string value of a key. If key already holds its 
         value, its overwritten, regardless of its type
         
         @return: Status code reply. 
         Always OK
     """
     self.connect()
     self.sock.sendall(comm.constructMessage("SET", [key,value]))
     return self.handleResponse()
예제 #8
0
파일: pie.py 프로젝트: stargazer/Red-Pie
    def hkeys(self, key):
        """ Returns all field names in the hash stored at key.

            @return: Multi-bulk reply.
            List of fields in the hash, or an empty list when key does not
            exist.
        """
        self.connect()
        self.sock.sendall(comm.constructMessage("HKEYS", [key]))
        return self.handleResponse()
예제 #9
0
파일: pie.py 프로젝트: stargazer/Red-Pie
 def hmset(self, key, *field_value):
     """ Sets the specified fields to their respective values in the hash
         stored at key.
         
         @param field_value: Tuple of arguments. field1, value1, field2,
         value2, ...
         @return: Status code reply 
     """        
     self.connect()
     self.sock.sendall(comm.constructMessage("HMSET", [key] + list(field_value)))
     return self.handleResponse()
예제 #10
0
파일: pie.py 프로젝트: stargazer/Red-Pie
    def exists(self, key):
        """ Test if the specified key exists.

            @return: Integer reply.
            1, if the key exists
            0, otherwise
            
        """
        self.connect()
        self.sock.sendall(comm.constructMessage("EXISTS", [key]))
        return self.handleResponse()
예제 #11
0
파일: pie.py 프로젝트: stargazer/Red-Pie
 def hgetall(self, key):
     """ Returns all fields and values of the hash stored at key
     
         @return: Multi-bulk reply.
         A dictionary of field:value pairs stored at key.
     """
     self.connect()
     self.sock.sendall(comm.constructMessage("HGETALL", [key]))
     # Returns a list
     response = self.handleResponse()
     # Which I transform to a dictionary
     dic = {} 
     if isinstance(response, list):
         for i in range(0, len(response), 2):
             dic[response[i]] = response[i+1]
         return dic
     return False
예제 #12
0
파일: pie.py 프로젝트: stargazer/Red-Pie
    def quit(self):
        """ Asks the server to close the connection. The socket closes.
            Subsequent connections will use different sockets.

            @return: Status code reply. Always returns OK
        """               
        self.connect()
        self.sock.sendall(comm.constructMessage("QUIT"))
        # self.sock = None    # The socket has closed the connection. None
                              # is used in connect() to symbolize this.
        
        #del self           # del, only removes the local reference to the
                            # object. So if I had placed "del object" here,
                            # the object would just unbind from the self var.
                            # It would still exist on the calling program's 
                            # namespace, since there still would be a reference
                            # there
                           
        return "OK"
예제 #13
0
파일: pie.py 프로젝트: stargazer/Red-Pie
 def keys(self, pattern = None):
     self.connect()
     self.sock.sendall(comm.constructMessage("KEYS", [pattern]))
     return self.handleResponse()
예제 #14
0
파일: pie.py 프로젝트: stargazer/Red-Pie
 def save(self):
     """ Synchronously save the dataset to disk.
     """
     self.connect()
     self.sock.sendall(comm.constructMessage("SAVE"))
     return self.handleResponse()