xunch 0.0.10.2 → 0.0.10.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2745b0a105ccb0dfa6461af733d0a544719ce442
4
- data.tar.gz: da52e284ba4cc556b1f8addfbdccf0f5f2be21ff
3
+ metadata.gz: 7a823df55ee04eec6dd9cb198b9219d633228e58
4
+ data.tar.gz: 8ef44351fd2de4129f2060918fdef8754d31bb41
5
5
  SHA512:
6
- metadata.gz: 93c52651755a238ffb43edd2b6c3c8fab1ac0b6d5e857dcb3f58544d6689d104c2d7980c93ee88a7a34989cbcd20488d35d2532b929458ca61a37c77340f4d7f
7
- data.tar.gz: bde5eaabfb9b5c9bf7c92591fd74093dee2f7fcf99af9a6297b6ee48d0edfc9499a63a23a1f8a2d6e330a74281c63d1cc525a207babf838fe6907db89846e0aa
6
+ metadata.gz: 36e5ac51f6ca81bb02baece72e0bf7e6720723d843df6d7d0d748bf9bfcf12846f19a9053fe70a483d5a9cbae236cbb2f2917a4cf7e045dd8f633738451d7a6e
7
+ data.tar.gz: e05efd775ea4e6b4811b0e37f48197184812dcd098350a543c16279014d4643ea6203226cd3f7f455c8f6deaea354c18032cbd535e6540515dfb25db2dd1eaf7
@@ -1,16 +1,19 @@
1
+ require 'socket'
1
2
  module Xunch
2
3
  class Cache
3
4
 
4
5
  def initialize(options, shard_infos)
5
6
  @options = initialize_options(options)
6
7
  @shard_redis = ShardRedis.new(@options[:regex],shard_infos)
8
+ @host = Socket.gethostname
9
+ @pid = Process.pid
7
10
  end
8
11
 
9
12
  # 从缓存中删除指定的key
10
13
  def evict(key)
11
14
  @shard_redis.del(assembleKey(key))
12
15
  end
13
-
16
+
14
17
  # 从缓存中删除指定的一组key
15
18
  def batch_evict(keys)
16
19
  new_keys = []
@@ -30,7 +33,7 @@ module Xunch
30
33
  @shard_redis.destroy
31
34
  end
32
35
 
33
- protected
36
+ protected
34
37
  def getCacheObjectKey(value)
35
38
  key = value.send(@options[:key_field_name])
36
39
  raise ArgumentError("value #{value} key field can not be nil.") unless key != nil
@@ -44,7 +47,7 @@ module Xunch
44
47
 
45
48
  def assembleTempKey(key)
46
49
  name = @options[:name]
47
- name + "_".concat(key.to_s).concat("_").concat(@options[:version].to_s).concat("_temp")
50
+ name + "_".concat(key.to_s).concat("_").concat(@options[:version].to_s).concat("_temp").concat(@host).concat(@pid)
48
51
  end
49
52
 
50
53
  def initialize_options(options)
@@ -65,7 +68,7 @@ module Xunch
65
68
  version = 1
66
69
  if(options["version"] != nil)
67
70
  version = options["version"]
68
- use_options.store(:version, version)
71
+ use_options.store(:version, version)
69
72
  end
70
73
 
71
74
  if(options["name"] != nil)
@@ -26,6 +26,9 @@ module Xunch
26
26
  caches = {}
27
27
  lazy_caches = {}
28
28
  cache_configs.each_value { |cache_config|
29
+ if cache_config["type"] == nil
30
+ raise ArgumentError.new("cache type can't be nil.")
31
+ end
29
32
  shard_names = cache_config["shards"].split(",")
30
33
  driver = cache_config["driver"].downcase.to_sym if cache_config["driver"]
31
34
  shard_infos = []
@@ -37,6 +40,9 @@ module Xunch
37
40
  shard_options = {}
38
41
  if driver
39
42
  shard_options[:driver] = driver
43
+ if shard_options[:driver] == :synchrony and cache_config["type"].start_with?("list")
44
+ raise ArgumentError.new("list cache can't use synchrony driver.")
45
+ end
40
46
  end
41
47
  if cache_config["timeout"]
42
48
  shard_options[:timeout] = cache_config["timeout"]
@@ -20,9 +20,9 @@ module Xunch
20
20
  end
21
21
 
22
22
  def encode(value)
23
- unless value.class.name == @klass.name
24
- raise XunchCodecError.new("Codec error. Codec class is #{@klass}," <<
25
- "object_id is #{@klass.object_id}, but value class is #{value.class}," <<
23
+ unless value.class.name.start_with? @klass.name
24
+ raise XunchCodecError.new("Codec error. Codec class is #{@klass}," <<
25
+ "object_id is #{@klass.object_id}, but value class is #{value.class}," <<
26
26
  "object_id is #{value.class.object_id}.
27
27
  value class = #{value.class.inspect} vs config class = #{@klass.inspect} ")
28
28
  end
@@ -8,7 +8,7 @@ module Xunch
8
8
  end
9
9
 
10
10
  def encode(value)
11
- unless value.class.name == @klass.name
11
+ unless value.class.name.start_with? @klass.name
12
12
  raise XunchCodecError.new("Codec error. Codec class is #{@klass}," <<
13
13
  "object_id is #{@klass.object_id}, but value class is #{value.class}," <<
14
14
  "object_id is #{value.class.object_id}.
@@ -29,6 +29,24 @@ class CacheBuilderTest < Test::Unit::TestCase
29
29
  end
30
30
  }
31
31
  puts "CacheBuilderTest test_build_type stop."
32
+ require 'socket'
33
+ i = 0
34
+ start = Time.now
35
+ while i < 1000000 do
36
+ Socket.gethostname
37
+ i += 1
38
+ end
39
+ stop = Time.now
40
+ puts stop - start
41
+
42
+ i = 0
43
+ start = Time.now
44
+ while i < 1000000 do
45
+ Process.pid
46
+ i += 1
47
+ end
48
+ stop = Time.now
49
+ puts stop - start
32
50
  end
33
51
 
34
52
  def teardown
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xunch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10.2
4
+ version: 0.0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ted Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-06 00:00:00.000000000 Z
11
+ date: 2014-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -44,6 +44,7 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
+ - lib/xunch.rb
47
48
  - lib/xunch/cache/cache.rb
48
49
  - lib/xunch/cache/cache_builder.rb
49
50
  - lib/xunch/cache/field_object_cache.rb
@@ -56,18 +57,17 @@ files:
56
57
  - lib/xunch/codec/json_codec.rb
57
58
  - lib/xunch/connection/fiber_redis_pool.rb
58
59
  - lib/xunch/connection/threaded_redis_pool.rb
60
+ - lib/xunch/shard/ThreadedRedisPool.rb
59
61
  - lib/xunch/shard/redis.rb
60
62
  - lib/xunch/shard/shard_info.rb
61
63
  - lib/xunch/shard/shard_redis.rb
62
64
  - lib/xunch/shard/sharded.rb
63
- - lib/xunch/shard/ThreadedRedisPool.rb
64
65
  - lib/xunch/utils/exceptions.rb
65
66
  - lib/xunch/utils/nginx_cache_helper.rb
66
67
  - lib/xunch/utils/rb_tree.rb
67
68
  - lib/xunch/utils/rb_tree_node.rb
68
69
  - lib/xunch/utils/types.rb
69
70
  - lib/xunch/utils/utils.rb
70
- - lib/xunch.rb
71
71
  - test/cache_builder_test.rb
72
72
  - test/cache_test.rb
73
73
  - test/em_cache_test.rb
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.0.3
106
+ rubygems_version: 2.2.2
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: A distribute cache client library based on redis.