redis-objects 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c9dea664a6595b39e8542280a5b91091d204d72
4
+ data.tar.gz: 953f0b08f429ee68d58bb50d4db16c2f93840781
5
+ SHA512:
6
+ metadata.gz: 7ad7b1a216ff428b194bc2b6156f5fde907cbed35dd93780e3193b69cee1306f1b66a20cb3e952fbee3280b2acf4e9a1b7d83c3caea56e95f616a9f962e2bdc9
7
+ data.tar.gz: a08b2a851e6390ab78e9ca8102efab41784468aa2fbc9f3471327b13f271dc3ab981a4c055963de4ad4ad397fe7539826bef3d1f90af887bc620986ebcecd72e
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .*.swp
2
+ *.gemspec
3
+ nbproject
4
+ pkg/
5
+ spec/*.sqlite3
6
+ .rvmrc
7
+ spec/redis.pid
8
+ .bundle/
9
+ dump.rdb
10
+ Gemfile.lock
11
+ redis-objects-*.gem
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,21 @@
1
1
  = Changelog for Redis::Objects
2
2
 
3
+ == 0.8.0 (9 Nov 2013)
4
+
5
+ * Refactor to modular include/extend approach to enable hooking and remove evals [nateware]
6
+
7
+ * Custom id field via redis_id_field :whatever [liuming]
8
+
9
+ * Support marshaling of sorted set key names for incr/decr [hfwang]
10
+
11
+ * Add support for pushing multiple values into a list [scranton]
12
+
13
+ * Fix problematic typo in HashKey#fill [johnmaxwell]
14
+
15
+ * Fix wrong parameter order for revrangebyscore method [FoGhost]
16
+
17
+ * Convert to using Bundler from Jeweler to manage gem [nateware]
18
+
3
19
  == 0.7.0 (27 Feb 2013)
4
20
 
5
21
  * Enable inheritance of Redis::Objects models [rossta]
data/Gemfile CHANGED
@@ -1,8 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- gem 'redis', '>= 3.0.2'
3
- #group :development do
4
- # gem 'redis-namespace'
5
- # gem 'bacon'
6
- # gem 'jeweler'
7
- # gem 'activerecord'
8
- #end
2
+
3
+ # Specify your gem's dependencies in redis-objects.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ The Artistic License 2.0
2
+
3
+ Copyright (c) 2000-2006, The Perl Foundation.
4
+
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ This license establishes the terms under which a given free software
11
+ Package may be copied, modified, distributed, and/or redistributed.
12
+ The intent is that the Copyright Holder maintains some artistic
13
+ control over the development of that Package while still keeping the
14
+ Package available as open source and free software.
15
+
16
+ You are always permitted to make arrangements wholly outside of this
17
+ license directly with the Copyright Holder of a given Package. If the
18
+ terms of this license do not permit the full use that you propose to
19
+ make of the Package, you should contact the Copyright Holder and seek
20
+ a different licensing arrangement.
21
+
22
+ Definitions
23
+
24
+ "Copyright Holder" means the individual(s) or organization(s)
25
+ named in the copyright notice for the entire Package.
26
+
27
+ "Contributor" means any party that has contributed code or other
28
+ material to the Package, in accordance with the Copyright Holder's
29
+ procedures.
30
+
31
+ "You" and "your" means any person who would like to copy,
32
+ distribute, or modify the Package.
33
+
34
+ "Package" means the collection of files distributed by the
35
+ Copyright Holder, and derivatives of that collection and/or of
36
+ those files. A given Package may consist of either the Standard
37
+ Version, or a Modified Version.
38
+
39
+ "Distribute" means providing a copy of the Package or making it
40
+ accessible to anyone else, or in the case of a company or
41
+ organization, to others outside of your company or organization.
42
+
43
+ "Distributor Fee" means any fee that you charge for Distributing
44
+ this Package or providing support for this Package to another
45
+ party. It does not mean licensing fees.
46
+
47
+ "Standard Version" refers to the Package if it has not been
48
+ modified, or has been modified only in ways explicitly requested
49
+ by the Copyright Holder.
50
+
51
+ "Modified Version" means the Package, if it has been changed, and
52
+ such changes were not explicitly requested by the Copyright
53
+ Holder.
54
+
55
+ "Original License" means this Artistic License as Distributed with
56
+ the Standard Version of the Package, in its current version or as
57
+ it may be modified by The Perl Foundation in the future.
58
+
59
+ "Source" form means the source code, documentation source, and
60
+ configuration files for the Package.
61
+
62
+ "Compiled" form means the compiled bytecode, object code, binary,
63
+ or any other form resulting from mechanical transformation or
64
+ translation of the Source form.
65
+
66
+
67
+ Permission for Use and Modification Without Distribution
68
+
69
+ (1) You are permitted to use the Standard Version and create and use
70
+ Modified Versions for any purpose without restriction, provided that
71
+ you do not Distribute the Modified Version.
72
+
73
+
74
+ Permissions for Redistribution of the Standard Version
75
+
76
+ (2) You may Distribute verbatim copies of the Source form of the
77
+ Standard Version of this Package in any medium without restriction,
78
+ either gratis or for a Distributor Fee, provided that you duplicate
79
+ all of the original copyright notices and associated disclaimers. At
80
+ your discretion, such verbatim copies may or may not include a
81
+ Compiled form of the Package.
82
+
83
+ (3) You may apply any bug fixes, portability changes, and other
84
+ modifications made available from the Copyright Holder. The resulting
85
+ Package will still be considered the Standard Version, and as such
86
+ will be subject to the Original License.
87
+
88
+
89
+ Distribution of Modified Versions of the Package as Source
90
+
91
+ (4) You may Distribute your Modified Version as Source (either gratis
92
+ or for a Distributor Fee, and with or without a Compiled form of the
93
+ Modified Version) provided that you clearly document how it differs
94
+ from the Standard Version, including, but not limited to, documenting
95
+ any non-standard features, executables, or modules, and provided that
96
+ you do at least ONE of the following:
97
+
98
+ (a) make the Modified Version available to the Copyright Holder
99
+ of the Standard Version, under the Original License, so that the
100
+ Copyright Holder may include your modifications in the Standard
101
+ Version.
102
+
103
+ (b) ensure that installation of your Modified Version does not
104
+ prevent the user installing or running the Standard Version. In
105
+ addition, the Modified Version must bear a name that is different
106
+ from the name of the Standard Version.
107
+
108
+ (c) allow anyone who receives a copy of the Modified Version to
109
+ make the Source form of the Modified Version available to others
110
+ under
111
+
112
+ (i) the Original License or
113
+
114
+ (ii) a license that permits the licensee to freely copy,
115
+ modify and redistribute the Modified Version using the same
116
+ licensing terms that apply to the copy that the licensee
117
+ received, and requires that the Source form of the Modified
118
+ Version, and of any works derived from it, be made freely
119
+ available in that license fees are prohibited but Distributor
120
+ Fees are allowed.
121
+
122
+
123
+ Distribution of Compiled Forms of the Standard Version
124
+ or Modified Versions without the Source
125
+
126
+ (5) You may Distribute Compiled forms of the Standard Version without
127
+ the Source, provided that you include complete instructions on how to
128
+ get the Source of the Standard Version. Such instructions must be
129
+ valid at the time of your distribution. If these instructions, at any
130
+ time while you are carrying out such distribution, become invalid, you
131
+ must provide new instructions on demand or cease further distribution.
132
+ If you provide valid instructions or cease distribution within thirty
133
+ days after you become aware that the instructions are invalid, then
134
+ you do not forfeit any of your rights under this license.
135
+
136
+ (6) You may Distribute a Modified Version in Compiled form without
137
+ the Source, provided that you comply with Section 4 with respect to
138
+ the Source of the Modified Version.
139
+
140
+
141
+ Aggregating or Linking the Package
142
+
143
+ (7) You may aggregate the Package (either the Standard Version or
144
+ Modified Version) with other packages and Distribute the resulting
145
+ aggregation provided that you do not charge a licensing fee for the
146
+ Package. Distributor Fees are permitted, and licensing fees for other
147
+ components in the aggregation are permitted. The terms of this license
148
+ apply to the use and Distribution of the Standard or Modified Versions
149
+ as included in the aggregation.
150
+
151
+ (8) You are permitted to link Modified and Standard Versions with
152
+ other works, to embed the Package in a larger work of your own, or to
153
+ build stand-alone binary or bytecode versions of applications that
154
+ include the Package, and Distribute the result without restriction,
155
+ provided the result does not expose a direct interface to the Package.
156
+
157
+
158
+ Items That are Not Considered Part of a Modified Version
159
+
160
+ (9) Works (including, but not limited to, modules and scripts) that
161
+ merely extend or make use of the Package, do not, by themselves, cause
162
+ the Package to be a Modified Version. In addition, such works are not
163
+ considered parts of the Package itself, and are not subject to the
164
+ terms of this license.
165
+
166
+
167
+ General Provisions
168
+
169
+ (10) Any use, modification, and distribution of the Standard or
170
+ Modified Versions is governed by this Artistic License. By using,
171
+ modifying or distributing the Package, you accept this license. Do not
172
+ use, modify, or distribute the Package, if you do not accept this
173
+ license.
174
+
175
+ (11) If your Modified Version has been derived from a Modified
176
+ Version made by someone other than you, you are nevertheless required
177
+ to ensure that your Modified Version complies with the requirements of
178
+ this license.
179
+
180
+ (12) This license does not grant you the right to use any trademark,
181
+ service mark, tradename, or logo of the Copyright Holder.
182
+
183
+ (13) This license includes the non-exclusive, worldwide,
184
+ free-of-charge patent license to make, have made, use, offer to sell,
185
+ sell, import and otherwise transfer the Package with respect to any
186
+ patent claims licensable by the Copyright Holder that are necessarily
187
+ infringed by the Package. If you institute patent litigation
188
+ (including a cross-claim or counterclaim) against any party alleging
189
+ that the Package constitutes direct or contributory patent
190
+ infringement, then this Artistic License to you shall terminate on the
191
+ date that such litigation is filed.
192
+
193
+ (14) Disclaimer of Warranty:
194
+ THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
195
+ IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
196
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
197
+ NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL
198
+ LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL
199
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
200
+ DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF
201
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
202
+
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  Redis::Objects - Map Redis types directly to Ruby objects
2
2
  =========================================================
3
3
 
4
+ [![Build Status](https://travis-ci.org/nateware/redis-objects.png)](https://travis-ci.org/nateware/redis-objects)
5
+ [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MJF7JU5M7F8VL)
6
+
4
7
  This is **not** an ORM. People that are wrapping ORM’s around Redis are missing the point.
5
8
 
6
9
  The killer feature of Redis is that it allows you to perform _atomic_ operations
@@ -8,7 +11,7 @@ on _individual_ data structures, like counters, lists, and sets. The **atomic**
8
11
  Using an ORM wrapper that retrieves a "record", updates values, then sends those values back,
9
12
  _removes_ the atomicity, cutting the nuts off the major advantage of Redis. Just use MySQL, k?
10
13
 
11
- This gem provides a Rubyish interface to Redis, by mapping [Redis types](http://redis.io/commands)
14
+ This gem provides a Rubyish interface to Redis, by mapping [Redis data types](http://redis.io/commands)
12
15
  to Ruby objects, via a thin layer over the `redis` gem. It offers several advantages
13
16
  over the lower-level redis-rb API:
14
17
 
@@ -22,8 +25,8 @@ for a fun rant on the topic, see [An Atomic Rant](http://nateware.com/2010/02/18
22
25
  or scroll down to [Atomic Counters and Locks](#atomicity) in this README.
23
26
 
24
27
  There are two ways to use Redis::Objects, either as an include in a model class (to
25
- integrate with ORMs or other classes), or by using new with the type of data structure
26
- you want to create.
28
+ tightly integrate with ORMs or other classes), or standalone by using classes such
29
+ as `Redis::List` and `Redis::SortedSet`.
27
30
 
28
31
  Installation and Setup
29
32
  ----------------------
@@ -31,22 +34,21 @@ Add it to your Gemfile as:
31
34
 
32
35
  gem 'redis-objects'
33
36
 
34
- **Redis::Objects** needs a handle created by `Redis.new`. The recommended approach
35
- is to set `Redis.current` to point to your server, which **Redis::Objects** will
37
+ Redis::Objects needs a handle created by `Redis.new`. The recommended approach
38
+ is to set `Redis.current` to point to your server, which Redis::Objects will
36
39
  pick up automatically.
37
40
 
38
- require 'redis/objects'
39
41
  Redis.current = Redis.new(:host => '127.0.0.1', :port => 6379)
40
42
 
41
43
  (If you're on Rails, `config/initializers/redis.rb` is a good place for this.)
42
- Remember you can use **Redis::Objects** in any Ruby code. There are **no** dependencies
44
+ Remember you can use Redis::Objects in any Ruby code. There are **no** dependencies
43
45
  on Rails. Standalone, Sinatra, Resque - no problem.
44
46
 
45
47
  Alternatively, you can set the `redis` handle directly:
46
48
 
47
49
  Redis::Objects.redis = Redis.new(...)
48
50
 
49
- Finally, you can even setup different handles for different classes:
51
+ Finally, you can even set different handles for different classes:
50
52
 
51
53
  class User
52
54
  include Redis::Objects
@@ -55,23 +57,19 @@ Finally, you can even setup different handles for different classes:
55
57
  include Redis::Objects
56
58
  end
57
59
 
58
- User.redis = Redis.new(...)
59
- Post.redis = Redis.new(...)
60
+ User.redis = Redis.new(:host => '1.2.3.4')
61
+ Post.redis = Redis.new(:host => '5.6.7.8')
60
62
 
61
63
  As of `0.7.0`, `redis-objects` now autoloads the appropriate `Redis::Whatever`
62
64
  classes on demand. Previous strategies of individually requiring `redis/list`
63
65
  or `redis/set` are no longer required.
64
66
 
65
- There are two ways to use **Redis::Objects**: As part of an model class (ActiveRecord,
66
- DataMapper, Mongoid, etc) or as standalong data type classes (`Redis::Set`, `Redis::List`, etc).
67
-
68
- Option 1: Model Class Usage
69
- ============================
70
- Using Redis::Objects this way makes it trivial to integrate Redis types with an
71
- existing ActiveRecord model, DataMapper resource, or other class. **Redis::Objects**
72
- will work with _any_ class that provides an `id` method that returns a unique
73
- value. **Redis::Objects** will then automatically create keys that are unique to
74
- each object, in the format:
67
+ Option 1: Model Class Include
68
+ =============================
69
+ Including Redis::Objects in a model class makes it trivial to integrate Redis types
70
+ with an existing ActiveRecord, DataMapper, Mongoid, or similar class. **Redis::Objects
71
+ will work with _any_ class that provides an `id` method that returns a unique value.**
72
+ Redis::Objects automatically creates keys that are unique to each object, in the format:
75
73
 
76
74
  model_name:id:field_name
77
75
 
@@ -91,8 +89,12 @@ For illustration purposes, consider this stub class:
91
89
  user.my_posts.increment
92
90
  user.my_posts.increment
93
91
  puts user.my_posts # 3
92
+ user.my_posts.reset
93
+ puts user.my_posts.value # 0
94
+ user.my_posts.reset 5
95
+ puts user.my_posts.value # 5
94
96
 
95
- You can include Redis::Objects in any type of class:
97
+ Here's an example that integrates several data types with an ActiveRecord model:
96
98
 
97
99
  class Team < ActiveRecord::Base
98
100
  include Redis::Objects
@@ -133,7 +135,7 @@ Sets work too:
133
135
  end
134
136
  player = @team.outfielders.detect{|of| of == 'outfielder2'}
135
137
 
136
- And you can do intersections between objects (kinda cool):
138
+ And you can do unions and intersections between objects (kinda cool):
137
139
 
138
140
  @team1.outfielders | @team2.outfielders # outfielders on both teams
139
141
  @team1.outfielders & @team2.outfielders # in baseball, should be empty :-)
@@ -145,6 +147,17 @@ Counters can be atomically incremented/decremented (but not assigned):
145
147
  @team.hits.incr(3) # add 3
146
148
  @team.runs = 4 # exception
147
149
 
150
+ Defining a different method as the `id` field is easy
151
+
152
+ class User
153
+ include Redis::Objects
154
+ redis_id_field :uid
155
+ counter :my_posts
156
+ end
157
+
158
+ user.uid # 195137a1bdea4473
159
+ user.my_posts.increment # 1
160
+
148
161
  Finally, for free, you get a `redis` method that points directly to a Redis connection:
149
162
 
150
163
  Team.redis.get('somekey')
@@ -230,7 +243,7 @@ You can bound the size of the list to only hold N elements like so:
230
243
  # Only holds 10 elements, throws out old ones when you reach :maxlength.
231
244
  @list = Redis::List.new('list_name', :maxlength => 10)
232
245
 
233
- Complex data types are no handled with :marshal => true:
246
+ Complex data types are now handled with :marshal => true:
234
247
 
235
248
  @list = Redis::List.new('list_name', :marshal => true)
236
249
  @list << {:name => "Nate", :city => "San Diego"}
data/Rakefile CHANGED
@@ -1,62 +1,9 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "redis-objects"
8
- gem.summary = %Q{Map Redis types directly to Ruby objects}
9
- gem.description = %Q{Map Redis types directly to Ruby objects. Works with any class or ORM.}
10
- gem.email = "nwiger@gmail.com"
11
- gem.homepage = "http://github.com/nateware/redis-objects"
12
- gem.authors = ["Nate Wiger"]
13
- gem.add_development_dependency "bacon", ">= 0"
14
- gem.add_development_dependency "redis-namespace", ">= 1.2.0"
15
- #gem.requirements << 'redis, v3.0.2 or greater'
16
- #gem.add_dependency('redis', '>= 3.0.2') # ALSO: update spec/spec_helper.rb
17
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
- end
19
- Jeweler::GemcutterTasks.new
20
- rescue LoadError
21
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
- end
23
-
24
- # require 'rdoc/task'
25
- # Rake::TestTask.new(:spec) do |spec|
26
- # spec.libs << 'lib' << 'spec'
27
- # spec.pattern = 'spec/**/*_spec.rb'
28
- # spec.verbose = true
29
- # end
1
+ require "bundler/gem_tasks"
30
2
 
31
3
  desc "run all the specs"
32
4
  task :test do
33
5
  sh "bacon spec/*_spec.rb"
34
6
  end
35
7
 
8
+ task :default => :test
36
9
 
37
- begin
38
- require 'rcov/rcovtask'
39
- Rcov::RcovTask.new do |spec|
40
- spec.libs << 'spec'
41
- spec.pattern = 'spec/**/*_spec.rb'
42
- spec.verbose = true
43
- end
44
- rescue LoadError
45
- task :rcov do
46
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
47
- end
48
- end
49
-
50
- task :spec => :check_dependencies
51
-
52
- task :default => :spec
53
-
54
- require 'rdoc/task'
55
- Rake::RDocTask.new do |rdoc|
56
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
57
-
58
- rdoc.rdoc_dir = 'rdoc'
59
- rdoc.title = "Redis::Objects #{version}"
60
- rdoc.rdoc_files.include('README*')
61
- rdoc.rdoc_files.include('lib/**/*.rb')
62
- end