Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zefer/redised
a simple module that allows you to setup your class or module with a redis connection
https://github.com/zefer/redised
Last synced: 2 days ago
JSON representation
a simple module that allows you to setup your class or module with a redis connection
- Host: GitHub
- URL: https://github.com/zefer/redised
- Owner: zefer
- License: mit
- Created: 2012-07-11T13:53:30.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-04-09T06:31:19.000Z (over 12 years ago)
- Last Synced: 2024-04-13T23:29:51.097Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 78.1 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: LICENSE.txt
Awesome Lists containing this project
README
= redised
Redised provides a simple module for establishing reusable class level namespaced redis connections
in your vanilla Ruby classes.== Why?
We use redis a lot throughout our apps. This pattern of having a class level `redis` method
thats already namespaced and connected to a specific server via a config has served us well.
It has allowed us to split different usages across different namespaces and eventually
different hosts/servers.== Usage
You can include Redised as a module in your class.
class MyRedisClass
include Redised
endThis now gives you the power to assign the url of the redis server you want to connect to
as a string:MyRedisClass.redis = 'localhost:6739:1/myredisclass' # hostname:port:db/namespace
# also accepts a Redis or Redis::Namespace objectThis gets a little easier and more powerful when you setup a YAML config:
# in config/redis.yml
---
mynamespace:
development: localhost:6379
production: redis01:6379/mynamespace
othernamespace:
development: localhost:6379
production: redis01:6379/othernamespaceYou can tell redised where this config lives:
Redised.redised_config_path = File.join(Rails.root, 'config', 'redis.yml')
And what the 'env' is (will try to pull from RACK_ENV and RAILS_ENV):
Redised.redised_env = Rails.env #=> 'production'
Then in your class you tell it what namespace config this class points to:
class MyRedisClass
include Redisedredised_namespace 'mynamespace'
end
It will now automatically load the correct redis connection for your namespace/env:
MyRedisClass.redis #=> #
MyRedisClass.redis.client.host #=> 'redis01'
MyRedisClass.namespace #=> 'mynamespace'The implementation of the `self.redis` method is very close to the `Resque.redis` method and is
actually a drop in replacement (if you want to load your connection settings from a config). Our
`config/initializers/resque.rb` looks like:module Resque
include Redised
extend selfredised_namespace 'paperless'
end== Acknowledgments
The original parsing of URL idea came from @defunkt/resque.
== Contributing to redised
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
* Fork the project.
* Start a feature/bugfix branch.
* Commit and push until you are happy with your contribution.
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.== Copyright
Copyright (c) 2012 Aaron Quint, Paperless Inc. See LICENSE.txt for further details.