redis-bid 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/redis_bid.rb +7 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76d99d63cab6355633ad31a5227be635543a8f08
|
4
|
+
data.tar.gz: 7ef3bf93cb3dd2f60bc7f48cb21f2ed3d545f833
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5200e8fb0a4d21d5353299d8ef0912121134a0926693778dfbe03a448f41cb6481681063e7033a1ea2c079f4c4fbf5f6fd188ddfb39e2133ff0f17f3dc7dc071
|
7
|
+
data.tar.gz: f956881154283c19bec703a36177609423b6f47860e9006b54b94f4f88ac78ddfbd252196381d05c26edcc9395f95aa7f0ffbd0b9abe4a3c1e8dadb9c683984d
|
data/lib/redis_bid.rb
CHANGED
@@ -3,7 +3,7 @@ require 'redis'
|
|
3
3
|
class RedisBid
|
4
4
|
|
5
5
|
DEFAULT_USER_ID = 0
|
6
|
-
|
6
|
+
DEFAULT_MIN_BID_SCORE = 0
|
7
7
|
|
8
8
|
BID_ITEMS_KEY_PREFIX = "bid_items"
|
9
9
|
BID_ITEM_KEY_PREFIX = "bid"
|
@@ -14,7 +14,7 @@ class RedisBid
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.register_bid_item(bid_id, options = {})
|
17
|
-
options = {
|
17
|
+
options = { min_bid_score: DEFAULT_MIN_BID_SCORE }.merge(options)
|
18
18
|
redis.sadd(BID_ITEMS_KEY_PREFIX, bid_id)
|
19
19
|
set_min_bid(bid_id, options[:min_bid_score])
|
20
20
|
end
|
@@ -24,6 +24,7 @@ class RedisBid
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.set_min_bid(bid_id, score)
|
27
|
+
return false if score < DEFAULT_MIN_BID_SCORE
|
27
28
|
return false unless is_registered?(bid_id)
|
28
29
|
redis.hset("min_bid", bid_id, score)
|
29
30
|
true
|
@@ -38,7 +39,7 @@ class RedisBid
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def self.add_user_bid(user_id, bid_id, score)
|
41
|
-
return false if score <
|
42
|
+
return false if score < get_min_bid(bid_id)
|
42
43
|
return false unless is_registered?(bid_id)
|
43
44
|
redis.zadd("BID_ITEM_KEY_PREFIX:#{bid_id}", score, user_id)
|
44
45
|
true
|
@@ -53,14 +54,14 @@ class RedisBid
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def self.list_user_bids(bid_id, options = {})
|
56
|
-
options = {
|
57
|
+
options = { min_bid_score: DEFAULT_MIN_BID_SCORE, max_score: "+inf", with_scores: false, order: "desc"}.merge(options)
|
57
58
|
return list_user_bids_in_descending_order(bid_id, options) if options[:order] == "desc"
|
58
|
-
redis.zrangebyscore("BID_ITEM_KEY_PREFIX:#{bid_id}", options[:
|
59
|
+
redis.zrangebyscore("BID_ITEM_KEY_PREFIX:#{bid_id}", options[:min_bid_score], options[:max_score], with_scores: options[:with_scores])
|
59
60
|
end
|
60
61
|
|
61
62
|
private
|
62
63
|
|
63
64
|
def self.list_user_bids_in_descending_order(bid_id, options = {})
|
64
|
-
redis.zrevrangebyscore("BID_ITEM_KEY_PREFIX:#{bid_id}", options[:max_score], options[:
|
65
|
+
redis.zrevrangebyscore("BID_ITEM_KEY_PREFIX:#{bid_id}", options[:max_score], options[:min_bid_score], with_scores: options[:with_scores])
|
65
66
|
end
|
66
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-bid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tkang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Bid System
|
14
14
|
email: tkang1@gmail.com
|