german / redis_orm Goto Github PK
View Code? Open in Web Editor NEWORM for Redis
License: MIT License
ORM for Redis
License: MIT License
It would be useful to define properties of type Symbol. As of Ruby 2.2, Symbols can be GCed.
redis-orm was resolved to 0.0.4, which depends on
activemodel (~> 3.0.10)
Hi @german,
I see some changes in master. Any chance you could push a new version as I believe it's currently broken.
Thanks in advance!
For example:
When 'user:1' has expired,the 'user:1' must be removed. But user:ids also contain 1.
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!
It would be useful to override the id
property to allow using unique Strings instead of incremental IDs or UUIDs.
Is it theoretically hard to store array and hash as a property? These two types are pretty basic so I want to know if it is possible to monkey patch these two in.
Hi,
Your redis gem looks really interesting.... few questions... does it support rails 3.1 and how long do the records live? Are you using http://redis.io/commands/expire at all?
Many thanks
It would be useful to allow support for activemodel 6.2 and activesupport 6.1.4.6, especially with Rails 6 release
When building a has_one
or belongs_to
association that maps to an ActiveRecord model, a lookup is done in each of the association types for an old association that will later be cleared. However, when the lookup happens when there is no prior association, it fails. As such:
1. @comment = Comment.new(:message => 'Awesome Comment')
2. @comment.user = User.first # User is ActiveRecord
3. @comment.save
... would fail on line 2 because of the way the lookup is done for a has_one and belongs_to lookup with:
Couldn't find User without an ID
The lookup is made in lib/redis_orm/associations/belongs_to.rb
, on lines 43-44,
# we need to store this to clear old association later
old_assoc = self.send(foreign_model_name)
... that calls foreign_model_name
method that finds the record using the id value it gets from Redis, which returns nil if never previously associated. When nil is passed to an ActiveRecord model's find
method, ActiveRecord raises an error because find_by_ids
checks to see if there are 0, 1, or many ids being passed, and raising an error if the length is 0. (See: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/finder_methods.rb#L244)
When old_assoc
is later checked to see if the old associated records (if !old_assoc.nil?
/ if old_assoc
), the best fix, IMO, would be to add rescue nil
when sending foreign_model_name
, or adding a rescue clause in foreign_model_name
, such as:
old_assoc = self.send(foreign_model_name) rescue nil
Another option is to adding some check during foreign_model_name
to see if an association exist before finding the associated record, return nil before attempting to find the associated record.
Holla which method you like and I can help patch.
I created 2 models
class User < RedisOrm::Base
property :name, String
has_many :books
end
class Book < RedisOrm::Base
property :title, String
has_many :users, as: :authors
end
And
user = User.create(name: 'Kent Beck')
user.books << Book.create(title: 'Refactoring')
But this code fails as follows:
undefined method `pluralize' for :authors:Symbol
How should I do in this case?
has_many
looks like not support HABTM
https://github.com/german/redis_orm/blob/master/lib/redis_orm/associations/has_many.rb#L7
Possibly a case of: rails/rails#14664
As I see in redis_orm.rb a bunch of lines requiring very specific files in ActiveSupport.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.