redlics 0.1.6 → 0.1.7
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/README.md +1 -1
 - data/lib/redlics.rb +6 -5
 - data/lib/redlics/config.rb +1 -1
 - data/lib/redlics/counter.rb +10 -6
 - data/lib/redlics/key.rb +6 -4
 - data/lib/redlics/query.rb +3 -3
 - data/lib/redlics/query/operation.rb +3 -3
 - data/lib/redlics/tracker.rb +5 -3
 - data/lib/redlics/version.rb +1 -1
 - data/test/redlics_test.rb +1 -1
 - 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: 5c952b2aaef0c600c43759b347f42cf121f84359
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 1f1122c2deeb9bcca5f77dbd2f577e81acc15a1f
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 7f5f5f504154cf0e53cff914c6dbd4ea33c29ecaf0519a38630fa20a649c39270823ead3b5c6c6e693957f34bcbe7f22180433953aa11d0f1345841ab05e39de
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 7c66a67307b5873d43ada08c4cf8c3b43a4b1db9b75fb7322b8990425c742ea851864d9b472302651e4b20b40f1058fe648fefaf5b8c885c53cc0e606142f772
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -64,7 +64,7 @@ Redlics.configure do |config| 
     | 
|
| 
       64 
64 
     | 
    
         
             
                ids: true
         
     | 
| 
       65 
65 
     | 
    
         
             
              }
         
     | 
| 
       66 
66 
     | 
    
         
             
              config.granularities = {
         
     | 
| 
       67 
     | 
    
         
            -
                minutely: { step: 1.minute, pattern: '%Y%m%d%H% 
     | 
| 
      
 67 
     | 
    
         
            +
                minutely: { step: 1.minute, pattern: '%Y%m%d%H%M' },
         
     | 
| 
       68 
68 
     | 
    
         
             
                hourly:   { step: 1.hour,   pattern: '%Y%m%d%H' },
         
     | 
| 
       69 
69 
     | 
    
         
             
                daily:    { step: 1.day,    pattern: '%Y%m%d' },
         
     | 
| 
       70 
70 
     | 
    
         
             
                weekly:   { step: 1.week,   pattern: '%GW%V' },
         
     | 
    
        data/lib/redlics.rb
    CHANGED
    
    | 
         @@ -27,10 +27,11 @@ module Redlics 
     | 
|
| 
       27 
27 
     | 
    
         
             
              # Get or initialize the Redis connection.
         
     | 
| 
       28 
28 
     | 
    
         
             
              # @return [Object] redis connection
         
     | 
| 
       29 
29 
     | 
    
         
             
              def redis
         
     | 
| 
      
 30 
     | 
    
         
            +
                raise ArgumentError, 'requires a block' unless block_given?
         
     | 
| 
       30 
31 
     | 
    
         
             
                redis_pool.with do |conn|
         
     | 
| 
       31 
32 
     | 
    
         
             
                  retryable = true
         
     | 
| 
       32 
33 
     | 
    
         
             
                  begin
         
     | 
| 
       33 
     | 
    
         
            -
                    conn
         
     | 
| 
      
 34 
     | 
    
         
            +
                    yield conn
         
     | 
| 
       34 
35 
     | 
    
         
             
                  rescue Redis::BaseError => e
         
     | 
| 
       35 
36 
     | 
    
         
             
                    raise e unless config.silent
         
     | 
| 
       36 
37 
     | 
    
         
             
                  rescue Redis::CommandError => ex
         
     | 
| 
         @@ -48,19 +49,19 @@ module Redlics 
     | 
|
| 
       48 
49 
     | 
    
         
             
              # @return [String] Lua script result
         
     | 
| 
       49 
50 
     | 
    
         
             
              def script(file, *args)
         
     | 
| 
       50 
51 
     | 
    
         
             
                begin
         
     | 
| 
       51 
     | 
    
         
            -
                  cache = LUA_CACHE[redis.client.options[:url]]
         
     | 
| 
      
 52 
     | 
    
         
            +
                  cache = LUA_CACHE[redis { |r| r.client.options[:url] }]
         
     | 
| 
       52 
53 
     | 
    
         
             
                  if cache.key?(file)
         
     | 
| 
       53 
54 
     | 
    
         
             
                    sha = cache[file]
         
     | 
| 
       54 
55 
     | 
    
         
             
                  else
         
     | 
| 
       55 
56 
     | 
    
         
             
                    src = File.read(file)
         
     | 
| 
       56 
     | 
    
         
            -
                    sha = redis.script(:load, src)
         
     | 
| 
      
 57 
     | 
    
         
            +
                    sha = redis { |r| r.script(:load, src) }
         
     | 
| 
       57 
58 
     | 
    
         
             
                    cache[file] = sha
         
     | 
| 
       58 
59 
     | 
    
         
             
                  end
         
     | 
| 
       59 
     | 
    
         
            -
                  redis.evalsha(sha, *args)
         
     | 
| 
      
 60 
     | 
    
         
            +
                  redis { |r| r.evalsha(sha, *args) }
         
     | 
| 
       60 
61 
     | 
    
         
             
                rescue RuntimeError
         
     | 
| 
       61 
62 
     | 
    
         
             
                  case $!.message
         
     | 
| 
       62 
63 
     | 
    
         
             
                  when Exception::ErrorPatterns::NOSCRIPT
         
     | 
| 
       63 
     | 
    
         
            -
                    LUA_CACHE[redis.client.options[:url]].clear
         
     | 
| 
      
 64 
     | 
    
         
            +
                    LUA_CACHE[redis { |r| r.client.options[:url] }].clear
         
     | 
| 
       64 
65 
     | 
    
         
             
                    retry
         
     | 
| 
       65 
66 
     | 
    
         
             
                  else
         
     | 
| 
       66 
67 
     | 
    
         
             
                    raise $! unless config.silent
         
     | 
    
        data/lib/redlics/config.rb
    CHANGED
    
    | 
         @@ -33,7 +33,7 @@ module Redlics 
     | 
|
| 
       33 
33 
     | 
    
         
             
                      ids: true
         
     | 
| 
       34 
34 
     | 
    
         
             
                    },
         
     | 
| 
       35 
35 
     | 
    
         
             
                    granularities: {
         
     | 
| 
       36 
     | 
    
         
            -
                      minutely: { step: 1.minute, pattern: '%Y%m%d%H% 
     | 
| 
      
 36 
     | 
    
         
            +
                      minutely: { step: 1.minute, pattern: '%Y%m%d%H%M' },
         
     | 
| 
       37 
37 
     | 
    
         
             
                      hourly:   { step: 1.hour,   pattern: '%Y%m%d%H' },
         
     | 
| 
       38 
38 
     | 
    
         
             
                      daily:    { step: 1.day,    pattern: '%Y%m%d' },
         
     | 
| 
       39 
39 
     | 
    
         
             
                      weekly:   { step: 1.week,   pattern: '%GW%V' },
         
     | 
    
        data/lib/redlics/counter.rb
    CHANGED
    
    | 
         @@ -67,9 +67,11 @@ module Redlics 
     | 
|
| 
       67 
67 
     | 
    
         
             
                  def count_by_hash(options)
         
     | 
| 
       68 
68 
     | 
    
         
             
                    granularity = options[:granularity]
         
     | 
| 
       69 
69 
     | 
    
         
             
                    key = Key.name(CONTEXT, options[:event], granularity, options[:past], { id: options[:id], bucketized: true })
         
     | 
| 
       70 
     | 
    
         
            -
                    Redlics.redis 
     | 
| 
       71 
     | 
    
         
            -
                       
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
      
 70 
     | 
    
         
            +
                    Redlics.redis do |conn|
         
     | 
| 
      
 71 
     | 
    
         
            +
                      conn.pipelined do |redis|
         
     | 
| 
      
 72 
     | 
    
         
            +
                        redis.hincrby(key[0], key[1], 1)
         
     | 
| 
      
 73 
     | 
    
         
            +
                        redis.expire(key[0], (options[:expiration_for] && options[:expiration_for][granularity] || Redlics.config.counter_expirations[granularity]).to_i)
         
     | 
| 
      
 74 
     | 
    
         
            +
                      end
         
     | 
| 
       73 
75 
     | 
    
         
             
                    end
         
     | 
| 
       74 
76 
     | 
    
         
             
                  end
         
     | 
| 
       75 
77 
     | 
    
         | 
| 
         @@ -81,9 +83,11 @@ module Redlics 
     | 
|
| 
       81 
83 
     | 
    
         
             
                  def count_by_key(options)
         
     | 
| 
       82 
84 
     | 
    
         
             
                    granularity = options[:granularity]
         
     | 
| 
       83 
85 
     | 
    
         
             
                    key = Key.name(CONTEXT, options[:event], granularity, options[:past], { id: options[:id], bucketized: false })
         
     | 
| 
       84 
     | 
    
         
            -
                    Redlics.redis 
     | 
| 
       85 
     | 
    
         
            -
                      redis 
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
      
 86 
     | 
    
         
            +
                    Redlics.redis do |conn|
         
     | 
| 
      
 87 
     | 
    
         
            +
                      conn.pipelined do |redis|
         
     | 
| 
      
 88 
     | 
    
         
            +
                        redis.incr(key)
         
     | 
| 
      
 89 
     | 
    
         
            +
                        redis.expire(key, (options[:expiration_for] && options[:expiration_for][granularity] || Redlics.config.counter_expirations[granularity]).to_i)
         
     | 
| 
      
 90 
     | 
    
         
            +
                      end
         
     | 
| 
       87 
91 
     | 
    
         
             
                    end
         
     | 
| 
       88 
92 
     | 
    
         
             
                  end
         
     | 
| 
       89 
93 
     | 
    
         | 
    
        data/lib/redlics/key.rb
    CHANGED
    
    | 
         @@ -97,7 +97,7 @@ module Redlics 
     | 
|
| 
       97 
97 
     | 
    
         
             
                # @param string [String] the key name to check
         
     | 
| 
       98 
98 
     | 
    
         
             
                # @return [Boolean] true id key exists, false if not
         
     | 
| 
       99 
99 
     | 
    
         
             
                def exists?(key)
         
     | 
| 
       100 
     | 
    
         
            -
                  Redlics.redis.exists(key)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  Redlics.redis { |r| r.exists(key) }
         
     | 
| 
       101 
101 
     | 
    
         
             
                end
         
     | 
| 
       102 
102 
     | 
    
         | 
| 
       103 
103 
     | 
    
         | 
| 
         @@ -117,9 +117,11 @@ module Redlics 
     | 
|
| 
       117 
117 
     | 
    
         
             
                  loop do
         
     | 
| 
       118 
118 
     | 
    
         
             
                    ns = operation
         
     | 
| 
       119 
119 
     | 
    
         
             
                    unless exists?(ns)
         
     | 
| 
       120 
     | 
    
         
            -
                      Redlics.redis 
     | 
| 
       121 
     | 
    
         
            -
                         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
      
 120 
     | 
    
         
            +
                      Redlics.redis do |conn|
         
     | 
| 
      
 121 
     | 
    
         
            +
                        conn.pipelined do |redis|
         
     | 
| 
      
 122 
     | 
    
         
            +
                          redis.set(ns, 0)
         
     | 
| 
      
 123 
     | 
    
         
            +
                          redis.expire(ns, Redlics.config.operation_expiration)
         
     | 
| 
      
 124 
     | 
    
         
            +
                        end
         
     | 
| 
       123 
125 
     | 
    
         
             
                      end
         
     | 
| 
       124 
126 
     | 
    
         
             
                      break ns
         
     | 
| 
       125 
127 
     | 
    
         
             
                    end
         
     | 
    
        data/lib/redlics/query.rb
    CHANGED
    
    | 
         @@ -44,7 +44,7 @@ module Redlics 
     | 
|
| 
       44 
44 
     | 
    
         
             
                # Get or process tracks on Redis.
         
     | 
| 
       45 
45 
     | 
    
         
             
                # @return [Integer] tracks result of given query
         
     | 
| 
       46 
46 
     | 
    
         
             
                def tracks
         
     | 
| 
       47 
     | 
    
         
            -
                  @tracks ||= Redlics.redis.bitcount(track_bits)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @tracks ||= Redlics.redis { |r| r.bitcount(track_bits) }
         
     | 
| 
       48 
48 
     | 
    
         
             
                end
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         | 
| 
         @@ -65,7 +65,7 @@ module Redlics 
     | 
|
| 
       65 
65 
     | 
    
         
             
                # @return [Boolean] true if exists, false if not
         
     | 
| 
       66 
66 
     | 
    
         
             
                # @return [NilClass] nil if no object id is given
         
     | 
| 
       67 
67 
     | 
    
         
             
                def exists?
         
     | 
| 
       68 
     | 
    
         
            -
                  @exists ||= @options[:id] ? Redlics.redis.getbit(track_bits, @options[:id]) == 1 : nil
         
     | 
| 
      
 68 
     | 
    
         
            +
                  @exists ||= @options[:id] ? Redlics.redis { |r| r.getbit(track_bits, @options[:id]) } == 1 : nil
         
     | 
| 
       69 
69 
     | 
    
         
             
                end
         
     | 
| 
       70 
70 
     | 
    
         | 
| 
       71 
71 
     | 
    
         | 
| 
         @@ -197,7 +197,7 @@ module Redlics 
     | 
|
| 
       197 
197 
     | 
    
         
             
                  # @return [Integer] result of Redis delete keys
         
     | 
| 
       198 
198 
     | 
    
         
             
                  # @return [NilClass] nil if namespaces are empty
         
     | 
| 
       199 
199 
     | 
    
         
             
                  def reset_redis_namespaces(namespaces)
         
     | 
| 
       200 
     | 
    
         
            -
                    Redlics.redis.del(namespaces) if namespaces.any?
         
     | 
| 
      
 200 
     | 
    
         
            +
                    Redlics.redis { |r| r.del(namespaces) } if namespaces.any?
         
     | 
| 
       201 
201 
     | 
    
         
             
                  end
         
     | 
| 
       202 
202 
     | 
    
         | 
| 
       203 
203 
     | 
    
         
             
                end
         
     | 
| 
         @@ -30,7 +30,7 @@ module Redlics 
     | 
|
| 
       30 
30 
     | 
    
         
             
                  # @return [Integer] tracks result of given query operation
         
     | 
| 
       31 
31 
     | 
    
         
             
                  def tracks
         
     | 
| 
       32 
32 
     | 
    
         
             
                    @tracks ||= (
         
     | 
| 
       33 
     | 
    
         
            -
                      Redlics.redis.bitcount(@track_bits || traverse)
         
     | 
| 
      
 33 
     | 
    
         
            +
                      Redlics.redis { |r| r.bitcount(@track_bits || traverse) }
         
     | 
| 
       34 
34 
     | 
    
         
             
                    )
         
     | 
| 
       35 
35 
     | 
    
         
             
                  end
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
         @@ -59,7 +59,7 @@ module Redlics 
     | 
|
| 
       59 
59 
     | 
    
         
             
                  # @param [Integer] the object id to check
         
     | 
| 
       60 
60 
     | 
    
         
             
                  # @return [Boolean] true if exists, false if not
         
     | 
| 
       61 
61 
     | 
    
         
             
                  def exists?(id)
         
     | 
| 
       62 
     | 
    
         
            -
                    Redlics.redis.getbit(@track_bits || traverse, id.to_i) == 1
         
     | 
| 
      
 62 
     | 
    
         
            +
                    Redlics.redis { |r| r.getbit(@track_bits || traverse, id.to_i) } == 1
         
     | 
| 
       63 
63 
     | 
    
         
             
                  end
         
     | 
| 
       64 
64 
     | 
    
         | 
| 
       65 
65 
     | 
    
         | 
| 
         @@ -109,7 +109,7 @@ module Redlics 
     | 
|
| 
       109 
109 
     | 
    
         
             
                    # @return [Integer] result of Redis delete keys
         
     | 
| 
       110 
110 
     | 
    
         
             
                    # @return [NilClass] nil if namespaces are empty
         
     | 
| 
       111 
111 
     | 
    
         
             
                    def reset_redis_namespaces(namespaces)
         
     | 
| 
       112 
     | 
    
         
            -
                      Redlics.redis.del(namespaces) if namespaces.any?
         
     | 
| 
      
 112 
     | 
    
         
            +
                      Redlics.redis { |r| r.del(namespaces) } if namespaces.any?
         
     | 
| 
       113 
113 
     | 
    
         
             
                    end
         
     | 
| 
       114 
114 
     | 
    
         | 
| 
       115 
115 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/redlics/tracker.rb
    CHANGED
    
    | 
         @@ -29,9 +29,11 @@ module Redlics 
     | 
|
| 
       29 
29 
     | 
    
         
             
                  def track_with_hash(options)
         
     | 
| 
       30 
30 
     | 
    
         
             
                    Granularity.validate(CONTEXT, options[:granularity]).each do |granularity|
         
     | 
| 
       31 
31 
     | 
    
         
             
                      key = Key.name(CONTEXT, options[:event], granularity, options[:past])
         
     | 
| 
       32 
     | 
    
         
            -
                      Redlics.redis 
     | 
| 
       33 
     | 
    
         
            -
                         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
                      Redlics.redis do |conn|
         
     | 
| 
      
 33 
     | 
    
         
            +
                        conn.pipelined do |redis|
         
     | 
| 
      
 34 
     | 
    
         
            +
                          redis.setbit(key, options[:id].to_i, 1)
         
     | 
| 
      
 35 
     | 
    
         
            +
                          redis.expire(key, (options[:expiration_for] && options[:expiration_for][granularity] || Redlics.config.tracker_expirations[granularity]).to_i)
         
     | 
| 
      
 36 
     | 
    
         
            +
                        end
         
     | 
| 
       35 
37 
     | 
    
         
             
                      end
         
     | 
| 
       36 
38 
     | 
    
         
             
                    end
         
     | 
| 
       37 
39 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/redlics/version.rb
    CHANGED
    
    
    
        data/test/redlics_test.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: redlics
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.7
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Egon Zemmer
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2016- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-06-18 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: connection_pool
         
     |