frivol 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a24e083670901a1e0114ec42a4da90f666ef23f
4
- data.tar.gz: ce84cd346fde8137c233c18feb0e13858c1c5f41
3
+ metadata.gz: fb5b81ba6e03198c9bd7e33e3ce843dd3a0d48df
4
+ data.tar.gz: 1e2456b6e27f97eec9309fc7e638c498bc166f5a
5
5
  SHA512:
6
- metadata.gz: d5bfd4d1406e56a839615cca1577f31fc900d4a8f23e2ca788bbcf0d2b5ea6507fc63f635a8db9de734a8a81083973ec0d8c1670338e0b66fd6c62805765b27e
7
- data.tar.gz: f641d253e43ae8fe48ddb2bde13940289423bf877302c61d72b6d8b490feedbb1d84b2e3dc794dd03bcc0f85046979c3ee54e362cbb92390cb6c457bad5244fd
6
+ metadata.gz: 741f725ccee1f4fd43e5edde0d2de85500511c84c547dbc1af85baa2a8eff8cbc9498809d38a7c60e28d6d22eb86a43bfe42e0db74bd8e6087c1cfa8f7f4e3da
7
+ data.tar.gz: 0d1cc7ddeaffc023ccb1449a28e1ce9b9f536667d2fea6c3f7f2e5ed96663162905dc009114adef5dcb7ea38cb2cc8a2b8594f1e95ba37261efc7e0383397a73
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: frivol 0.3.0 ruby lib
5
+ # stub: frivol 0.3.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "frivol"
9
- s.version = "0.3.0"
9
+ s.version = "0.3.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -13,6 +13,7 @@ module Frivol
13
13
  # Frivol::Config.redis_config = REDIS_CONFIG
14
14
  def self.redis_config=(config)
15
15
  @@redis_config = config
16
+ @@redis_version = nil
16
17
  Thread.current[:frivol_redis] = nil
17
18
  end
18
19
 
@@ -21,6 +22,14 @@ module Frivol
21
22
  Thread.current[:frivol_redis] ||= Redis.new(@@redis_config)
22
23
  end
23
24
 
25
+ def self.redis_version
26
+ redis.info('server')['redis_version'].to_f
27
+ end
28
+
29
+ def self.requires_expiry_reset?
30
+ redis_version < 2.2
31
+ end
32
+
24
33
  def self.allow_json_create
25
34
  @@allow_json_create ||= []
26
35
  end
@@ -39,13 +39,19 @@ module Frivol
39
39
  time = instance.class.storage_expiry(bucket)
40
40
  if time == Frivol::NEVER_EXPIRE
41
41
  Frivol::Config.redis[key] = value
42
- else
42
+ elsif Frivol::Config.requires_expiry_reset?
43
+ time = redis.ttl(key).to_i unless is_new
43
44
  Frivol::Config.redis.multi do |redis|
44
- # TODO: write test for the to_i bug fix
45
- time = redis.ttl(key).to_i unless is_new
46
45
  redis[key] = value
47
46
  redis.expire(key, time)
48
47
  end
48
+ elsif is_new
49
+ Frivol::Config.redis.multi do |redis|
50
+ redis[key] = value
51
+ redis.expire(key, time)
52
+ end
53
+ else
54
+ Frivol::Config.redis[key] = value
49
55
  end
50
56
  end
51
57
 
@@ -5,12 +5,17 @@ require 'time'
5
5
  # serialized by <tt>MultiJson#dump</tt> and deserialized by
6
6
  # <tt>MultiJson#load</tt>.
7
7
  class Time
8
- # Serialize to JSON
9
- def to_json(*a)
10
- MultiJson.dump(
8
+ # Rails support
9
+ def as_json(*a)
10
+ {
11
11
  'json_class' => self.class.name,
12
12
  'data' => self.to_s
13
- )
13
+ }
14
+ end
15
+
16
+ # Serialize to JSON
17
+ def to_json(*a)
18
+ MultiJson.dump(as_json(*a))
14
19
  end
15
20
 
16
21
  # Deserialize from JSON
@@ -27,12 +32,17 @@ begin
27
32
  # instances to be serialized by <tt>MultiJson#dump</tt> and deserialized by
28
33
  # <tt>MultiJson#load</tt>.
29
34
  class ActiveSupport::TimeWithZone
30
- # Serialize to JSON
31
- def to_json(*a)
32
- MultiJson.dump(
35
+ # Rails support
36
+ def as_json(*a)
37
+ {
33
38
  'json_class' => self.class.name,
34
39
  'data' => self.to_s
35
- )
40
+ }
41
+ end
42
+
43
+ # Serialize to JSON
44
+ def to_json(*a)
45
+ MultiJson.dump(as_json(*a))
36
46
  end
37
47
 
38
48
  # Deserialize from JSON
@@ -4,6 +4,7 @@ class Redis
4
4
  def initialize(config)
5
5
  @storage = {}
6
6
  @expires = Hash.new(nil)
7
+ @version = config[:version] || "2.2.0"
7
8
  end
8
9
 
9
10
  def [](key)
@@ -18,6 +19,10 @@ class Redis
18
19
  @expires.delete key
19
20
  end
20
21
 
22
+ def info(key)
23
+ { 'redis_version' => @version }
24
+ end
25
+
21
26
  def del(key)
22
27
  # puts "del #{key}"
23
28
  @storage.delete key
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frivol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Heiligers