memcached-seanl 0.19.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/BENCHMARKS +120 -0
- data/CHANGELOG +77 -0
- data/LICENSE +184 -0
- data/Manifest +31 -0
- data/README +111 -0
- data/Rakefile +31 -0
- data/TODO +4 -0
- data/ext/extconf.rb +89 -0
- data/ext/libmemcached-0.32.tar.gz +0 -0
- data/ext/libmemcached.patch +270 -0
- data/ext/rlibmemcached.i +230 -0
- data/ext/rlibmemcached_wrap.c +13290 -0
- data/ext/sasl.patch +29283 -0
- data/lib/memcached/auth.rb +16 -0
- data/lib/memcached/behaviors.rb +78 -0
- data/lib/memcached/exceptions.rb +84 -0
- data/lib/memcached/integer.rb +6 -0
- data/lib/memcached/memcached.rb +649 -0
- data/lib/memcached/rails.rb +116 -0
- data/lib/memcached.rb +32 -0
- data/memcached-seanl.gemspec +32 -0
- data/memcached.gemspec +32 -0
- data/test/profile/benchmark.rb +210 -0
- data/test/profile/profile.rb +14 -0
- data/test/profile/valgrind.rb +147 -0
- data/test/setup.rb +29 -0
- data/test/teardown.rb +0 -0
- data/test/test_helper.rb +18 -0
- data/test/unit/binding_test.rb +8 -0
- data/test/unit/memcached_test.rb +1168 -0
- data/test/unit/rails_test.rb +109 -0
- metadata +117 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
class Memcached
|
2
|
+
def destroy_credentials
|
3
|
+
if options[:credentials] != nil
|
4
|
+
check_return_code(Lib.memcached_destroy_sasl_auth_data(@struct))
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def set_credentials
|
9
|
+
# If credentials aren't provided, try to get them from the environment
|
10
|
+
if options[:credentials] != nil
|
11
|
+
username, password = options[:credentials]
|
12
|
+
check_return_code(Lib.memcached_set_sasl_auth_data(@struct, username, password))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
|
2
|
+
class Memcached
|
3
|
+
|
4
|
+
#:stopdoc:
|
5
|
+
|
6
|
+
def self.load_constants(prefix, hash = {})
|
7
|
+
Lib.constants.grep(/^#{prefix}/).each do |const_name|
|
8
|
+
hash[const_name[prefix.length..-1].downcase.to_sym] = Lib.const_get(const_name)
|
9
|
+
end
|
10
|
+
hash
|
11
|
+
end
|
12
|
+
|
13
|
+
BEHAVIORS = load_constants("MEMCACHED_BEHAVIOR_")
|
14
|
+
|
15
|
+
BEHAVIOR_VALUES = {
|
16
|
+
false => 0,
|
17
|
+
true => 1
|
18
|
+
}
|
19
|
+
|
20
|
+
HASH_VALUES = {}
|
21
|
+
BEHAVIOR_VALUES.merge!(load_constants("MEMCACHED_HASH_", HASH_VALUES))
|
22
|
+
|
23
|
+
DISTRIBUTION_VALUES = {}
|
24
|
+
BEHAVIOR_VALUES.merge!(load_constants("MEMCACHED_DISTRIBUTION_", DISTRIBUTION_VALUES))
|
25
|
+
|
26
|
+
DIRECT_VALUE_BEHAVIORS = [:retry_timeout, :connect_timeout, :rcv_timeout, :socket_recv_size, :poll_timeout, :socket_send_size, :server_failure_limit]
|
27
|
+
|
28
|
+
CONVERSION_FACTORS = {
|
29
|
+
:rcv_timeout => 1_000_000,
|
30
|
+
:poll_timeout => 1_000,
|
31
|
+
:connect_timeout => 1_000
|
32
|
+
}
|
33
|
+
|
34
|
+
#:startdoc:
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# Set a behavior option for this Memcached instance. Accepts a Symbol <tt>behavior</tt> and either <tt>true</tt>, <tt>false</tt>, or a Symbol for <tt>value</tt>. Arguments are validated and converted into integers for the struct setter method.
|
39
|
+
def set_behavior(behavior, value) #:doc:
|
40
|
+
raise ArgumentError, "No behavior #{behavior.inspect}" unless b_id = BEHAVIORS[behavior]
|
41
|
+
|
42
|
+
# Scoped validations; annoying
|
43
|
+
msg = "Invalid behavior value #{value.inspect} for #{behavior.inspect}"
|
44
|
+
case behavior
|
45
|
+
when :hash then raise(ArgumentError, msg) unless HASH_VALUES[value]
|
46
|
+
when :distribution then raise(ArgumentError, msg) unless DISTRIBUTION_VALUES[value]
|
47
|
+
when *DIRECT_VALUE_BEHAVIORS then raise(ArgumentError, msg) unless value.is_a?(Numeric) and value >= 0
|
48
|
+
else
|
49
|
+
raise(ArgumentError, msg) unless BEHAVIOR_VALUES[value]
|
50
|
+
end
|
51
|
+
|
52
|
+
lib_value = BEHAVIOR_VALUES[value] || (value * (CONVERSION_FACTORS[behavior] || 1)).to_i
|
53
|
+
#STDERR.puts "Setting #{behavior}:#{b_id} => #{value} (#{lib_value})"
|
54
|
+
Lib.memcached_behavior_set(@struct, b_id, lib_value)
|
55
|
+
#STDERR.puts " -> set to #{get_behavior(behavior).inspect}"
|
56
|
+
end
|
57
|
+
|
58
|
+
# Get a behavior value for this Memcached instance. Accepts a Symbol.
|
59
|
+
def get_behavior(behavior)
|
60
|
+
raise ArgumentError, "No behavior #{behavior.inspect}" unless b_id = BEHAVIORS[behavior]
|
61
|
+
value = Lib.memcached_behavior_get(@struct, b_id)
|
62
|
+
|
63
|
+
if BEHAVIOR_VALUES.invert.has_key?(value)
|
64
|
+
# False, nil are valid values so we can not rely on direct lookups
|
65
|
+
case behavior
|
66
|
+
# Scoped values; still annoying
|
67
|
+
when :hash then HASH_VALUES.invert[value]
|
68
|
+
when :distribution then DISTRIBUTION_VALUES.invert[value]
|
69
|
+
when *DIRECT_VALUE_BEHAVIORS then value
|
70
|
+
else
|
71
|
+
BEHAVIOR_VALUES.invert[value]
|
72
|
+
end
|
73
|
+
else
|
74
|
+
value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
|
2
|
+
class Memcached
|
3
|
+
|
4
|
+
=begin rdoc
|
5
|
+
|
6
|
+
Superclass for all Memcached runtime exceptions.
|
7
|
+
|
8
|
+
Subclasses correspond one-to-one with server response strings or libmemcached errors. For example, raising <b>Memcached::NotFound</b> means that the server returned <tt>"NOT_FOUND\r\n"</tt>.
|
9
|
+
|
10
|
+
== Subclasses
|
11
|
+
|
12
|
+
* Memcached::ABadKeyWasProvidedOrCharactersOutOfRange
|
13
|
+
* Memcached::AKeyLengthOfZeroWasProvided
|
14
|
+
* Memcached::ATimeoutOccurred
|
15
|
+
* Memcached::ActionNotSupported
|
16
|
+
* Memcached::ActionQueued
|
17
|
+
* Memcached::ClientError
|
18
|
+
* Memcached::ConnectionBindFailure
|
19
|
+
* Memcached::ConnectionDataDoesNotExist
|
20
|
+
* Memcached::ConnectionDataExists
|
21
|
+
* Memcached::ConnectionFailure
|
22
|
+
* Memcached::ConnectionSocketCreateFailure
|
23
|
+
* Memcached::CouldNotOpenUnixSocket
|
24
|
+
* Memcached::EncounteredAnUnknownStatKey
|
25
|
+
* Memcached::Failure
|
26
|
+
* Memcached::FetchWasNotCompleted
|
27
|
+
* Memcached::HostnameLookupFailure
|
28
|
+
* Memcached::ItemValue
|
29
|
+
* Memcached::MemoryAllocationFailure
|
30
|
+
* Memcached::NoServersDefined
|
31
|
+
* Memcached::NotFound
|
32
|
+
* Memcached::NotStored
|
33
|
+
* Memcached::PartialRead
|
34
|
+
* Memcached::ProtocolError
|
35
|
+
* Memcached::ReadFailure
|
36
|
+
* Memcached::ServerDelete
|
37
|
+
* Memcached::ServerEnd
|
38
|
+
* Memcached::ServerError
|
39
|
+
* Memcached::ServerIsMarkedDead
|
40
|
+
* Memcached::ServerValue
|
41
|
+
* Memcached::SomeErrorsWereReported
|
42
|
+
* Memcached::StatValue
|
43
|
+
* Memcached::SystemError
|
44
|
+
* Memcached::TheHostTransportProtocolDoesNotMatchThatOfTheClient
|
45
|
+
* Memcached::UnknownReadFailure
|
46
|
+
* Memcached::WriteFailure
|
47
|
+
|
48
|
+
=end
|
49
|
+
class Error < RuntimeError
|
50
|
+
attr_accessor :no_backtrace
|
51
|
+
|
52
|
+
def set_backtrace(*args)
|
53
|
+
@no_backtrace ? [] : super
|
54
|
+
end
|
55
|
+
|
56
|
+
def backtrace(*args)
|
57
|
+
@no_backtrace ? [] : super
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
#:stopdoc:
|
62
|
+
|
63
|
+
class << self
|
64
|
+
private
|
65
|
+
def camelize(string)
|
66
|
+
string.downcase.gsub('/', ' or ').split(' ').map {|s| s.capitalize}.join
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
ERRNO_HASH = Hash[*Errno.constants.map{ |c| [Errno.const_get(c)::Errno, Errno.const_get(c).new.message] }.flatten]
|
71
|
+
|
72
|
+
EXCEPTIONS = []
|
73
|
+
EMPTY_STRUCT = Rlibmemcached::MemcachedSt.new
|
74
|
+
Rlibmemcached.memcached_create(EMPTY_STRUCT)
|
75
|
+
|
76
|
+
# Generate exception classes
|
77
|
+
Rlibmemcached::MEMCACHED_MAXIMUM_RETURN.times do |index|
|
78
|
+
description = Rlibmemcached.memcached_strerror(EMPTY_STRUCT, index).gsub("!", "")
|
79
|
+
exception_class = eval("class #{camelize(description)} < Error; self; end")
|
80
|
+
EXCEPTIONS << exception_class
|
81
|
+
end
|
82
|
+
|
83
|
+
#:startdoc:
|
84
|
+
end
|