redijson_models 0.7.1 → 0.8.0

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
  SHA256:
3
- metadata.gz: 5bbbd589b7a392bd696145bcd903703f61d412db3f8534e7aeef3aa230eaf7a8
4
- data.tar.gz: ddabd3baf2b2d2c7175e5dd96c7abc0e26d6ca793e264ab6e4cb108f09127554
3
+ metadata.gz: 54c5606a725d17734a92db476abae3e38450c2ed5abe28bf49036b2a29b633e2
4
+ data.tar.gz: 53881342fc655b9ce36703d7480914aec2a4aeb353d6b539b4610801bfbb97a8
5
5
  SHA512:
6
- metadata.gz: 30e6892d7c04f70bbaf04544bf515864be82f5c9c0f00c27f0cfdc16caf80119902fc35c6ab3c306f8f775de58bf1e990ec36448af0bd3f29e78dd9053dd9d2e
7
- data.tar.gz: 925472da1e51f964dc5e725fccdb69cea6f15fcb290347aef5e6faf07b2998f7617303b274767099ed0037665fbb955940a89b855370928dab71c5ee1e344c9f
6
+ metadata.gz: ca8662a4d00d8ccbe55a37154b9070357f045f4bd4123541ce58f1d5e008af070b59effc63b10c00dfc6c4a2639392769557e6035c49fbdecfaa80b1ff31f08c
7
+ data.tar.gz: 2a9b3bf6ee2a276601bb8a66799e6fb48372f1c0f25bdb27e5e31340eeac29af7e90ed25746a24f37c4b3d94d6a9298524bca3f7276bf39bd7846fb575c59af3
data/lib/env.rb CHANGED
@@ -2,13 +2,14 @@
2
2
  # Bundler.require :default
3
3
  require 'redis'
4
4
  require 'virtus'
5
- require 'oj'
6
5
  require 'dry-inflector'
7
- # require 'redis_rejson'
8
6
  require 'rejson'
7
+ # require 'redis_rejson' # a little bit faster but has less features than the above
9
8
 
10
9
  module RediJsonModels
11
10
  REDIS_DB = ENV["REDIS_DB"]
12
11
 
13
12
  R = Redis.new db: REDIS_DB || 0
13
+
14
+ class NilValue; end
14
15
  end
@@ -13,10 +13,12 @@ module RediJsonModels
13
13
  end
14
14
 
15
15
  def self.[](key)
16
+ # redis.json_get key
16
17
  redis.json_get key, Rejson::Path.root_path
17
18
  end
18
19
 
19
20
  def self.[]=(key, val)
21
+ # redis.json_set key, val
20
22
  redis.json_set key, Rejson::Path.root_path, val
21
23
  end
22
24
  end
@@ -37,16 +39,21 @@ module RediJsonModels
37
39
  def get(id)
38
40
  data = RJ["#{resource}:#{id}"]
39
41
  return unless data
40
- data = Oj.load data
41
42
  new data
42
43
  end
43
44
 
45
+ def get_attr(id, attr)
46
+ key = "#{resource}:#{id}"
47
+ data = RJ.redis.json_get key, ".name"
48
+ return NilValue.new unless data
49
+ data
50
+ end
51
+
44
52
  def create(attrs)
45
53
  id = incr
46
54
  attrs.merge! id: id
47
55
  obj = new attrs
48
- data = Oj.dump obj.attributes
49
- RJ["#{resource}:#{id}"] = data
56
+ RJ["#{resource}:#{id}"] = obj.attributes
50
57
  obj
51
58
  end
52
59
 
@@ -81,8 +88,7 @@ module RediJsonModels
81
88
  attrs = model.attributes
82
89
  attrs.merge! attrs_new
83
90
  obj = klass.new attrs
84
- data = Oj.dump obj.attributes
85
- RJ["#{self.class.resource}:#{id}"] = data
91
+ RJ["#{self.class.resource}:#{id}"] = obj.attributes
86
92
  obj
87
93
  end
88
94
 
@@ -91,8 +97,7 @@ module RediJsonModels
91
97
  id = klass.send :incr
92
98
  attrs = attributes
93
99
  attrs.merge! id: id
94
- data = Oj.dump attrs
95
- RJ["#{self.class.resource}:#{id}"] = data
100
+ RJ["#{self.class.resource}:#{id}"] = attrs
96
101
  self
97
102
  end
98
103
 
@@ -1,3 +1,3 @@
1
1
  module RediJsonModels
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redijson_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - makevoid
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.0.5
41
- - !ruby/object:Gem::Dependency
42
- name: oj
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 3.10.6
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 3.10.6
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: dry-inflector
57
43
  requirement: !ruby/object:Gem::Requirement