dalli 2.7.11 → 3.2.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 +4 -4
- data/Gemfile +7 -6
- data/History.md +124 -0
- data/README.md +26 -200
- data/lib/dalli/cas/client.rb +1 -57
- data/lib/dalli/client.rb +230 -263
- data/lib/dalli/compressor.rb +12 -2
- data/lib/dalli/key_manager.rb +113 -0
- data/lib/dalli/options.rb +6 -7
- data/lib/dalli/pipelined_getter.rb +177 -0
- data/lib/dalli/protocol/base.rb +241 -0
- data/lib/dalli/protocol/binary/request_formatter.rb +117 -0
- data/lib/dalli/protocol/binary/response_header.rb +36 -0
- data/lib/dalli/protocol/binary/response_processor.rb +239 -0
- data/lib/dalli/protocol/binary/sasl_authentication.rb +60 -0
- data/lib/dalli/protocol/binary.rb +173 -0
- data/lib/dalli/protocol/connection_manager.rb +252 -0
- data/lib/dalli/protocol/meta/key_regularizer.rb +31 -0
- data/lib/dalli/protocol/meta/request_formatter.rb +108 -0
- data/lib/dalli/protocol/meta/response_processor.rb +211 -0
- data/lib/dalli/protocol/meta.rb +177 -0
- data/lib/dalli/protocol/response_buffer.rb +54 -0
- data/lib/dalli/protocol/server_config_parser.rb +84 -0
- data/lib/dalli/protocol/ttl_sanitizer.rb +45 -0
- data/lib/dalli/protocol/value_compressor.rb +85 -0
- data/lib/dalli/protocol/value_marshaller.rb +59 -0
- data/lib/dalli/protocol/value_serializer.rb +91 -0
- data/lib/dalli/protocol.rb +8 -0
- data/lib/dalli/ring.rb +90 -81
- data/lib/dalli/server.rb +3 -749
- data/lib/dalli/servers_arg_normalizer.rb +54 -0
- data/lib/dalli/socket.rb +117 -137
- data/lib/dalli/version.rb +4 -1
- data/lib/dalli.rb +42 -14
- data/lib/rack/session/dalli.rb +95 -95
- metadata +118 -10
- data/lib/action_dispatch/middleware/session/dalli_store.rb +0 -82
- data/lib/active_support/cache/dalli_store.rb +0 -441
- data/lib/dalli/railtie.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56babb2362639cca3fd24225eea2a76a0d9a075a3b113b7f8ea09814a79bf59a
|
4
|
+
data.tar.gz: 309f6be3fce52b38608c4b22e5dce439e68944796fbe1f2240b2ed40760e8700
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16847c7b39ff624deeb5fecd324d3f0bddafdcd6096c5f65cfa7a79e8b2369930b7078e8fc019bd49015c3415b43f33ea07cf85380b28d3c46199339bc9aeb2a
|
7
|
+
data.tar.gz: 890f87a779947ec269fb9889334eaa7b4424a654995b9b12b723dee7452f82de066b538465800c20bf9ed9bb2c5a81fbca3ae5ff382340f241f0525ad158df0c
|
data/Gemfile
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
gemspec
|
4
6
|
|
5
|
-
gem 'appraisal'
|
6
|
-
gem 'kgio', :platform => :mri
|
7
|
-
gem 'rails'
|
8
|
-
|
9
7
|
group :test do
|
10
8
|
gem 'minitest'
|
11
|
-
gem 'mocha'
|
12
9
|
gem 'rake'
|
13
|
-
gem '
|
10
|
+
gem 'rubocop'
|
11
|
+
gem 'rubocop-minitest'
|
12
|
+
gem 'rubocop-performance'
|
13
|
+
gem 'rubocop-rake'
|
14
|
+
gem 'ruby-prof', platform: :mri
|
14
15
|
gem 'simplecov'
|
15
16
|
end
|
data/History.md
CHANGED
@@ -1,6 +1,130 @@
|
|
1
1
|
Dalli Changelog
|
2
2
|
=====================
|
3
3
|
|
4
|
+
Unreleased
|
5
|
+
==========
|
6
|
+
|
7
|
+
3.2.0
|
8
|
+
==========
|
9
|
+
|
10
|
+
- BREAKING CHANGE: Remove protocol_implementation client option (petergoldstein)
|
11
|
+
- Add protocol option with meta implementation (petergoldstein)
|
12
|
+
|
13
|
+
3.1.6
|
14
|
+
==========
|
15
|
+
|
16
|
+
- Fix bug with cas/cas! with "Not found" value (petergoldstein)
|
17
|
+
- Add Ruby 3.1 to CI (petergoldstein)
|
18
|
+
- Replace reject(&:nil?) with compact (petergoldstein)
|
19
|
+
|
20
|
+
3.1.5
|
21
|
+
==========
|
22
|
+
|
23
|
+
- Fix bug with get_cas key with "Not found" value (petergoldstein)
|
24
|
+
- Replace should return nil, not raise error, on miss (petergoldstein)
|
25
|
+
|
26
|
+
3.1.4
|
27
|
+
==========
|
28
|
+
|
29
|
+
- Improve response parsing performance (casperisfine)
|
30
|
+
- Reorganize binary protocol parsing a bit (petergoldstein)
|
31
|
+
- Fix handling of non-ASCII keys in get_multi (petergoldstein)
|
32
|
+
|
33
|
+
3.1.3
|
34
|
+
==========
|
35
|
+
|
36
|
+
- Restore falsey behavior on delete/delete_cas for nonexistent key (petergoldstein)
|
37
|
+
|
38
|
+
3.1.2
|
39
|
+
==========
|
40
|
+
|
41
|
+
- Make quiet? / multi? public on Dalli::Protocol::Binary (petergoldstein)
|
42
|
+
|
43
|
+
3.1.1
|
44
|
+
==========
|
45
|
+
|
46
|
+
- Add quiet support for incr, decr, append, depend, and flush (petergoldstein)
|
47
|
+
- Additional refactoring to allow reuse of connection behavior (petergoldstein)
|
48
|
+
- Fix issue in flush such that it wasn't passing the delay argument to memcached (petergoldstein)
|
49
|
+
|
50
|
+
3.1.0
|
51
|
+
==========
|
52
|
+
|
53
|
+
- BREAKING CHANGE: Update Rack::Session::Dalli to inherit from Abstract::PersistedSecure. This will invalidate existing sessions (petergoldstein)
|
54
|
+
- BREAKING CHANGE: Use of unsupported operations in a multi block now raise an error. (petergoldstein)
|
55
|
+
- Extract PipelinedGetter from Dalli::Client (petergoldstein)
|
56
|
+
- Fix SSL socket so that it works with pipelined gets (petergoldstein)
|
57
|
+
- Additional refactoring to split classes (petergoldstein)
|
58
|
+
|
59
|
+
3.0.6
|
60
|
+
==========
|
61
|
+
|
62
|
+
- Fix regression in SASL authentication response parsing (petergoldstein)
|
63
|
+
|
64
|
+
3.0.5
|
65
|
+
==========
|
66
|
+
|
67
|
+
- Add Rubocop and fix most outstanding issues (petergoldstein)
|
68
|
+
- Extract a number of classes, to simplify the largest classes (petergoldstein)
|
69
|
+
- Ensure against socket corruption if an error occurs in a multi block (petergoldstein)
|
70
|
+
|
71
|
+
3.0.4
|
72
|
+
==========
|
73
|
+
|
74
|
+
- Clean connections and retry after NetworkError in get_multi (andrejbl)
|
75
|
+
- Internal refactoring and cleanup (petergoldstein)
|
76
|
+
|
77
|
+
3.0.3
|
78
|
+
==========
|
79
|
+
|
80
|
+
- Restore ability for `compress` to be disabled on a per request basis (petergoldstein)
|
81
|
+
- Fix broken image in README (deining)
|
82
|
+
- Use bundler-cache in CI (olleolleolle)
|
83
|
+
- Remove the OpenSSL extensions dependency (petergoldstein)
|
84
|
+
- Add Memcached 1.5.x to the CI matrix
|
85
|
+
- Updated compression documentation (petergoldstein)
|
86
|
+
|
87
|
+
3.0.2
|
88
|
+
==========
|
89
|
+
|
90
|
+
- Restore Windows compatibility (petergoldstein)
|
91
|
+
- Add JRuby to CI and make requisite changes (petergoldstein)
|
92
|
+
- Clarify documentation for supported rubies (petergoldstein)
|
93
|
+
|
94
|
+
3.0.1
|
95
|
+
==========
|
96
|
+
|
97
|
+
- Fix syntax error that prevented inclusion of Dalli::Server (ryanfb)
|
98
|
+
- Restore with method required by ActiveSupport::Cache::MemCacheStore
|
99
|
+
|
100
|
+
3.0.0
|
101
|
+
==========
|
102
|
+
- BREAKING CHANGES:
|
103
|
+
|
104
|
+
* Removes :dalli_store.
|
105
|
+
Use Rails' official :mem_cache_store instead.
|
106
|
+
https://guides.rubyonrails.org/caching_with_rails.html
|
107
|
+
* Attempting to store a larger value than allowed by memcached used to
|
108
|
+
print a warning and truncate the value. This now raises an error to
|
109
|
+
prevent silent data corruption.
|
110
|
+
* Compression now defaults to `true` for large values (greater than 4KB).
|
111
|
+
This is intended to minimize errors due to the previous note.
|
112
|
+
* Errors marshalling values now raise rather than just printing an error.
|
113
|
+
* The Rack session adapter has been refactored to remove support for thread-unsafe
|
114
|
+
configurations. You will need to include the `connection_pool` gem in
|
115
|
+
your Gemfile to ensure session operations are thread-safe.
|
116
|
+
|
117
|
+
- Raise NetworkError when multi response gets into corrupt state (mervync, #783)
|
118
|
+
- Validate servers argument (semaperepelitsa, petergoldstein, #776)
|
119
|
+
- Enable SSL support (bdunne, #775)
|
120
|
+
- Add gat operation (tbeauvais, #769)
|
121
|
+
- Removes inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
|
122
|
+
- Switch repo to Github Actions and upgrade Ruby versions (petergoldstein, bdunne, Fryguy)
|
123
|
+
- Update benchmark test for Rubyprof changes (nateberkopec)
|
124
|
+
- Remove support for the `kgio` gem, it is not relevant in Ruby 2.3+. (mperham)
|
125
|
+
- Remove inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
|
126
|
+
|
127
|
+
|
4
128
|
2.7.11
|
5
129
|
==========
|
6
130
|
- DEPRECATION: :dalli_store will be removed in Dalli 3.0.
|
data/README.md
CHANGED
@@ -1,224 +1,50 @@
|
|
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
|
-
Dalli is a high performance pure Ruby client for accessing memcached servers.
|
5
|
-
|
6
|
-
The name is a variant of Salvador Dali for his famous painting [The Persistence of Memory](http://en.wikipedia.org/wiki/The_Persistence_of_Memory).
|
7
|
-
|
8
|
-
![Persistence of Memory](http://www.virtualdali.com/assets/paintings/31PersistenceOfMemory.jpg)
|
9
|
-
|
10
|
-
Dalli's initial development was sponsored by [CouchBase](http://www.couchbase.com/). Many thanks to them!
|
11
|
-
|
12
|
-
Supported Ruby versions and implementations
|
13
|
-
------------------------------------------------
|
14
|
-
|
15
|
-
Dalli should work identically on:
|
16
|
-
|
17
|
-
* JRuby 1.6+
|
18
|
-
* Ruby 1.9.3+
|
19
|
-
* Rubinius 2.0
|
20
|
-
|
21
|
-
If you have problems, please enter an issue.
|
22
|
-
|
23
|
-
|
24
|
-
Installation and Usage
|
25
|
-
------------------------
|
26
|
-
|
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
|
28
|
-
|
29
|
-
brew install memcached
|
30
|
-
|
31
|
-
On Ubuntu you can install it by running:
|
32
|
-
|
33
|
-
apt-get install memcached
|
34
|
-
|
35
|
-
You can verify your installation using this piece of code:
|
36
|
-
|
37
|
-
```bash
|
38
|
-
gem install dalli
|
39
|
-
```
|
40
|
-
|
41
|
-
```ruby
|
42
|
-
require 'dalli'
|
43
|
-
options = { :namespace => "app_v1", :compress => true }
|
44
|
-
dc = Dalli::Client.new('localhost:11211', options)
|
45
|
-
dc.set('abc', 123)
|
46
|
-
value = dc.get('abc')
|
47
|
-
```
|
48
|
-
|
49
|
-
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.
|
50
|
-
|
51
|
-
Dalli has no runtime dependencies.
|
52
|
-
|
53
|
-
Usage with Rails 3.x and 4.x
|
54
|
-
---------------------------
|
55
|
-
|
56
|
-
In your Gemfile:
|
57
|
-
|
58
|
-
```ruby
|
59
|
-
gem 'dalli'
|
60
|
-
```
|
61
|
-
|
62
|
-
In `config/environments/production.rb`:
|
63
|
-
|
64
|
-
```ruby
|
65
|
-
config.cache_store = :dalli_store
|
66
|
-
```
|
67
|
-
|
68
|
-
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.
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
config.cache_store = :dalli_store, 'cache-1.example.com', 'cache-2.example.com:11211:2',
|
72
|
-
{ :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true }
|
73
|
-
```
|
74
|
-
|
75
|
-
You can specify a port and a weight by appending to the server name. You may wish to increase the weight of a server with more memory configured. (e.g. to specify port 11211 and a weight of 2, append `:11211:2` )
|
76
|
-
|
77
|
-
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:
|
78
|
-
|
79
|
-
```ruby
|
80
|
-
config.cache_store = :dalli_store, nil, { :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true }
|
81
|
-
```
|
82
|
-
|
83
|
-
To use Dalli for Rails session storage that times out after 20 minutes, in `config/initializers/session_store.rb`:
|
84
|
-
|
85
|
-
For Rails >= 3.2.4:
|
86
|
-
|
87
|
-
```ruby
|
88
|
-
Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 20.minutes
|
89
|
-
```
|
90
|
-
|
91
|
-
For Rails 3.x:
|
92
|
-
|
93
|
-
```ruby
|
94
|
-
require 'action_dispatch/middleware/session/dalli_store'
|
95
|
-
Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 20.minutes
|
96
|
-
```
|
97
|
-
|
98
|
-
Dalli does not support Rails 2.x.
|
4
|
+
Dalli is a high performance pure Ruby client for accessing memcached servers.
|
99
5
|
|
6
|
+
Dalli supports:
|
100
7
|
|
101
|
-
|
102
|
-
|
8
|
+
* Simple and complex memcached configurations
|
9
|
+
* Failover between memcached instances
|
10
|
+
* Fine-grained control of data serialization and compression
|
11
|
+
* Thread-safe operation (either through use of a connection pool, or by using the Dalli client in threadsafe mode)
|
12
|
+
* SSL/TLS connections to memcached
|
13
|
+
* SASL authentication
|
103
14
|
|
104
|
-
|
105
|
-
of Dalli clients with Rails to ensure the `Rails.cache` singleton does not become a
|
106
|
-
source of thread contention. You must add `gem 'connection_pool'` to your Gemfile and
|
107
|
-
add :pool\_size to your `dalli_store` config:
|
108
|
-
|
109
|
-
```ruby
|
110
|
-
config.cache_store = :dalli_store, 'cache-1.example.com', { :pool_size => 5 }
|
111
|
-
```
|
112
|
-
|
113
|
-
You can then use the Rails cache as normal and Rails.cache will use the pool transparently under the covers, or you can check out a Dalli client directly from the pool:
|
114
|
-
|
115
|
-
```ruby
|
116
|
-
Rails.cache.fetch('foo', :expires_in => 300) do
|
117
|
-
'bar'
|
118
|
-
end
|
119
|
-
|
120
|
-
Rails.cache.dalli.with do |client|
|
121
|
-
# client is a Dalli::Client instance which you can
|
122
|
-
# use ONLY within this block
|
123
|
-
end
|
124
|
-
```
|
125
|
-
|
126
|
-
|
127
|
-
Configuration
|
128
|
-
------------------------
|
129
|
-
|
130
|
-
**servers**: An Array of "host:port:weight" where weight allows you to distribute cache unevenly.
|
131
|
-
|
132
|
-
Dalli::Client accepts the following options. All times are in seconds.
|
133
|
-
|
134
|
-
**expires_in**: Global default for key TTL. Default is 0, which means no expiry.
|
135
|
-
|
136
|
-
**namespace**: If specified, prepends each key with this value to provide simple namespacing. Default is nil.
|
137
|
-
|
138
|
-
**failover**: Boolean, if true Dalli will failover to another server if the main server for a key is down. Default is true.
|
139
|
-
|
140
|
-
**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.
|
141
|
-
|
142
|
-
**serializer**: The serializer to use for objects being stored (ex. JSON).
|
143
|
-
Default is Marshal.
|
144
|
-
|
145
|
-
**compress**: Boolean, if true Dalli will gzip-compress values larger than 1K. Default is false.
|
146
|
-
|
147
|
-
**compression_min_size**: Minimum value byte size for which to attempt compression. Default is 1K.
|
148
|
-
|
149
|
-
**compression_max_size**: Maximum value byte size for which to attempt compression. Default is unlimited.
|
150
|
-
|
151
|
-
**compressor**: The compressor to use for objects being stored.
|
152
|
-
Default is zlib, implemented under `Dalli::Compressor`.
|
153
|
-
If serving compressed data using nginx's HttpMemcachedModule, set `memcached_gzip_flag 2` and use `Dalli::GzipCompressor`
|
154
|
-
|
155
|
-
**keepalive**: Boolean. If true, Dalli will enable keep-alive for socket connections. Default is true.
|
156
|
-
|
157
|
-
**socket_timeout**: Timeout for all socket operations (connect, read, write). Default is 0.5.
|
158
|
-
|
159
|
-
**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.
|
160
|
-
|
161
|
-
**socket_failure_delay**: Before retrying a socket operation, the process sleeps for this amount of time. Default is 0.01. Set to nil for no delay.
|
162
|
-
|
163
|
-
**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 60 seconds.
|
164
|
-
|
165
|
-
**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.
|
166
|
-
|
167
|
-
**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.
|
168
|
-
|
169
|
-
**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.
|
170
|
-
|
171
|
-
**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.
|
172
|
-
|
173
|
-
**sndbuf**: In bytes, set the socket SO_SNDBUF. Defaults to operating system default.
|
174
|
-
|
175
|
-
**rcvbuf**: In bytes, set the socket SO_RCVBUF. Defaults to operating system default.
|
176
|
-
|
177
|
-
**cache_nils**: Boolean. If true Dalli will not treat cached `nil` values as 'not found' for `#fetch` operations. Default is false.
|
178
|
-
|
179
|
-
**raise_errors**: Boolean. When true DalliStore will reraise Dalli:DalliError instead swallowing the error. Default is false.
|
180
|
-
|
181
|
-
**instrument_errors**: Boolean. When true DalliStore will send notification of Dalli::DalliError via a 'cache_error.active_support' event. Default is false.
|
182
|
-
|
183
|
-
Features and Changes
|
184
|
-
------------------------
|
15
|
+
The name is a variant of Salvador Dali for his famous painting [The Persistence of Memory](http://en.wikipedia.org/wiki/The_Persistence_of_Memory).
|
185
16
|
|
186
|
-
|
17
|
+
![Persistence of Memory](https://upload.wikimedia.org/wikipedia/en/d/dd/The_Persistence_of_Memory.jpg)
|
187
18
|
|
188
|
-
Dalli does not need anything special in Unicorn/Passenger since 2.0.4.
|
189
|
-
It will detect sockets shared with child processes and gracefully reopen the
|
190
|
-
socket.
|
191
19
|
|
192
|
-
|
20
|
+
## Documentation and Information
|
193
21
|
|
194
|
-
[
|
22
|
+
* [User Documentation](https://github.com/petergoldstein/dalli/wiki) - The documentation is maintained in the repository's wiki.
|
23
|
+
* [Announcements](https://github.com/petergoldstein/dalli/discussions/categories/announcements) - Announcements of interest to the Dalli community will be posted here.
|
24
|
+
* [Bug Reports](https://github.com/petergoldstein/dalli/issues) - If you discover a problem with Dalli, please submit a bug report in the tracker.
|
25
|
+
* [Forum](https://github.com/petergoldstein/dalli/discussions/categories/q-a) - If you have questions about Dalli, please post them here.
|
26
|
+
* [Client API](https://www.rubydoc.info/github/petergoldstein/dalli/master/Dalli/Client) - Ruby documentation for the `Dalli::Client` API
|
195
27
|
|
196
|
-
|
197
|
-
-------------
|
28
|
+
## Contributing
|
198
29
|
|
199
30
|
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.
|
200
31
|
|
201
|
-
|
202
|
-
|
203
|
-
Thanks
|
204
|
-
------------
|
205
|
-
|
206
|
-
Mike Perham - for originally authoring the Dalli project and serving as maintainer and primary contributor
|
32
|
+
## Appreciation
|
207
33
|
|
208
|
-
|
34
|
+
Dalli would not exist in its current form without the contributions of many people. But special thanks go to several individuals and organizations:
|
209
35
|
|
210
|
-
|
36
|
+
* Mike Perham - for originally authoring the Dalli project and serving as maintainer and primary contributor for many years
|
37
|
+
* Eric Wong - for help using his [kgio](http://bogomips.org/kgio/) library.
|
38
|
+
* Brian Mitchell - for his remix-stash project which was helpful when implementing and testing the binary protocol support.
|
39
|
+
* [CouchBase](http://couchbase.com) - for their sponsorship of the original development
|
211
40
|
|
212
|
-
[CouchBase](http://couchbase.com) - for their project sponsorship
|
213
41
|
|
214
|
-
Authors
|
215
|
-
----------
|
42
|
+
## Authors
|
216
43
|
|
217
44
|
* [Peter M. Goldstein](https://github.com/petergoldstein) - current maintainer
|
218
45
|
* [Mike Perham](https://github.com/mperham) and contributors
|
219
46
|
|
220
47
|
|
221
|
-
Copyright
|
222
|
-
-----------
|
48
|
+
## Copyright
|
223
49
|
|
224
50
|
Copyright (c) Mike Perham, Peter M. Goldstein. See LICENSE for details.
|
data/lib/dalli/cas/client.rb
CHANGED
@@ -1,59 +1,3 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'dalli/client'
|
3
2
|
|
4
|
-
|
5
|
-
class Client
|
6
|
-
##
|
7
|
-
# Get the value and CAS ID associated with the key. If a block is provided,
|
8
|
-
# value and CAS will be passed to the block.
|
9
|
-
def get_cas(key)
|
10
|
-
(value, cas) = perform(:cas, key)
|
11
|
-
value = (!value || value == 'Not found') ? nil : value
|
12
|
-
if block_given?
|
13
|
-
yield value, cas
|
14
|
-
else
|
15
|
-
[value, cas]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
##
|
20
|
-
# Fetch multiple keys efficiently, including available metadata such as CAS.
|
21
|
-
# If a block is given, yields key/data pairs one a time. Data is an array:
|
22
|
-
# [value, cas_id]
|
23
|
-
# If no block is given, returns a hash of
|
24
|
-
# { 'key' => [value, cas_id] }
|
25
|
-
def get_multi_cas(*keys)
|
26
|
-
if block_given?
|
27
|
-
get_multi_yielder(keys) {|*args| yield(*args)}
|
28
|
-
else
|
29
|
-
Hash.new.tap do |hash|
|
30
|
-
get_multi_yielder(keys) {|k, data| hash[k] = data}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
##
|
36
|
-
# Set the key-value pair, verifying existing CAS.
|
37
|
-
# Returns the resulting CAS value if succeeded, and falsy otherwise.
|
38
|
-
def set_cas(key, value, cas, ttl=nil, options=nil)
|
39
|
-
ttl ||= @options[:expires_in].to_i
|
40
|
-
perform(:set, key, value, ttl, cas, options)
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# Conditionally add a key/value pair, verifying existing CAS, only if the
|
45
|
-
# key already exists on the server. Returns the new CAS value if the
|
46
|
-
# operation succeeded, or falsy otherwise.
|
47
|
-
def replace_cas(key, value, cas, ttl=nil, options=nil)
|
48
|
-
ttl ||= @options[:expires_in].to_i
|
49
|
-
perform(:replace, key, value, ttl, cas, options)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Delete a key/value pair, verifying existing CAS.
|
53
|
-
# Returns true if succeeded, and falsy otherwise.
|
54
|
-
def delete_cas(key, cas=0)
|
55
|
-
perform(:delete, key, cas)
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
3
|
+
puts "You can remove `require 'dalli/cas/client'` as this code has been rolled into the standard 'dalli/client'."
|