moneta 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +176 -0
  3. data/.travis.yml +57 -23
  4. data/CHANGES +12 -0
  5. data/Gemfile +89 -64
  6. data/README.md +40 -14
  7. data/feature_matrix.yaml +1 -0
  8. data/lib/action_dispatch/middleware/session/moneta_store.rb +1 -0
  9. data/lib/active_support/cache/moneta_store.rb +5 -5
  10. data/lib/moneta.rb +9 -1
  11. data/lib/moneta/adapters/activerecord.rb +35 -19
  12. data/lib/moneta/adapters/activesupportcache.rb +3 -7
  13. data/lib/moneta/adapters/cassandra.rb +24 -16
  14. data/lib/moneta/adapters/client.rb +13 -9
  15. data/lib/moneta/adapters/couch.rb +220 -80
  16. data/lib/moneta/adapters/datamapper.rb +1 -0
  17. data/lib/moneta/adapters/file.rb +9 -6
  18. data/lib/moneta/adapters/hbase.rb +1 -1
  19. data/lib/moneta/adapters/kyotocabinet.rb +8 -7
  20. data/lib/moneta/adapters/leveldb.rb +1 -1
  21. data/lib/moneta/adapters/lmdb.rb +3 -4
  22. data/lib/moneta/adapters/lruhash.rb +29 -62
  23. data/lib/moneta/adapters/memcached.rb +1 -0
  24. data/lib/moneta/adapters/memcached/dalli.rb +1 -1
  25. data/lib/moneta/adapters/memcached/native.rb +10 -8
  26. data/lib/moneta/adapters/mongo.rb +1 -0
  27. data/lib/moneta/adapters/mongo/base.rb +3 -3
  28. data/lib/moneta/adapters/mongo/moped.rb +12 -13
  29. data/lib/moneta/adapters/mongo/official.rb +7 -8
  30. data/lib/moneta/adapters/null.rb +1 -2
  31. data/lib/moneta/adapters/pstore.rb +3 -2
  32. data/lib/moneta/adapters/redis.rb +3 -3
  33. data/lib/moneta/adapters/restclient.rb +12 -3
  34. data/lib/moneta/adapters/riak.rb +2 -2
  35. data/lib/moneta/adapters/sequel.rb +112 -119
  36. data/lib/moneta/adapters/sqlite.rb +3 -3
  37. data/lib/moneta/adapters/tokyotyrant.rb +1 -1
  38. data/lib/moneta/builder.rb +0 -1
  39. data/lib/moneta/enumerable.rb +38 -0
  40. data/lib/moneta/expires.rb +12 -12
  41. data/lib/moneta/fallback.rb +84 -0
  42. data/lib/moneta/lock.rb +1 -1
  43. data/lib/moneta/logger.rb +2 -2
  44. data/lib/moneta/mixins.rb +12 -10
  45. data/lib/moneta/optionmerger.rb +0 -1
  46. data/lib/moneta/pool.rb +301 -31
  47. data/lib/moneta/proxy.rb +2 -2
  48. data/lib/moneta/server.rb +9 -12
  49. data/lib/moneta/shared.rb +1 -1
  50. data/lib/moneta/stack.rb +6 -6
  51. data/lib/moneta/synchronize.rb +3 -3
  52. data/lib/moneta/transformer.rb +19 -17
  53. data/lib/moneta/transformer/config.rb +6 -5
  54. data/lib/moneta/transformer/helper.rb +3 -3
  55. data/lib/moneta/transformer/helper/bson.rb +18 -15
  56. data/lib/moneta/utils.rb +3 -9
  57. data/lib/moneta/version.rb +1 -1
  58. data/lib/moneta/weak_each_key.rb +2 -4
  59. data/lib/rack/cache/moneta.rb +16 -13
  60. data/lib/rack/moneta_rest.rb +2 -2
  61. data/lib/rack/session/moneta.rb +3 -4
  62. data/moneta.gemspec +8 -0
  63. data/script/benchmarks +55 -32
  64. data/script/reconfigure-couchdb +13 -0
  65. data/script/start-hbase +1 -0
  66. data/script/start-services +2 -10
  67. data/spec/active_support/cache_moneta_store_spec.rb +3 -1
  68. data/spec/features/concurrent_create.rb +31 -10
  69. data/spec/features/concurrent_increment.rb +27 -19
  70. data/spec/features/increment.rb +41 -41
  71. data/spec/helper.rb +2 -42
  72. data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_spec.rb +4 -1
  73. data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_with_default_expires_spec.rb +4 -1
  74. data/spec/moneta/adapters/activesupportcache/standard_activesupportcache_spec.rb +14 -0
  75. data/spec/moneta/adapters/couch/adapter_couch_spec.rb +199 -2
  76. data/spec/moneta/adapters/couch/standard_couch_spec.rb +8 -2
  77. data/spec/moneta/adapters/couch/standard_couch_with_expires_spec.rb +7 -1
  78. data/spec/moneta/adapters/faraday_helper.rb +9 -0
  79. data/spec/moneta/adapters/lruhash/adapter_lruhash_spec.rb +2 -2
  80. data/spec/moneta/adapters/memcached/adapter_memcached_spec.rb +1 -1
  81. data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_spec.rb +1 -1
  82. data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_with_default_expires_spec.rb +1 -1
  83. data/spec/moneta/adapters/memcached/dalli/standard_memcached_dalli_spec.rb +1 -1
  84. data/spec/moneta/adapters/memcached/native/adapter_memcached_native_spec.rb +1 -1
  85. data/spec/moneta/adapters/memcached/native/adapter_memcached_native_with_default_expires_spec.rb +1 -1
  86. data/spec/moneta/adapters/memcached/native/standard_memcached_native_spec.rb +1 -1
  87. data/spec/moneta/adapters/memcached/standard_memcached_spec.rb +1 -1
  88. data/spec/moneta/adapters/{memcached/helper.rb → memcached_helper.rb} +0 -0
  89. data/spec/moneta/adapters/null/null_adapter_spec.rb +1 -1
  90. data/spec/moneta/adapters/restclient/adapter_restclient_spec.rb +7 -5
  91. data/spec/moneta/adapters/restclient/helper.rb +12 -0
  92. data/spec/moneta/adapters/restclient/standard_restclient_spec.rb +9 -6
  93. data/spec/moneta/adapters/riak/standard_riak_with_expires_spec.rb +4 -0
  94. data/spec/moneta/adapters/tokyotyrant/adapter_tokyotyrant_spec.rb +6 -2
  95. data/spec/moneta/adapters/tokyotyrant/helper.rb +12 -0
  96. data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_spec.rb +5 -2
  97. data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_with_expires_spec.rb +5 -1
  98. data/spec/moneta/proxies/enumerable/enumerable_spec.rb +26 -0
  99. data/spec/moneta/proxies/fallback/fallback_spec.rb +42 -0
  100. data/spec/moneta/proxies/pool/pool_spec.rb +319 -6
  101. data/spec/restserver.rb +40 -0
  102. metadata +122 -7
  103. data/script/install-kyotocabinet +0 -17
@@ -11,6 +11,7 @@ module Moneta
11
11
 
12
12
  supports :create
13
13
 
14
+ # @api private
14
15
  class Store
15
16
  include ::DataMapper::Resource
16
17
  property :k, String, key: true, length: 255
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'English'
2
3
 
3
4
  module Moneta
4
5
  module Adapters
@@ -35,17 +36,18 @@ module Moneta
35
36
  def load(key, options = {})
36
37
  ::File.read(store_path(key), mode: 'rb')
37
38
  rescue Errno::ENOENT
39
+ nil
38
40
  end
39
41
 
40
42
  # (see Proxy#store)
41
43
  def store(key, value, options = {})
42
- temp_file = ::File.join(@dir, "value-#{$$}-#{Thread.current.object_id}")
44
+ temp_file = ::File.join(@dir, "value-#{$PROCESS_ID}-#{Thread.current.object_id}")
43
45
  path = store_path(key)
44
46
  FileUtils.mkpath(::File.dirname(path))
45
- ::File.open(temp_file, 'wb') {|f| f.write(value) }
47
+ ::File.open(temp_file, 'wb') { |f| f.write(value) }
46
48
  ::File.rename(temp_file, path)
47
49
  value
48
- rescue Exception
50
+ rescue
49
51
  File.unlink(temp_file) rescue nil
50
52
  raise
51
53
  end
@@ -56,11 +58,12 @@ module Moneta
56
58
  ::File.unlink(store_path(key))
57
59
  value
58
60
  rescue Errno::ENOENT
61
+ nil
59
62
  end
60
63
 
61
64
  # (see Proxy#clear)
62
65
  def clear(options = {})
63
- temp_dir = "#{@dir}-#{$$}-#{Thread.current.object_id}"
66
+ temp_dir = "#{@dir}-#{$PROCESS_ID}-#{Thread.current.object_id}"
64
67
  ::File.rename(@dir, temp_dir)
65
68
  FileUtils.mkpath(@dir)
66
69
  self
@@ -77,7 +80,7 @@ module Moneta
77
80
  ::File.open(path, ::File::RDWR | ::File::CREAT) do |f|
78
81
  Thread.pass until f.flock(::File::LOCK_EX)
79
82
  content = f.read
80
- amount += Utils.to_int(content) unless content.empty?
83
+ amount += Integer(content) unless content.empty?
81
84
  content = amount.to_s
82
85
  f.binmode
83
86
  f.pos = 0
@@ -96,7 +99,7 @@ module Moneta
96
99
  FileUtils.mkpath(::File.dirname(path))
97
100
  # Call native java.io.File#createNewFile
98
101
  return false unless ::Java::JavaIo::File.new(path).createNewFile
99
- ::File.open(path, 'wb+') {|f| f.write(value) }
102
+ ::File.open(path, 'wb+') { |f| f.write(value) }
100
103
  true
101
104
  end
102
105
  else
@@ -53,7 +53,7 @@ module Moneta
53
53
  def increment(key, amount = 1, options = {})
54
54
  result = @table.atomic_increment(key, @column, amount)
55
55
  # HACK: Throw error if applied to invalid value
56
- Utils.to_int(load(key)) if result == 0
56
+ Integer(load(key)) if result == 0
57
57
  result
58
58
  end
59
59
 
@@ -48,19 +48,20 @@ module Moneta
48
48
  # (see Proxy#each_key)
49
49
  def each_key
50
50
  return enum_for(:each_key) { @backend.count } unless block_given?
51
- @backend.each_key{ |arr| yield arr[0] }
51
+ @backend.each_key { |arr| yield arr[0] }
52
52
  self
53
53
  end
54
54
 
55
55
  # (see Proxy#increment)
56
56
  def increment(key, amount = 1, options = {})
57
57
  ret = nil
58
- success = @backend.accept(key) do |key, value|
59
- if value
60
- ret = Integer(value) + amount
61
- else
62
- ret = amount
63
- end
58
+ success = @backend.accept(key) do |_, value|
59
+ ret =
60
+ if value
61
+ Integer(value) + amount
62
+ else
63
+ amount
64
+ end
64
65
  ret.to_s
65
66
  end
66
67
 
@@ -30,7 +30,7 @@ module Moneta
30
30
 
31
31
  # (see Proxy#clear)
32
32
  def clear(options = {})
33
- @backend.each {|k,v| delete(k, options) }
33
+ @backend.each { |k,| delete(k, options) }
34
34
  self
35
35
  end
36
36
 
@@ -11,7 +11,7 @@ module Moneta
11
11
  supports :create, :increment, :each_key
12
12
  attr_reader :backend, :db
13
13
 
14
- PUT_FLAGS = [:nooverwrite, :nodupdata, :current, :append, :appenddup]
14
+ PUT_FLAGS = %i[nooverwrite nodupdata current append appenddup].freeze
15
15
 
16
16
  # @param [Hash] options
17
17
  # @option options [String] :dir Environment directory
@@ -31,7 +31,7 @@ module Moneta
31
31
 
32
32
  # (see Proxy#key?)
33
33
  def key?(key, options = {})
34
- !@db.get(key).nil?
34
+ @db.get(key) != nil
35
35
  end
36
36
 
37
37
  # (see Proxy#load)
@@ -64,8 +64,7 @@ module Moneta
64
64
  # (see Proxy#increment)
65
65
  def increment(key, amount = 1, options = {})
66
66
  @backend.transaction do
67
- value = @db.get(key)
68
- value = Utils.to_int(value) + amount
67
+ value = Integer(@db.get(key) || 0) + amount
69
68
  @db.put(key, value.to_s, Utils.only(options, *PUT_FLAGS))
70
69
  value
71
70
  end
@@ -2,7 +2,8 @@ module Moneta
2
2
  module Adapters
3
3
  # LRUHash backend
4
4
  #
5
- # Based on Hashery::LRUHash but simpler and measures both memory usage and hash size.
5
+ # Based on {https://rubygems.org/gems/lru_redux lru_redux} but measures
6
+ # both memory usage and hash size.
6
7
  #
7
8
  # @api public
8
9
  class LRUHash
@@ -28,22 +29,24 @@ module Moneta
28
29
 
29
30
  # (see Proxy#key?)
30
31
  def key?(key, options = {})
31
- @entry.key?(key)
32
+ @backend.key?(key)
32
33
  end
33
34
 
34
35
  # (see Proxy#each_key)
35
36
  def each_key(&block)
36
- return enum_for(:each_key) { @entry.length } unless block_given?
37
+ return enum_for(:each_key) { @backend.length } unless block_given?
37
38
 
38
- @entry.each_key { |k| yield(k) }
39
+ # The backend needs to be duplicated because reading mutates this
40
+ # store.
41
+ @backend.dup.each_key { |k| yield(k) }
39
42
  self
40
43
  end
41
44
 
42
45
  # (see Proxy#load)
43
46
  def load(key, options = {})
44
- if entry = @entry[key]
45
- entry.insert_after(@list)
46
- entry.value
47
+ if value = @backend.delete(key)
48
+ @backend[key] = value
49
+ value
47
50
  end
48
51
  end
49
52
 
@@ -52,76 +55,40 @@ module Moneta
52
55
  if @max_value && value.bytesize > @max_value
53
56
  delete(key)
54
57
  else
55
- if entry = @entry[key]
56
- @size -= entry.value.bytesize if @max_size
57
- else
58
- @entry[key] = entry = Entry.new
59
- entry.key = key
58
+ if @max_size
59
+ if old_value = @backend.delete(key)
60
+ @size -= old_value.bytesize
61
+ end
62
+ @size += value.bytesize
60
63
  end
61
- entry.value = value
62
- @size += entry.value.bytesize if @max_size
63
- entry.insert_after(@list)
64
- delete(@list.prev.key) while @list.next != @list.prev && (@max_size && @size > @max_size || @max_count && @entry.size > @max_count)
64
+ @backend[key] = value
65
+ drop while @max_size && @size > @max_size || @max_count && @backend.size > @max_count
65
66
  end
66
67
  value
67
68
  end
68
69
 
69
70
  # (see Proxy#delete)
70
71
  def delete(key, options = {})
71
- if entry = @entry.delete(key)
72
- @size -= entry.value.bytesize if @max_size
73
- entry.unlink
74
- entry.value
72
+ if value = @backend.delete(key) and @max_size
73
+ @size -= value.bytesize
75
74
  end
75
+ value
76
76
  end
77
77
 
78
78
  # (see Proxy#clear)
79
79
  def clear(options = {})
80
- @entry, @size = {}, 0
81
- @list = Entry.new
82
- @list.prev = @list.next = @list
80
+ @backend = {}
81
+ @size = 0
83
82
  self
84
83
  end
85
84
 
86
- # (see Proxy#values_at)
87
- def values_at(*keys, **options)
88
- @entry.values_at(*keys).map do |entry|
89
- if entry
90
- entry.insert_after(@list)
91
- entry.value
92
- end
93
- end
94
- end
95
-
96
- # (see Proxy#slice)
97
- def slice(*keys, **options)
98
- return super unless @entry.respond_to?(:slice)
99
- hash = @entry.slice(*keys)
100
- hash.each do |key, entry|
101
- entry.insert_after(@list)
102
- hash[key] = entry.value
103
- end
104
- end
105
-
106
- private
107
-
108
- class Entry
109
- attr_accessor :key, :value, :prev, :next
110
-
111
- def unlink
112
- @prev.next = @next if @prev
113
- @next.prev = @prev if @next
114
- @prev = @next = nil
115
- end
116
-
117
- def insert_after(entry)
118
- if entry.next != self
119
- unlink
120
- @next = entry.next
121
- @prev = entry
122
- entry.next.prev = self
123
- entry.next = self
124
- end
85
+ # Drops the least-recently-used pair, if any
86
+ #
87
+ # @param [Hash] options Options to merge
88
+ # @return [(Object, String), nil] The dropped pair, if any
89
+ def drop(options = {})
90
+ if key = @backend.keys.first
91
+ [key, delete(key)]
125
92
  end
126
93
  end
127
94
  end
@@ -1,4 +1,5 @@
1
1
  module Moneta
2
+ # @api private
2
3
  module Adapters
3
4
  # Prefer Dalli over native Memcached!
4
5
  #
@@ -87,7 +87,7 @@ module Moneta
87
87
  @backend.get_multi(keys).tap do |pairs|
88
88
  next if pairs.empty?
89
89
  expires = expires_value(options, nil)
90
- next if expires.nil?
90
+ next if expires == nil
91
91
  expires = expires.to_i if Numeric === expires
92
92
  expires ||= 0
93
93
  @backend.multi do
@@ -22,7 +22,7 @@ module Moneta
22
22
  self.default_expires = options.delete(:expires)
23
23
  @backend = options[:backend] ||
24
24
  begin
25
- options.merge!(prefix_key: options.delete(:namespace)) if options[:namespace]
25
+ options[:prefix_key] = options.delete(:namespace) if options[:namespace]
26
26
  # We don't want a limitation on the key charset. Therefore we use the binary protocol.
27
27
  # It is also faster.
28
28
  options[:binary_protocol] = true unless options.include?(:binary_protocol)
@@ -35,13 +35,14 @@ module Moneta
35
35
  value = @backend.get(key, false)
36
36
  if value
37
37
  expires = expires_value(options, nil)
38
- unless expires.nil?
38
+ unless expires == nil
39
39
  Numeric === expires and expires = expires.to_i
40
40
  @backend.set(key, value, expires || 0, false)
41
41
  end
42
42
  value
43
43
  end
44
44
  rescue ::Memcached::NotFound
45
+ nil
45
46
  end
46
47
 
47
48
  # (see Proxy#store)
@@ -59,20 +60,21 @@ module Moneta
59
60
  @backend.delete(key)
60
61
  value
61
62
  rescue ::Memcached::NotFound
63
+ nil
62
64
  end
63
65
 
64
66
  # (see Proxy#increment)
65
67
  def increment(key, amount = 1, options = {})
66
68
  result = if amount >= 0
67
- @backend.increment(key, amount)
68
- else
69
- @backend.decrement(key, -amount)
70
- end
69
+ @backend.increment(key, amount)
70
+ else
71
+ @backend.decrement(key, -amount)
72
+ end
71
73
  # HACK: Throw error if applied to invalid value
72
74
  # see https://github.com/evan/memcached/issues/110
73
- Utils.to_int((@backend.get(key, false) rescue nil)) if result == 0
75
+ Integer((@backend.get(key, false) rescue 0)) if result == 0
74
76
  result
75
- rescue ::Memcached::NotFound => ex
77
+ rescue ::Memcached::NotFound
76
78
  retry unless create(key, amount.to_s, options)
77
79
  amount
78
80
  end
@@ -1,4 +1,5 @@
1
1
  module Moneta
2
+ # @api private
2
3
  module Adapters
3
4
  begin
4
5
  require 'moneta/adapters/mongo/official'
@@ -84,9 +84,9 @@ module Moneta
84
84
  # BSON will use String#force_encoding to make the string 8-bit
85
85
  # ASCII. This could break unicode text so we should dup in this
86
86
  # case, and it also fails with frozen strings.
87
- def to_binary(s)
88
- s = s.dup if s.frozen? || s.encoding != Encoding::ASCII_8BIT
89
- ::BSON::Binary.new(s)
87
+ def to_binary(str)
88
+ str = str.dup if str.frozen? || str.encoding != Encoding::ASCII_8BIT
89
+ ::BSON::Binary.new(str)
90
90
  end
91
91
 
92
92
  if defined?(::BSON::VERSION) and ::BSON::VERSION[0].to_i >= 2
@@ -87,11 +87,10 @@ module Moneta
87
87
  # (see Proxy#increment)
88
88
  def increment(key, amount = 1, options = {})
89
89
  @backend.with(safe: true, consistency: :strong) do |safe|
90
- safe[@collection.name].
91
- find(_id: to_binary(key)).
92
- modify({:$inc => { @value_field => amount }},
93
- new: true,
94
- upsert: true)[@value_field]
90
+ safe[@collection.name]
91
+ .find(_id: to_binary(key))
92
+ .modify({ :$inc => { @value_field => amount } },
93
+ new: true, upsert: true)[@value_field]
95
94
  end
96
95
  rescue ::Moped::Errors::OperationFailure
97
96
  tries ||= 0
@@ -120,7 +119,7 @@ module Moneta
120
119
 
121
120
  # (see Proxy#slice)
122
121
  def slice(*keys, **options)
123
- query = @collection.find(_id: {:$in => keys.map(&method(:to_binary))})
122
+ query = @collection.find(_id: { :$in => keys.map(&method(:to_binary)) })
124
123
  pairs = query.map do |doc|
125
124
  next if doc[@expires_field] && doc[@expires_field] < Time.now
126
125
  [from_binary(doc[:_id]), doc_to_value(doc)]
@@ -137,10 +136,10 @@ module Moneta
137
136
  def merge!(pairs, options = {})
138
137
  @backend.with(safe: true, consistency: :strong) do |safe|
139
138
  collection = safe[@collection.name]
140
- existing = collection.
141
- find(_id: {:$in => pairs.map { |key, _| to_binary(key) }.to_a}).
142
- map{ |doc| [from_binary(doc[:_id]), doc_to_value(doc)] }.
143
- to_h
139
+ existing = collection
140
+ .find(_id: { :$in => pairs.map { |key, _| to_binary(key) }.to_a })
141
+ .map { |doc| [from_binary(doc[:_id]), doc_to_value(doc)] }
142
+ .to_h
144
143
 
145
144
  update_pairs, insert_pairs = pairs.partition { |key, _| existing.key?(key) }
146
145
  unless insert_pairs.empty?
@@ -152,9 +151,9 @@ module Moneta
152
151
  update_pairs.each do |key, value|
153
152
  value = yield(key, existing[key], value) if block_given?
154
153
  binary = to_binary(key)
155
- collection.
156
- find(_id: binary).
157
- update(value_to_doc(binary, value, options))
154
+ collection
155
+ .find(_id: binary)
156
+ .update(value_to_doc(binary, value, options))
158
157
  end
159
158
  end
160
159
  self
@@ -45,7 +45,7 @@ module Moneta
45
45
  @backend.use(db)
46
46
  @collection = @backend[collection]
47
47
  if @backend.command(buildinfo: 1).documents.first['version'] >= '2.2'
48
- @collection.indexes.create_one({@expires_field => 1}, expire_after: 0)
48
+ @collection.indexes.create_one({ @expires_field => 1 }, expire_after: 0)
49
49
  else
50
50
  warn 'Moneta::Adapters::Mongo - You are using MongoDB version < 2.2, expired documents will not be deleted'
51
51
  end
@@ -59,7 +59,7 @@ module Moneta
59
59
  expires = expires_at(options, nil)
60
60
  # @expires_field must be a Time object (BSON date datatype)
61
61
  @collection.update_one({ _id: key },
62
- '$set' => { @expires_field => expires }) unless expires.nil?
62
+ '$set' => { @expires_field => expires }) unless expires == nil
63
63
  doc_to_value(doc)
64
64
  end
65
65
  end
@@ -84,8 +84,7 @@ module Moneta
84
84
  def delete(key, options = {})
85
85
  key = to_binary(key)
86
86
  if doc = @collection.find(_id: key).find_one_and_delete and
87
- !doc[@expires_field] || doc[@expires_field] >= Time.now
88
- then
87
+ !doc[@expires_field] || doc[@expires_field] >= Time.now
89
88
  doc_to_value(doc)
90
89
  end
91
90
  end
@@ -94,8 +93,8 @@ module Moneta
94
93
  def increment(key, amount = 1, options = {})
95
94
  @collection.find_one_and_update({ _id: to_binary(key) },
96
95
  { '$inc' => { @value_field => amount } },
97
- :return_document => :after,
98
- :upsert => true)[@value_field]
96
+ return_document: :after,
97
+ upsert: true)[@value_field]
99
98
  end
100
99
 
101
100
  # (see Proxy#create)
@@ -122,7 +121,7 @@ module Moneta
122
121
 
123
122
  # (see Proxy#slice)
124
123
  def slice(*keys, **options)
125
- query = @collection.find(_id: {:$in => keys.map(&method(:to_binary))})
124
+ query = @collection.find(_id: { :$in => keys.map(&method(:to_binary)) })
126
125
  pairs = query.map do |doc|
127
126
  next if doc[@expires_field] && doc[@expires_field] < Time.now
128
127
  [from_binary(doc[:_id]), doc_to_value(doc)]
@@ -147,7 +146,7 @@ module Moneta
147
146
  update_pairs.each do |key, value|
148
147
  value = yield(key, existing[key], value) if block_given?
149
148
  binary = to_binary(key)
150
- @collection.replace_one({_id: binary}, value_to_doc(binary, value, options))
149
+ @collection.replace_one({ _id: binary }, value_to_doc(binary, value, options))
151
150
  end
152
151
 
153
152
  self