Skip to content

modified redis pipeline invocations #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v1.7.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Gemfile.lock
redis-objects-*.gem
coverage/
.DS_Store
.idea/
12 changes: 6 additions & 6 deletions lib/redis/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def push(*values)
# Remove a member from the end of the list. Redis: RPOP
def pop(n=nil)
if n
result, = redis.multi do
redis.lrange(key, -n, -1)
redis.ltrim(key, 0, -n - 1)
result, = redis.multi do |pipeline|
pipeline.lrange(key, -n, -1)
pipeline.ltrim(key, 0, -n - 1)
end
unmarshal result
else
Expand Down Expand Up @@ -65,9 +65,9 @@ def unshift(*values)
# Remove a member from the start of the list. Redis: LPOP
def shift(n=nil)
if n
result, = redis.multi do
redis.lrange(key, 0, n - 1)
redis.ltrim(key, n, -1)
result, = redis.multi do |pipeline|
pipeline.lrange(key, 0, n - 1)
pipeline.ltrim(key, n, -1)
end
unmarshal result
else
Expand Down
12 changes: 6 additions & 6 deletions lib/redis/sorted_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ def intersection(*sets)
result = nil
temp_key = :"#{key}:intersection:#{Time.current.to_i + rand}"

redis.multi do
redis.multi do |pipeline|
interstore(temp_key, *sets)
redis.expire(temp_key, 1)
pipeline.expire(temp_key, 1)

result = redis.zrange(temp_key, 0, -1)
result = pipeline.zrange(temp_key, 0, -1)
end

result.value
Expand Down Expand Up @@ -241,11 +241,11 @@ def union(*sets)
result = nil
temp_key = :"#{key}:union:#{Time.current.to_i + rand}"

redis.multi do
redis.multi do |pipeline|
unionstore(temp_key, *sets)
redis.expire(temp_key, 1)
pipeline.expire(temp_key, 1)

result = redis.zrange(temp_key, 0, -1)
result = pipeline.zrange(temp_key, 0, -1)
end

result.value
Expand Down