Esempio n. 1
0
    def get(self, key, r=None, conflict_handler=do_nothing):
        """Gets an object from Riak given a key.

        :param key: The key
        :param r: The r value
        :param conflict_handler: A function that handles conflict.
        :rtype: RObject
        """
        obj = RObject(self.client, self, key, conflict_handler)
        return obj.reload(r or self.r)
Esempio n. 2
0
    def new(self, key, data=None,
            content_type="application/json",
            conflict_handler=do_nothing):
        """Construct a new riak object. A short form for manually creating one.

        :param key: The key of the object. If you put it as None, one will be
                    generated when you save the object by Riak for you.
        :param data: The data you want to store. Make sure it matches
                     content_type. Defaults to None.
        :param content_type: The content type. Defaults to application/json
        :param conflict_handler: A conflict handler in case of conflict.
                                 Takes the object as argument and resolves
                                 conflict if necessary.
        :type conflict_handler: function
        :rtype: RObject"""
        data = self._ensure_ascii(data)
        obj = RObject(self.client, self, key, conflict_handler)
        obj.data = data
        obj.content_type = content_type

        return obj