dalli 2.7.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of dalli might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/Gemfile +5 -7
- data/History.md +107 -0
- data/LICENSE +1 -1
- data/README.md +53 -113
- data/lib/dalli/cas/client.rb +1 -58
- data/lib/dalli/client.rb +235 -133
- data/lib/dalli/compressor.rb +5 -3
- data/lib/dalli/options.rb +4 -4
- data/lib/dalli/protocol/binary.rb +753 -0
- data/lib/dalli/protocol.rb +9 -0
- data/lib/dalli/ring.rb +17 -68
- data/lib/dalli/server.rb +3 -693
- data/lib/dalli/socket.rb +72 -85
- data/lib/dalli/version.rb +3 -1
- data/lib/dalli.rb +17 -16
- data/lib/rack/session/dalli.rb +123 -31
- metadata +24 -59
- data/Performance.md +0 -42
- data/Rakefile +0 -42
- data/dalli.gemspec +0 -29
- data/lib/action_dispatch/middleware/session/dalli_store.rb +0 -81
- data/lib/active_support/cache/dalli_store.rb +0 -363
- data/lib/dalli/railtie.rb +0 -7
- data/test/benchmark_test.rb +0 -242
- data/test/helper.rb +0 -55
- data/test/memcached_mock.rb +0 -121
- data/test/sasldb +0 -1
- data/test/test_active_support.rb +0 -439
- data/test/test_cas_client.rb +0 -107
- data/test/test_compressor.rb +0 -53
- data/test/test_dalli.rb +0 -625
- data/test/test_encoding.rb +0 -32
- data/test/test_failover.rb +0 -128
- data/test/test_network.rb +0 -54
- data/test/test_rack_session.rb +0 -341
- data/test/test_ring.rb +0 -85
- data/test/test_sasl.rb +0 -110
- data/test/test_serializer.rb +0 -30
- data/test/test_server.rb +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 48a2e02ec2d89d9304b68d36ed3827f4677398043a875f10c78a47f0517f579b
|
4
|
+
data.tar.gz: f2f365d5bc6d353fed61fd72866460c2e2929de9097018639f78687d96dae320
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 732930e9654c116fbf3769bac8091126f831eb22d795ed8f7d70479ab3a15591576b9e88d150fc5a79590dbec309249d144de909698c010284bbb30b585c5180
|
7
|
+
data.tar.gz: 54aa18fc3808423e74507f1a3934afbbc60b78c080fc3e5bf790a1daf7832af9a8481f77c5dc8fcb428ca9743ec3f5eb3cb0258517d7cb126e5dd3c749e8f56f
|
data/Gemfile
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rake'
|
6
|
-
gem 'kgio', :platform => :mri
|
7
|
-
gem 'appraisal'
|
8
|
-
gem 'connection_pool'
|
9
|
-
|
10
5
|
group :test do
|
11
|
-
gem
|
6
|
+
gem "minitest"
|
7
|
+
gem "rake"
|
8
|
+
gem "simplecov"
|
9
|
+
gem "ruby-prof", platform: :mri
|
12
10
|
end
|
data/History.md
CHANGED
@@ -1,6 +1,113 @@
|
|
1
1
|
Dalli Changelog
|
2
2
|
=====================
|
3
3
|
|
4
|
+
3.0.0
|
5
|
+
==========
|
6
|
+
- BREAKING CHANGES:
|
7
|
+
|
8
|
+
- Removes :dalli_store.
|
9
|
+
Use Rails' official :mem_cache_store instead.
|
10
|
+
https://guides.rubyonrails.org/caching_with_rails.html
|
11
|
+
- Attempting to store a larger value than allowed by memcached used to
|
12
|
+
print a warning and truncate the value. This now raises an error to
|
13
|
+
prevent silent data corruption.
|
14
|
+
- Compression now defaults to `true` for large values (greater than 4KB).
|
15
|
+
This is intended to minimize errors due to the previous note.
|
16
|
+
- Errors marshalling values now raise rather than just printing an error.
|
17
|
+
- The Rack session adapter has been refactored to remove support for thread-unsafe
|
18
|
+
configurations. You will need to include the `connection_pool` gem in
|
19
|
+
your Gemfile to ensure session operations are thread-safe.
|
20
|
+
|
21
|
+
- Raise NetworkError when multi response gets into corrupt state (mervync, #783)
|
22
|
+
- Validate servers argument (semaperepelitsa, petergoldstein, #776)
|
23
|
+
- Enable SSL support (bdunne, #775)
|
24
|
+
- Add gat operation (tbeauvais, #769)
|
25
|
+
- Removes inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
|
26
|
+
- Switch repo to Github Actions and upgrade Ruby versions (petergoldstein, bdunne, Fryguy)
|
27
|
+
- Update benchmark test for Rubyprof changes (nateberkopec)
|
28
|
+
- Remove support for the `kgio` gem, it is not relevant in Ruby 2.3+. (mperham)
|
29
|
+
- Remove inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
|
30
|
+
|
31
|
+
|
32
|
+
2.7.11
|
33
|
+
==========
|
34
|
+
- DEPRECATION: :dalli_store will be removed in Dalli 3.0.
|
35
|
+
Use Rails' official :mem_cache_store instead.
|
36
|
+
https://guides.rubyonrails.org/caching_with_rails.html
|
37
|
+
- Add new `digest_class` option to Dalli::Client [#724]
|
38
|
+
- Don't treat NameError as a network error [#728]
|
39
|
+
- Handle nested comma separated server strings (sambostock)
|
40
|
+
|
41
|
+
2.7.10
|
42
|
+
==========
|
43
|
+
- Revert frozen string change (schneems)
|
44
|
+
- Advertise supports_cached_versioning? in DalliStore (schneems)
|
45
|
+
- Better detection of fork support, to allow specs to run under Truffle Ruby (deepj)
|
46
|
+
- Update logging for over max size to log as error (aeroastro)
|
47
|
+
|
48
|
+
2.7.9
|
49
|
+
==========
|
50
|
+
- Fix behavior for Rails 5.2+ cache_versioning (GriwMF)
|
51
|
+
- Ensure fetch provides the key to the fallback block as an argument (0exp)
|
52
|
+
- Assorted performance improvements (schneems)
|
53
|
+
|
54
|
+
2.7.8
|
55
|
+
==========
|
56
|
+
- Rails 5.2 compatibility (pbougie)
|
57
|
+
- Fix Session Cache compatibility (pixeltrix)
|
58
|
+
|
59
|
+
2.7.7
|
60
|
+
==========
|
61
|
+
- Support large cache keys on fetch multi (sobrinho)
|
62
|
+
- Not found checks no longer trigger the result's equality method (dannyfallon)
|
63
|
+
- Use SVG build badges (olleolleolle)
|
64
|
+
- Travis updates (junaruga, tiarly, petergoldstein)
|
65
|
+
- Update default down_retry_delay (jaredhales)
|
66
|
+
- Close kgio socket after IO.select timeouts
|
67
|
+
- Documentation updates (tipair)
|
68
|
+
- Instrument DalliStore errors with instrument_errors configuration option. (btatnall)
|
69
|
+
|
70
|
+
2.7.6
|
71
|
+
==========
|
72
|
+
- Rails 5.0.0.beta2 compatibility (yui-knk, petergoldstein)
|
73
|
+
- Add cas!, a variant of the #cas method that yields to the block whether or not the key already exist (mwpastore)
|
74
|
+
- Performance improvements (nateberkopec)
|
75
|
+
- Add Ruby 2.3.0 to support matrix (tricknotes)
|
76
|
+
|
77
|
+
2.7.5
|
78
|
+
==========
|
79
|
+
|
80
|
+
- Support rcvbuff and sndbuff byte configuration. (btatnall)
|
81
|
+
- Add `:cache_nils` option to support nil values in `DalliStore#fetch` and `Dalli::Client#fetch` (wjordan, #559)
|
82
|
+
- Log retryable server errors with 'warn' instead of 'info' (phrinx)
|
83
|
+
- Fix timeout issue with Dalli::Client#get_multi_yielder (dspeterson)
|
84
|
+
- Escape namespaces with special regexp characters (Steven Peckins)
|
85
|
+
- Ensure LocalCache supports the `:raw` option and Entry unwrapping (sj26)
|
86
|
+
- Ensure bad ttl values don't cause Dalli::RingError (eagletmt, petergoldstein)
|
87
|
+
- Always pass namespaced key to instrumentation API (kaorimatz)
|
88
|
+
- Replace use of deprecated TimeoutError with Timeout::Error (eagletmt)
|
89
|
+
- Clean up gemspec, and use Bundler for loading (grosser)
|
90
|
+
- Dry up local cache testing (grosser)
|
91
|
+
|
92
|
+
2.7.4
|
93
|
+
==========
|
94
|
+
|
95
|
+
- Restore Windows compatibility (dfens, #524)
|
96
|
+
|
97
|
+
2.7.3
|
98
|
+
==========
|
99
|
+
|
100
|
+
- Assorted spec improvements
|
101
|
+
- README changes to specify defaults for failover and compress options (keen99, #470)
|
102
|
+
- SASL authentication changes to deal with Unicode characters (flypiggy, #477)
|
103
|
+
- Call to_i on ttl to accomodate ActiveSupport::Duration (#494)
|
104
|
+
- Change to implicit blocks for performance (glaucocustodio, #495)
|
105
|
+
- Change to each_key for performance (jastix, #496)
|
106
|
+
- Support stats settings - (dterei, #500)
|
107
|
+
- Raise DallError if hostname canno be parsed (dannyfallon, #501)
|
108
|
+
- Fix instrumentation for falsey values (AlexRiedler, #514)
|
109
|
+
- Support UNIX socket configurations (r-stu31, #515)
|
110
|
+
|
4
111
|
2.7.2
|
5
112
|
==========
|
6
113
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Dalli [![
|
1
|
+
Dalli [![Tests](https://github.com/petergoldstein/dalli/actions/workflows/tests.yml/badge.svg)](https://github.com/petergoldstein/dalli/actions/workflows/tests.yml)
|
2
2
|
=====
|
3
3
|
|
4
4
|
Dalli is a high performance pure Ruby client for accessing memcached servers. It works with memcached 1.4+ only as it uses the newer binary protocol. It should be considered a replacement for the memcache-client gem.
|
@@ -9,26 +9,6 @@ The name is a variant of Salvador Dali for his famous painting [The Persistence
|
|
9
9
|
|
10
10
|
Dalli's initial development was sponsored by [CouchBase](http://www.couchbase.com/). Many thanks to them!
|
11
11
|
|
12
|
-
|
13
|
-
Design
|
14
|
-
------------
|
15
|
-
|
16
|
-
I decided to write Dalli after maintaining memcache-client for two years for a few specific reasons:
|
17
|
-
|
18
|
-
0. The code is mostly old and gross. The bulk of the code is a single 1000 line .rb file.
|
19
|
-
1. It has a lot of options that are infrequently used which complicate the codebase.
|
20
|
-
2. The implementation has no single point to attach monitoring hooks.
|
21
|
-
3. Uses the old text protocol, which hurts raw performance.
|
22
|
-
|
23
|
-
So a few notes. Dalli:
|
24
|
-
|
25
|
-
0. uses the exact same algorithm to choose a server so existing memcached clusters with TBs of data will work identically to memcache-client.
|
26
|
-
1. is approximately 20% faster than memcache-client (which itself was heavily optimized) in Ruby 1.9.2.
|
27
|
-
2. contains explicit "chokepoint" methods which handle all requests; these can be hooked into by monitoring tools (NewRelic, Rack::Bug, etc) to track memcached usage.
|
28
|
-
3. supports SASL for use in managed environments, e.g. Heroku.
|
29
|
-
4. provides proper failover with recovery and adjustable timeouts
|
30
|
-
|
31
|
-
|
32
12
|
Supported Ruby versions and implementations
|
33
13
|
------------------------------------------------
|
34
14
|
|
@@ -44,7 +24,7 @@ If you have problems, please enter an issue.
|
|
44
24
|
Installation and Usage
|
45
25
|
------------------------
|
46
26
|
|
47
|
-
Remember, Dalli **requires** memcached 1.4+. You can check the version with `memcached -h`. Please note that memcached that Mac OS X Snow Leopard ships with is 1.2.8 and won't work. Install 1.4.x using Homebrew with
|
27
|
+
Remember, Dalli **requires** memcached 1.4+. You can check the version with `memcached -h`. Please note that the memcached version that *Mac OS X Snow Leopard* ships with is 1.2.8 and it won't work. Install memcached 1.4.x using Homebrew with
|
48
28
|
|
49
29
|
brew install memcached
|
50
30
|
|
@@ -66,126 +46,84 @@ dc.set('abc', 123)
|
|
66
46
|
value = dc.get('abc')
|
67
47
|
```
|
68
48
|
|
69
|
-
|
70
|
-
|
71
|
-
Dalli has no runtime dependencies and never will. You can optionally install the 'kgio' gem to
|
72
|
-
give Dalli a 20-30% performance boost.
|
73
|
-
|
74
|
-
|
75
|
-
Usage with Rails 3.x and 4.x
|
76
|
-
---------------------------
|
77
|
-
|
78
|
-
In your Gemfile:
|
79
|
-
|
80
|
-
```ruby
|
81
|
-
gem 'dalli'
|
82
|
-
```
|
83
|
-
|
84
|
-
In `config/environments/production.rb`:
|
85
|
-
|
86
|
-
```ruby
|
87
|
-
config.cache_store = :dalli_store
|
88
|
-
```
|
89
|
-
|
90
|
-
Here's a more comprehensive example that sets a reasonable default for maximum cache entry lifetime (one day), enables compression for large values and namespaces all entries for this rails app. Remove the namespace if you have multiple apps which share cached values.
|
91
|
-
|
92
|
-
```ruby
|
93
|
-
config.cache_store = :dalli_store, 'cache-1.example.com', 'cache-2.example.com',
|
94
|
-
{ :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true }
|
95
|
-
```
|
96
|
-
|
97
|
-
If your servers are specified in `ENV["MEMCACHE_SERVERS"]` (e.g. on Heroku when using a third-party hosted addon), simply provide `nil` for the servers:
|
98
|
-
|
99
|
-
```ruby
|
100
|
-
config.cache_store = :dalli_store, nil, { :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true }
|
101
|
-
```
|
102
|
-
|
103
|
-
To use Dalli for Rails session storage that times out after 20 minutes, in `config/initializers/session_store.rb`:
|
104
|
-
|
105
|
-
For Rails >= 3.2.4:
|
106
|
-
|
107
|
-
```ruby
|
108
|
-
Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 20.minutes
|
109
|
-
```
|
110
|
-
|
111
|
-
For Rails 3.x:
|
112
|
-
|
113
|
-
```ruby
|
114
|
-
require 'action_dispatch/middleware/session/dalli_store'
|
115
|
-
Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 20.minutes
|
116
|
-
```
|
117
|
-
|
118
|
-
Dalli does not support Rails 2.x.
|
119
|
-
|
120
|
-
|
121
|
-
Multithreading and Rails
|
122
|
-
--------------------------
|
123
|
-
|
124
|
-
If you use Puma or another threaded app server, as of Dalli 2.7, you can use a pool
|
125
|
-
of Dalli clients with Rails to ensure the `Rails.cache` singleton does not become a
|
126
|
-
source of thread contention. You must add `gem 'connection_pool'` to your Gemfile and
|
127
|
-
add :pool\_size to your `dalli_store` config:
|
128
|
-
|
49
|
+
With SSL enabled:
|
129
50
|
```ruby
|
130
|
-
|
51
|
+
require 'dalli'
|
52
|
+
ssl_context = OpenSSL::SSL::SSLContext.new
|
53
|
+
ssl_context.ca_file = "./myCA.pem"
|
54
|
+
ssl_context.ssl_version = :SSLv23
|
55
|
+
ssl_context.verify_hostname = true
|
56
|
+
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
57
|
+
|
58
|
+
dc = Dalli::Client.new("memcached:11212", :ssl_context => ssl_context)
|
59
|
+
dc.set("abc", 123)
|
60
|
+
value = dc.get("abc")
|
131
61
|
```
|
132
62
|
|
133
|
-
|
134
|
-
|
135
|
-
```ruby
|
136
|
-
Rails.cache.fetch('foo', :expires_in => 300) do
|
137
|
-
'bar'
|
138
|
-
end
|
139
|
-
|
140
|
-
Rails.cache.dalli.with do |client|
|
141
|
-
# client is a Dalli::Client instance which you can
|
142
|
-
# use ONLY within this block
|
143
|
-
end
|
144
|
-
```
|
63
|
+
The test suite requires memcached 1.4.3+ with SASL enabled (`brew install memcached --enable-sasl ; mv /usr/bin/memcached /usr/bin/memcached.old`). Currently only supports the PLAIN mechanism.
|
145
64
|
|
65
|
+
Dalli has no runtime dependencies.
|
146
66
|
|
147
67
|
Configuration
|
148
68
|
------------------------
|
149
69
|
|
70
|
+
**servers**: An Array of "host:port:weight" where weight allows you to distribute cache unevenly.
|
71
|
+
|
150
72
|
Dalli::Client accepts the following options. All times are in seconds.
|
151
73
|
|
152
74
|
**expires_in**: Global default for key TTL. Default is 0, which means no expiry.
|
153
75
|
|
154
|
-
**
|
76
|
+
**namespace**: If specified, prepends each key with this value to provide simple namespacing. Default is nil.
|
77
|
+
|
78
|
+
**failover**: Boolean, if true Dalli will failover to another server if the main server for a key is down. Default is true.
|
79
|
+
|
80
|
+
**threadsafe**: Boolean. If true Dalli ensures that only one thread is using a socket at a given time. Default is true. You can set to false if you are using the Client within a thread-safe connection pool.
|
81
|
+
|
82
|
+
**serializer**: The serializer to use for objects being stored (ex. JSON).
|
83
|
+
Default is Marshal.
|
155
84
|
|
156
|
-
**compress**: Boolean, if true Dalli will gzip-compress values larger than 1K.
|
85
|
+
**compress**: Boolean, if true Dalli will gzip-compress values larger than 1K. Default is false.
|
157
86
|
|
158
87
|
**compression_min_size**: Minimum value byte size for which to attempt compression. Default is 1K.
|
159
88
|
|
160
89
|
**compression_max_size**: Maximum value byte size for which to attempt compression. Default is unlimited.
|
161
90
|
|
162
|
-
**
|
163
|
-
Default is
|
91
|
+
**compressor**: The compressor to use for objects being stored.
|
92
|
+
Default is zlib, implemented under `Dalli::Compressor`.
|
93
|
+
If serving compressed data using nginx's HttpMemcachedModule, set `memcached_gzip_flag 2` and use `Dalli::GzipCompressor`
|
164
94
|
|
165
|
-
**
|
95
|
+
**keepalive**: Boolean. If true, Dalli will enable keep-alive for socket connections. Default is true.
|
96
|
+
|
97
|
+
**socket_timeout**: Timeout for all socket operations (connect, read, write). Default is 1.
|
166
98
|
|
167
99
|
**socket_max_failures**: When a socket operation fails after socket_timeout, the same operation is retried. This is to not immediately mark a server down when there's a very slight network problem. Default is 2.
|
168
100
|
|
169
|
-
**socket_failure_delay**: Before retrying a socket operation, the process sleeps for this amount of time. Default is 0.
|
101
|
+
**socket_failure_delay**: Before retrying a socket operation, the process sleeps for this amount of time. Default is 0.1. Set to nil for no delay.
|
170
102
|
|
171
|
-
**down_retry_delay**: When a server has been marked down due to many failures, the server will be checked again for being alive only after this amount of time. Don't set this value
|
103
|
+
**down_retry_delay**: When a server has been marked down due to many failures, the server will be checked again for being alive only after this amount of time. Don't set this value too low, otherwise each request which tries the failed server might hang for the maximum **socket_timeout**. Default is 30 seconds.
|
172
104
|
|
173
105
|
**value_max_bytes**: The maximum size of a value in memcached. Defaults to 1MB, this can be increased with memcached's -I parameter. You must also configure Dalli to allow the larger size here.
|
174
106
|
|
107
|
+
**error_when_over_max_size**: Boolean. If true, Dalli will throw a Dalli::ValueOverMaxSize exception when trying to store data larger than **value_max_bytes**. Defaults to false, meaning only a warning is logged.
|
108
|
+
|
175
109
|
**username**: The username to use for authenticating this client instance against a SASL-enabled memcached server. Heroku users should not need to use this normally.
|
176
110
|
|
177
111
|
**password**: The password to use for authenticating this client instance against a SASL-enabled memcached server. Heroku users should not need to use this normally.
|
178
112
|
|
179
|
-
**
|
113
|
+
**sndbuf**: In bytes, set the socket SO_SNDBUF. Defaults to operating system default.
|
180
114
|
|
181
|
-
**
|
182
|
-
|
183
|
-
If
|
115
|
+
**rcvbuf**: In bytes, set the socket SO_RCVBUF. Defaults to operating system default.
|
116
|
+
|
117
|
+
**cache_nils**: Boolean. If true Dalli will not treat cached `nil` values as 'not found' for `#fetch` operations. Default is false.
|
118
|
+
|
119
|
+
**raise_errors**: Boolean. When true DalliStore will reraise Dalli:DalliError instead swallowing the error. Default is false.
|
120
|
+
|
121
|
+
**instrument_errors**: Boolean. When true DalliStore will send notification of Dalli::DalliError via a 'cache_error.active_support' event. Default is false.
|
184
122
|
|
185
123
|
Features and Changes
|
186
124
|
------------------------
|
187
125
|
|
188
|
-
By default, Dalli is thread-safe.
|
126
|
+
By default, Dalli is thread-safe. Disable thread-safety at your own peril.
|
189
127
|
|
190
128
|
Dalli does not need anything special in Unicorn/Passenger since 2.0.4.
|
191
129
|
It will detect sockets shared with child processes and gracefully reopen the
|
@@ -198,27 +136,29 @@ Note that Dalli does not require ActiveSupport or Rails. You can safely use it
|
|
198
136
|
Helping Out
|
199
137
|
-------------
|
200
138
|
|
201
|
-
If you have a fix you wish to provide, please fork the code, fix in your local project and then send a pull request on github. Please ensure that you include a test which verifies your fix and update History.md with a one sentence description of your fix so you get credit as a contributor.
|
139
|
+
If you have a fix you wish to provide, please fork the code, fix in your local project and then send a pull request on github. Please ensure that you include a test which verifies your fix and update `History.md` with a one sentence description of your fix so you get credit as a contributor.
|
202
140
|
|
203
141
|
We're not accepting new compressors. They are trivial to add in an initializer. See #385 (LZ4), #406 (Snappy)
|
204
142
|
|
205
143
|
Thanks
|
206
144
|
------------
|
207
145
|
|
208
|
-
|
146
|
+
Mike Perham - for originally authoring the Dalli project and serving as maintainer and primary contributor
|
147
|
+
|
148
|
+
Eric Wong - for help using his [kgio](http://bogomips.org/kgio/) library.
|
209
149
|
|
210
150
|
Brian Mitchell - for his remix-stash project which was helpful when implementing and testing the binary protocol support.
|
211
151
|
|
212
152
|
[CouchBase](http://couchbase.com) - for their project sponsorship
|
213
153
|
|
214
|
-
|
215
|
-
Author
|
154
|
+
Authors
|
216
155
|
----------
|
217
156
|
|
218
|
-
|
157
|
+
* [Peter M. Goldstein](https://github.com/petergoldstein) - current maintainer
|
158
|
+
* [Mike Perham](https://github.com/mperham) and contributors
|
219
159
|
|
220
160
|
|
221
161
|
Copyright
|
222
162
|
-----------
|
223
163
|
|
224
|
-
Copyright (c) Mike Perham. See LICENSE for details.
|
164
|
+
Copyright (c) Mike Perham, Peter M. Goldstein. See LICENSE for details.
|
data/lib/dalli/cas/client.rb
CHANGED
@@ -1,58 +1 @@
|
|
1
|
-
require 'dalli/client'
|
2
|
-
|
3
|
-
module Dalli
|
4
|
-
class Client
|
5
|
-
##
|
6
|
-
# Get the value and CAS ID associated with the key. If a block is provided,
|
7
|
-
# value and CAS will be passed to the block.
|
8
|
-
def get_cas(key)
|
9
|
-
(value, cas) = perform(:cas, key)
|
10
|
-
value = (!value || value == 'Not found') ? nil : value
|
11
|
-
if block_given?
|
12
|
-
yield value, cas
|
13
|
-
else
|
14
|
-
[value, cas]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
##
|
19
|
-
# Fetch multiple keys efficiently, including available metadata such as CAS.
|
20
|
-
# If a block is given, yields key/data pairs one a time. Data is an array:
|
21
|
-
# [value, cas_id]
|
22
|
-
# If no block is given, returns a hash of
|
23
|
-
# { 'key' => [value, cas_id] }
|
24
|
-
def get_multi_cas(*keys)
|
25
|
-
if block_given?
|
26
|
-
get_multi_yielder(keys) {|*args| yield(*args)}
|
27
|
-
else
|
28
|
-
Hash.new.tap do |hash|
|
29
|
-
get_multi_yielder(keys) {|k, data| hash[k] = data}
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
##
|
35
|
-
# Set the key-value pair, verifying existing CAS.
|
36
|
-
# Returns the resulting CAS value if succeeded, and falsy otherwise.
|
37
|
-
def set_cas(key, value, cas, ttl=nil, options=nil)
|
38
|
-
ttl ||= @options[:expires_in].to_i
|
39
|
-
perform(:set, key, value, ttl, cas, options)
|
40
|
-
end
|
41
|
-
|
42
|
-
##
|
43
|
-
# Conditionally add a key/value pair, verifying existing CAS, only if the
|
44
|
-
# key already exists on the server. Returns the new CAS value if the
|
45
|
-
# operation succeeded, or falsy otherwise.
|
46
|
-
def replace_cas(key, value, cas, ttl=nil, options=nil)
|
47
|
-
ttl ||= @options[:expires_in].to_i
|
48
|
-
perform(:replace, key, value, ttl, cas, options)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Delete a key/value pair, verifying existing CAS.
|
52
|
-
# Returns true if succeeded, and falsy otherwise.
|
53
|
-
def delete_cas(key, cas=0)
|
54
|
-
perform(:delete, key, cas)
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
1
|
+
puts "You can remove `require 'dalli/cas/client'` as this code has been rolled into the standard 'dalli/client'.
|