german / redis_orm

ORM for Redis
MIT License
89 stars 16 forks source link

NoMethodError: undefined method `incr' for nil:NilClass #13

Open scalp42 opened 5 years ago

scalp42 commented 5 years ago

Hi @german,

Thanks a lot for the gem.

I tried to replicate the example in the README and using the current master@2aa6160. Unfortunately, when trying to create or call .save on a new class, I'm running into the following issue:

class Article < RedisOrm::Base
  property :title, String
  has_many :comments
end

class Comment < RedisOrm::Base
  property :body, String
  property :moderated, RedisOrm::Boolean, :default => false
  index :moderated
  belongs_to :article
end
[12] pry(main)> article = Article.create :title => "DHH drops OpenID on 37signals"
NoMethodError: undefined method `incr' for nil:NilClass

Do you happen to have an idea by any chance? It looks $redis is nil:

    def get_next_id
      if @@use_uuid_as_id[model_name]
        @@uuid.generate(:compact)
      else
        $redis.incr("#{model_name}:id")
      end
    end

Thanks in advance!