kredis 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kredis might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/kredis.rb +6 -0
- data/lib/kredis/attributes.rb +50 -7
- data/lib/kredis/logger.rb +5 -0
- data/lib/kredis/railtie.rb +4 -0
- data/lib/kredis/types.rb +13 -3
- data/lib/kredis/types/counter.rb +1 -1
- data/lib/kredis/types/flag.rb +1 -1
- data/lib/kredis/types/integer.rb +9 -0
- data/lib/kredis/types/list.rb +1 -1
- data/lib/kredis/types/mutex.rb +1 -1
- data/lib/kredis/{proxy.rb → types/proxy.rb} +2 -1
- data/lib/kredis/types/string.rb +21 -0
- data/lib/kredis/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57c373219f474818bb85a7da4ef3a07bd4910cd685704b54549969c364ee5993
|
4
|
+
data.tar.gz: f220ce448caa279514e249bc7c2f744c7276946d5f5af5a9899a9f6e14d3b5be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef637b80601d21e815317201ab426da35a56926a2d069303cf1244e5a51f4ab0f80f7ef6e47a566d306248bbc2006c8a0dcdfd6990e0abf3057b5474ba7b6fc0
|
7
|
+
data.tar.gz: 99e4587242b125cfc78deff59e410055f9fefbfce726942ce1192e6065a6e08c1cfd0d83d409221c54418803b4405643ce8f873de8fbb0ef0c781ba882625c0e
|
data/lib/kredis.rb
CHANGED
@@ -4,11 +4,17 @@ require "kredis/connections"
|
|
4
4
|
require "kredis/types"
|
5
5
|
require "kredis/attributes"
|
6
6
|
require "kredis/namespace"
|
7
|
+
require "kredis/logger"
|
7
8
|
|
8
9
|
module Kredis
|
9
10
|
include Connections
|
10
11
|
include Namespace
|
11
12
|
include Types
|
13
|
+
include Logger
|
12
14
|
|
13
15
|
extend self
|
16
|
+
|
17
|
+
def redis(config: :shared)
|
18
|
+
configured_for(config)
|
19
|
+
end
|
14
20
|
end
|
data/lib/kredis/attributes.rb
CHANGED
@@ -2,38 +2,50 @@ module Kredis::Attributes
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
class_methods do
|
5
|
-
def
|
5
|
+
def kredis_proxy(name, key: nil, config: :shared)
|
6
|
+
ivar_symbol = :"@#{name}_kredis_proxy"
|
7
|
+
|
8
|
+
define_method(name) do
|
9
|
+
if instance_variable_defined?(ivar_symbol)
|
10
|
+
instance_variable_get(ivar_symbol)
|
11
|
+
else
|
12
|
+
instance_variable_set(ivar_symbol, Kredis.proxy(kredis_key_evaluated(key) || kredis_key_for_attribute(name), config: config))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def kredis_list(name, key: nil, config: :shared)
|
6
18
|
ivar_symbol = :"@#{name}_kredis_list"
|
7
19
|
|
8
20
|
define_method(name) do
|
9
21
|
if instance_variable_defined?(ivar_symbol)
|
10
22
|
instance_variable_get(ivar_symbol)
|
11
23
|
else
|
12
|
-
instance_variable_set(ivar_symbol, Kredis.list(kredis_key_for_attribute(name), config: config))
|
24
|
+
instance_variable_set(ivar_symbol, Kredis.list(kredis_key_evaluated(key) || kredis_key_for_attribute(name), config: config))
|
13
25
|
end
|
14
26
|
end
|
15
27
|
end
|
16
28
|
|
17
|
-
def kredis_unique_list(name, limit: nil, config: :shared)
|
29
|
+
def kredis_unique_list(name, limit: nil, key: nil, config: :shared)
|
18
30
|
ivar_symbol = :"@#{name}_kredis_unique_list"
|
19
31
|
|
20
32
|
define_method(name) do
|
21
33
|
if instance_variable_defined?(ivar_symbol)
|
22
34
|
instance_variable_get(ivar_symbol)
|
23
35
|
else
|
24
|
-
instance_variable_set(ivar_symbol, Kredis.unique_list(kredis_key_for_attribute(name), limit: limit, config: config))
|
36
|
+
instance_variable_set(ivar_symbol, Kredis.unique_list(kredis_key_evaluated(key) || kredis_key_for_attribute(name), limit: limit, config: config))
|
25
37
|
end
|
26
38
|
end
|
27
39
|
end
|
28
40
|
|
29
|
-
def kredis_flag(name, config: :shared)
|
41
|
+
def kredis_flag(name, key: nil, config: :shared)
|
30
42
|
ivar_symbol = :"@#{name}_kredis_flag"
|
31
43
|
|
32
44
|
define_method(name) do
|
33
45
|
if instance_variable_defined?(ivar_symbol)
|
34
46
|
instance_variable_get(ivar_symbol)
|
35
47
|
else
|
36
|
-
instance_variable_set(ivar_symbol, Kredis.flag(kredis_key_for_attribute(name), config: config))
|
48
|
+
instance_variable_set(ivar_symbol, Kredis.flag(kredis_key_evaluated(key) || kredis_key_for_attribute(name), config: config))
|
37
49
|
end
|
38
50
|
end
|
39
51
|
|
@@ -41,10 +53,41 @@ module Kredis::Attributes
|
|
41
53
|
instance_variable_defined?(ivar_symbol) && instance_variable_get(ivar_symbol).marked?
|
42
54
|
end
|
43
55
|
end
|
56
|
+
|
57
|
+
def kredis_string(name, key: nil, config: :shared)
|
58
|
+
ivar_symbol = :"@#{name}_kredis_string"
|
59
|
+
|
60
|
+
define_method(name) do
|
61
|
+
if instance_variable_defined?(ivar_symbol)
|
62
|
+
instance_variable_get(ivar_symbol)
|
63
|
+
else
|
64
|
+
instance_variable_set(ivar_symbol, Kredis.string(kredis_key_evaluated(key) || kredis_key_for_attribute(name), config: config))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def kredis_integer(name, key: nil, config: :shared)
|
70
|
+
ivar_symbol = :"@#{name}_kredis_integer"
|
71
|
+
|
72
|
+
define_method(name) do
|
73
|
+
if instance_variable_defined?(ivar_symbol)
|
74
|
+
instance_variable_get(ivar_symbol)
|
75
|
+
else
|
76
|
+
instance_variable_set(ivar_symbol, Kredis.integer(kredis_key_evaluated(key) || kredis_key_for_attribute(name), config: config))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
44
80
|
end
|
45
81
|
|
46
82
|
private
|
47
|
-
def
|
83
|
+
def kredis_key_evaluated(key)
|
84
|
+
case key
|
85
|
+
when String then key
|
86
|
+
when Proc then key.call(self)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def kredis_key_for_attribute(name, key: nil)
|
48
91
|
"#{self.class.name.tableize.gsub("/", ":")}:#{id}:#{name}"
|
49
92
|
end
|
50
93
|
end
|
data/lib/kredis/railtie.rb
CHANGED
data/lib/kredis/types.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Kredis::Types
|
2
|
-
def
|
3
|
-
Kredis::Proxy.new configured_for(config), namespaced_key(key)
|
2
|
+
def proxy(key, config: :shared)
|
3
|
+
Kredis::Types::Proxy.new configured_for(config), namespaced_key(key)
|
4
4
|
end
|
5
5
|
|
6
6
|
def list(key, config: :shared)
|
@@ -19,14 +19,24 @@ module Kredis::Types
|
|
19
19
|
Flag.new configured_for(config), namespaced_key(key)
|
20
20
|
end
|
21
21
|
|
22
|
+
def string(key, config: :shared)
|
23
|
+
Kredis::Types::String.new configured_for(config), namespaced_key(key)
|
24
|
+
end
|
25
|
+
|
26
|
+
def integer(key, config: :shared)
|
27
|
+
Kredis::Types::Integer.new configured_for(config), namespaced_key(key)
|
28
|
+
end
|
29
|
+
|
22
30
|
def mutex(key, expires_in: nil, config: :shared)
|
23
31
|
Mutex.new configured_for(config), namespaced_key(key), expires_in: expires_in
|
24
32
|
end
|
25
33
|
end
|
26
34
|
|
27
|
-
require "kredis/proxy"
|
35
|
+
require "kredis/types/proxy"
|
28
36
|
require "kredis/types/list"
|
29
37
|
require "kredis/types/unique_list"
|
30
38
|
require "kredis/types/counter"
|
31
39
|
require "kredis/types/flag"
|
40
|
+
require "kredis/types/string"
|
41
|
+
require "kredis/types/integer"
|
32
42
|
require "kredis/types/mutex"
|
data/lib/kredis/types/counter.rb
CHANGED
data/lib/kredis/types/flag.rb
CHANGED
data/lib/kredis/types/list.rb
CHANGED
data/lib/kredis/types/mutex.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class Kredis::Proxy
|
1
|
+
class Kredis::Types::Proxy
|
2
2
|
def initialize(redis, key)
|
3
3
|
@redis, @key = redis, key
|
4
4
|
end
|
@@ -8,6 +8,7 @@ class Kredis::Proxy
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def method_missing(method, *args, **kwargs)
|
11
|
+
Kredis.logger&.debug "[Kredis] #{method} #{@key} #{args.inspect if args.compact_blank.any?} #{kwargs.inspect if kwargs.compact_blank.any?}".chomp
|
11
12
|
@redis.public_send method, @key, *args, **kwargs
|
12
13
|
end
|
13
14
|
end
|
data/lib/kredis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kredis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Timm Hansen
|
@@ -50,14 +50,17 @@ files:
|
|
50
50
|
- lib/kredis.rb
|
51
51
|
- lib/kredis/attributes.rb
|
52
52
|
- lib/kredis/connections.rb
|
53
|
+
- lib/kredis/logger.rb
|
53
54
|
- lib/kredis/namespace.rb
|
54
|
-
- lib/kredis/proxy.rb
|
55
55
|
- lib/kredis/railtie.rb
|
56
56
|
- lib/kredis/types.rb
|
57
57
|
- lib/kredis/types/counter.rb
|
58
58
|
- lib/kredis/types/flag.rb
|
59
|
+
- lib/kredis/types/integer.rb
|
59
60
|
- lib/kredis/types/list.rb
|
60
61
|
- lib/kredis/types/mutex.rb
|
62
|
+
- lib/kredis/types/proxy.rb
|
63
|
+
- lib/kredis/types/string.rb
|
61
64
|
- lib/kredis/types/unique_list.rb
|
62
65
|
- lib/kredis/version.rb
|
63
66
|
homepage: https://github.com/rails/kredis
|