-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefer
increment
and decrement
over incr
and decr
.
- Loading branch information
Showing
5 changed files
with
31 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -538,6 +538,7 @@ def except(dict) | |
# | ||
# # The result will include all users with active status | ||
# # and with names "John" or "Jane". | ||
# | ||
def combine(dict) | ||
Ohm::Set.new( | ||
model, namespace, [:SINTER, key, [:SUNION, *model.filters(dict)]] | ||
|
@@ -652,7 +653,7 @@ def replace(models) | |
# end | ||
# | ||
# u = User.create(:name => "John", :email => "[email protected]") | ||
# u.incr :points | ||
# u.increment :points | ||
# u.posts.add(Post.create) | ||
# | ||
# When you execute `User.create(...)`, you run the following Redis | ||
|
@@ -1041,9 +1042,9 @@ def self.attribute(name, cast = nil) | |
|
||
# Declare a counter. All the counters are internally stored in | ||
# a different Redis hash, independent from the one that stores | ||
# the model attributes. Counters are updated with the `incr` and | ||
# `decr` methods, which interact directly with Redis. Their value | ||
# can't be assigned as with regular attributes. | ||
# the model attributes. Counters are updated with the `increment` | ||
# and `decrement` methods, which interact directly with Redis. Their | ||
# value can't be assigned as with regular attributes. | ||
# | ||
# Example: | ||
# | ||
|
@@ -1052,7 +1053,7 @@ def self.attribute(name, cast = nil) | |
# end | ||
# | ||
# u = User.create | ||
# u.incr :points | ||
# u.increment :points | ||
# | ||
# u.points | ||
# # => 1 | ||
|
@@ -1196,17 +1197,17 @@ def new? | |
end | ||
|
||
# Increment a counter atomically. Internally uses HINCRBY. | ||
def incr(att, count = 1) | ||
def increment(att, count = 1) | ||
redis.call("HINCRBY", key[:counters], att, count) | ||
end | ||
|
||
# Decrement a counter atomically. Internally uses HINCRBY. | ||
def decr(att, count = 1) | ||
incr(att, -count) | ||
def decrement(att, count = 1) | ||
increment(att, -count) | ||
end | ||
|
||
alias_method(:increment, :incr) | ||
alias_method(:decrement, :decr) | ||
alias_method(:incr, :increment) | ||
alias_method(:decr, :decrement) | ||
|
||
# Return a value that allows the use of models as hash keys. | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters