
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Add this line to your application's Gemfile:
gem 'active_redis_orm'
And then execute:
$ bundle
Or install it yourself as:
$ gem install active_redis_orm
In an initializer, make sure that you're using the correct connection:
ActiveRedis.redis = Redis.new(connection_details)
Creating an ActiveRedis class looks like a combination of ActiveRecord and Mongoid:
class User < ActiveRedis::Base
field :username, finder_field: true
field :name
field :birthday, type: :date
field :age, type: :integer, default: lambda{|user| user.age_from_birthday}
field :things, type: :set
end
Declaring fields is similar to Mongoid - you declare the field, and its type (the default is string). We use symbols for type, unlike Mongoid which uses the data type's class.
Available types are: :string, :set, :sorted_set, :list, :hash, :float, :integer (or :int), :counter, :boolean, :date, :time (or :datetime, :timestamp).
You can declare a default value with either a value or a lambda.
When you want to be able to find an object by something other than its ID, you can define an index by stating a field to be a finder_field. This will allow you to do this:
User.create(username: "some_guy")
User.find_by_username("some_guy") #=> our user
When finding by ID, returns the object or nil. By default, every ActiveRedis class has a #presence_field method which is defaulted to "1", you can override the need for this if you have another way to determine presence (i.e. another field which says "this object surely exists"), in which case, override the "presence_field" class variable:
class User < ActiveRedis::Base
field :name
self.presence_field = :name
end
This way the #present? method on User will call the name method and check if it's present.
Using hashes, sets, sorted sets and lists is simple-ish.
Hash simply acts like a hash
Sets and Lists act like any ruby array
Sorted sets' getters act as an array, but setters are hash-like, where the hash key is the value and hash value is the score. Yes, it's a bit confusing.
class User < ActiveRedis::Base
field :foo, type: :sorted_set
end
user = User.new
user.foo["value2"] = 1
user.foo["value1"] = 0
user.save
user.foo #=> ["value1", "value2"]
Callbacks and validations work just like in Mongoid or ActiveRecord
class Messages < ActiveRedis::Base
include ActiveRedis::Timestamps
field :text
field :user_id
validates :text, presence: true, length: {maximum: 256}
validates :user_id, presence: true
after_create :do_something
def do_something
#this gets called after create
end
end
message = Message.new(text: "I am new text")
message.save #=> false
message.errors.messages #=> {:user_id=>["can't be blank"]}
available callbacks are before/after/around for create/update/save
available validations are any validations which come with ActiveModel (we're still missing the uniqueness validation, as it's a problem in redis, but it'll happen)
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that active_redis_orm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.