Anand,

I rewrote your script a little bit (you did some odd things in the initialize 
method which isn't expected to return anything), and this way it works:

require 'riak'

Riak::Serializers["text/html"] = Riak::Serializers::TextPlain

class RiakClient
def initialize
super
end

def client
@client ||= Riak::Client.new(:nodes => [{:http_port => 8091},{:http_port 
=>8092},{:http_port=>8093},{:http_port =>8094}])
end

def get_me(bucket, key)
obj = client.bucket(bucket).get(key)
puts obj.data
end

def put_me(bucket, key, data, content_type)
obj = client.bucket(bucket).get_or_new(key)
obj.content_type = content_type
obj.raw_data=data
obj.store
end
end

if __FILE__ == $0
my_client = RiakClient.new
my_client.put_me("doc", "index.html", "some data goes here", "text/html")
hash = my_client.get_me("doc", "index.html")
end


Cheers, Mathias
http://riakhandbook.com





On Monday, 25. June 2012 at 07:52, Anand Hegde wrote:

> require 'riak'
> 
> 
> 
> 
> class RiakClient < Riak::Client
> #attr_accessor :bucket
> 
> def initialize(hosts="")
> return Riak::Client.new(:nodes => [{:http_port => 8091},{:http_port 
> =>8092},{:http_port=>8093},{:http_port =>8094}])
> end
> 
> def get_me(bucket, key)
> obj = self.bucket(bucket).get(key)
> puts obj.data
> end
> 
> def put_me(bucket, key, data, content_type) 
> obj=self.bucket(bucket).get_or_new(key)
> puts obj.class
> obj.content_type=content_type
> obj.raw_data=data
> obj.store
> end
> end
> 
> 
> 
> if __FILE__ == $0
> my_client=RiakClient.new
> my_client.put_me("doc", "index.html", "some data goes here", "text/html")
> hash=my_client.get_me("doc", "index.html")
> end
> 
> 
> But I am getting the following errors - 
> 
> NilClass
> riak_client.rb:32:in `put_me': undefined method `content_type=' for 
> nil:NilClass (NoMethodError)
> from riak_client.rb:42:in `<main>'
> 
> 
> Do I have to import the RiakObject and RiakClient classes and all? and how do 
> i do this? 
> _______________________________________________
> riak-users mailing list
> riak-users@lists.basho.com (mailto:riak-users@lists.basho.com)
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com




_______________________________________________
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to