memcache 1.2.9 → 1.2.10
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/ext/native_server.c +12 -6
- data/lib/memcache.rb +1 -3
- data/memcache.gemspec +2 -2
- data/test/memcache_test.rb +8 -0
- metadata +2 -2
data/VERSION.yml
CHANGED
data/ext/native_server.c
CHANGED
@@ -131,8 +131,8 @@ static VALUE mc_initialize(VALUE self, VALUE opts) {
|
|
131
131
|
char* server;
|
132
132
|
int i;
|
133
133
|
|
134
|
-
for (i = 0; i <
|
135
|
-
server = StringValuePtr(
|
134
|
+
for (i = 0; i < RARRAY_LEN(servers_aryv); i++) {
|
135
|
+
server = StringValuePtr(RARRAY_PTR(servers_aryv)[i]);
|
136
136
|
memcached_server_push(mc, memcached_servers_parse(server));
|
137
137
|
}
|
138
138
|
} else {
|
@@ -153,6 +153,12 @@ static VALUE mc_initialize(VALUE self, VALUE opts) {
|
|
153
153
|
return self;
|
154
154
|
}
|
155
155
|
|
156
|
+
#ifdef RUBY_19
|
157
|
+
#define RSTRING_SET_LEN(str, newlen) (rb_str_set_len(str, new_len))
|
158
|
+
#else
|
159
|
+
#define RSTRING_SET_LEN(str, newlen) (RSTRING(str)->len = new_len)
|
160
|
+
#endif
|
161
|
+
|
156
162
|
static VALUE escape_key(VALUE key, bool* escaped) {
|
157
163
|
char* str = RSTRING_PTR(key);
|
158
164
|
uint16_t len = RSTRING_LEN(key);
|
@@ -170,7 +176,7 @@ static VALUE escape_key(VALUE key, bool* escaped) {
|
|
170
176
|
} else {
|
171
177
|
if (escaped) *escaped = true;
|
172
178
|
key = rb_str_buf_new(new_len);
|
173
|
-
|
179
|
+
RSTRING_SET_LEN(key, new_len);
|
174
180
|
new_str = RSTRING_PTR(key);
|
175
181
|
|
176
182
|
for (i = 0, j = 0; i < len; i++, j++) {
|
@@ -209,7 +215,7 @@ static VALUE unescape_key(const char* str, uint16_t len) {
|
|
209
215
|
key = rb_str_new(str, len);
|
210
216
|
} else {
|
211
217
|
key = rb_str_buf_new(new_len);
|
212
|
-
|
218
|
+
RSTRING_SET_LEN(key, new_len);
|
213
219
|
new_str = RSTRING_PTR(key);
|
214
220
|
|
215
221
|
for (i = 0, j = 0; i < len; j++, i++) {
|
@@ -279,8 +285,8 @@ static VALUE mc_get(int argc, VALUE *argv, VALUE self) {
|
|
279
285
|
|
280
286
|
key_strings = (const char**) malloc(num_keys * sizeof(char *));
|
281
287
|
key_lengths = (size_t *) malloc(num_keys * sizeof(size_t));
|
282
|
-
for (i = 0; i <
|
283
|
-
key =
|
288
|
+
for (i = 0; i < RARRAY_LEN(keys); i++) {
|
289
|
+
key = RARRAY_PTR(keys)[i];
|
284
290
|
if (!use_binary(mc)) key = escape_key(key, &escaped);
|
285
291
|
|
286
292
|
key_lengths[i] = RSTRING_LEN(key);
|
data/lib/memcache.rb
CHANGED
@@ -240,9 +240,7 @@ class Memcache
|
|
240
240
|
|
241
241
|
def add_or_get(key, value, opts = {})
|
242
242
|
# Try to add, but if that fails, get the existing value.
|
243
|
-
add(key, value, opts)
|
244
|
-
rescue Memcache::Error
|
245
|
-
get(key)
|
243
|
+
add(key, value, opts) || get(key)
|
246
244
|
end
|
247
245
|
|
248
246
|
def get_some(keys, opts = {})
|
data/memcache.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{memcache}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Justin Balthrop"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-12}
|
13
13
|
s.description = %q{Ruby client for memcached supporting advanced protocol features and pluggable architecture.}
|
14
14
|
s.email = %q{code@justinbalthrop.com}
|
15
15
|
s.extensions = ["ext/extconf.rb"]
|
data/test/memcache_test.rb
CHANGED
@@ -112,6 +112,14 @@ class MemcacheTest < Test::Unit::TestCase
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
def test_add_or_get
|
116
|
+
100.times do |i|
|
117
|
+
assert_equal [i, :foo], m.add_or_get("FOO#{i}", [i, :foo])
|
118
|
+
assert_equal nil, m.add("FOO#{i}", [i, :bar])
|
119
|
+
assert_equal [i, :foo], m.add_or_get("FOO#{i}", [i, :baz])
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
115
123
|
def test_update
|
116
124
|
100.times do |i|
|
117
125
|
m.set("foo#{i}", [:foo, i])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memcache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Balthrop
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-04-
|
12
|
+
date: 2010-04-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|