zeevex_cluster 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -11,6 +11,7 @@ group :development, :test do
11
11
  gem 'jist'
12
12
  gem 'ruby18_source_location', :platform => :mri_18
13
13
  gem 'mysql2', :platform => :mri
14
+ gem 'dalli'
14
15
  end
15
16
 
16
17
  group :development, :test do
@@ -0,0 +1,103 @@
1
+ require 'zeevex_cluster/coordinator/base_key_val_store'
2
+
3
+ module ZeevexCluster::Coordinator
4
+ class Dalli < BaseKeyValStore
5
+ def self.setup
6
+ unless @setup
7
+ require 'dalli'
8
+ BaseKeyValStore.setup
9
+
10
+ @setup = true
11
+ end
12
+ end
13
+
14
+ def initialize(options = {})
15
+ super
16
+ @client ||= ::Dalli::Client.new "#@server:#@port"
17
+ end
18
+
19
+ def add(key, value, options = {})
20
+ @client.add(to_key(key), serialize_value(value, options[:raw]),
21
+ options.fetch(:expiration, @expiration), raw: raw?)
22
+ rescue ::Dalli::DalliError
23
+ raise ZeevexCluster::Coordinator::ConnectionError.new 'Connection error', $!
24
+ end
25
+
26
+ def set(key, value, options = {})
27
+ @client.set(to_key(key), serialize_value(value, options[:raw]),
28
+ options.fetch(:expiration, @expiration), raw: raw?)
29
+ rescue ::Dalli::DalliError
30
+ raise ZeevexCluster::Coordinator::ConnectionError.new 'Connection error', $!
31
+ end
32
+
33
+ def delete(key, options = {})
34
+ @client.delete(to_key(key))
35
+ end
36
+
37
+ #
38
+ # Block is passed the current value, and returns the updated value.
39
+ #
40
+ # Block can raise DontChange to simply exit the block without updating.
41
+ #
42
+ # returns nil for no value
43
+ # returns false for failure (somebody else set)
44
+ # returns true for success
45
+ #
46
+ def cas(key, options = {}, &block)
47
+ res = @client.cas(to_key(key), options.fetch(:expiration, @expiration), raw: raw?) do |inval|
48
+ serialize_value(yield(deserialize_value(inval, options[:raw])), options[:raw])
49
+ end
50
+ case res
51
+ when nil then nil
52
+ when false then false
53
+ when true then true
54
+ else raise "Unhandled status code: #{res}"
55
+ end
56
+ rescue ZeevexCluster::Coordinator::DontChange
57
+ false
58
+ rescue ::Dalli::DalliError
59
+ raise ZeevexCluster::Coordinator::ConnectionError.new 'Connection error', $!
60
+ end
61
+
62
+ def get(key, options = {})
63
+ val = @client.get(to_key(key), raw: raw?)
64
+ if val && !options[:raw]
65
+ deserialize_value(val)
66
+ else
67
+ val
68
+ end
69
+ rescue ::Dalli::DalliError
70
+ raise ZeevexCluster::Coordinator::ConnectionError.new 'Connection error', $!
71
+ end
72
+
73
+ def append(key, val, options = {})
74
+ val = serialize_value(val, options[:raw])
75
+ key = to_key(key)
76
+ @client.append(key, val) ||
77
+ @client.add(key, val, options.fetch(:expiration, @expiration), raw: true) ||
78
+ @client.append(key, val)
79
+ rescue ::Dalli::DalliError
80
+ raise ZeevexCluster::Coordinator::ConnectionError.new 'Connection error', $!
81
+ end
82
+
83
+ def prepend(key, val, options = {})
84
+ val = serialize_value(val, options[:raw])
85
+ key = to_key(key)
86
+ @client.prepend(key, val) ||
87
+ @client.add(key, val, options.fetch(:expiration, @expiration), raw: true) ||
88
+ @client.prepend(key, val)
89
+ rescue ::Dalli::DalliError
90
+ raise ZeevexCluster::Coordinator::ConnectionError.new 'Connection error', $!
91
+ end
92
+
93
+ def push_to_queue(key, object, options = {})
94
+
95
+ end
96
+
97
+ protected
98
+
99
+ def raw?
100
+ true
101
+ end
102
+ end
103
+ end
@@ -22,6 +22,7 @@ module ZeevexCluster
22
22
  require 'zeevex_cluster/coordinator/' + coordinator_type
23
23
  clazz = self.const_get(coordinator_type.capitalize)
24
24
  raise ArgumentError, "Unknown coordinator type: #{coordinator_type}" unless clazz
25
+ clazz.setup if clazz.respond_to?(:setup)
25
26
  ZeevexCluster.Synchronized(clazz.new(options))
26
27
  end
27
28
  end
@@ -1,3 +1,3 @@
1
1
  module ZeevexCluster
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/script/election.rb CHANGED
@@ -9,6 +9,8 @@ strategy_type = 'cas'
9
9
 
10
10
  backend_options = case ctype
11
11
  when 'memcached' then {:server => '127.0.0.1', :port => 11212}
12
+ when 'dalli' then {:server => '127.0.0.1', :port => 11211}
13
+
12
14
  when 'redis' then {:server => '127.0.0.1', :port => 6379}
13
15
  when 'mysql' then {:server => '127.0.0.1', :port => 3306,
14
16
  :coordinator_options => {
data/script/repl CHANGED
@@ -2,9 +2,9 @@
2
2
  $: << File.join(File.dirname(__FILE__), "../lib")
3
3
  require 'pry'
4
4
  require 'zeevex_cluster'
5
- require 'zeevex_cluster/util/delayed'
6
- require 'zeevex_cluster/util/future'
7
- require 'zeevex_cluster/util/promise'
8
- require 'zeevex_cluster/util/delay'
5
+ #require 'zeevex_cluster/util/delayed'
6
+ #require 'zeevex_cluster/util/future'
7
+ #require 'zeevex_cluster/util/promise'
8
+ #require 'zeevex_cluster/util/delay'
9
9
 
10
10
  binding.pry
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeevex_cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -221,6 +221,7 @@ files:
221
221
  - lib/zeevex_cluster/base.rb
222
222
  - lib/zeevex_cluster/coordinator.rb
223
223
  - lib/zeevex_cluster/coordinator/base_key_val_store.rb
224
+ - lib/zeevex_cluster/coordinator/dalli.rb
224
225
  - lib/zeevex_cluster/coordinator/memcached.rb
225
226
  - lib/zeevex_cluster/coordinator/mysql.rb
226
227
  - lib/zeevex_cluster/coordinator/redis.rb