hiera-redis 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.
Files changed (2) hide show
  1. data/lib/hiera/backend/redis_backend.rb +28 -19
  2. metadata +4 -4
@@ -2,7 +2,7 @@ class Hiera
2
2
  module Backend
3
3
  class Redis_backend
4
4
 
5
- VERSION="0.2.1"
5
+ VERSION="0.2.2"
6
6
 
7
7
  attr_reader :redis
8
8
 
@@ -16,10 +16,13 @@ class Hiera
16
16
 
17
17
  # config overrides default values
18
18
  options.each_key do |k|
19
- options[k] = Config[:redis][k] if Config[:redis].has_key?(k)
19
+ options[k] = Config[:redis][k] if Config[:redis].is_a?(Hash) && Config[:redis].has_key?(k)
20
20
  end
21
21
 
22
22
  @redis = Redis.new(options)
23
+
24
+ @soft_connection_failure = false # Thus we are preventing the current behaviour
25
+ @soft_connection_failure = Config[:redis][:soft_connection_failure] if Config[:redis].is_a?(Hash) && Config[:redis].has_key?(:soft_connection_failure)
23
26
  end
24
27
 
25
28
  def redis_query(args = {})
@@ -27,25 +30,31 @@ class Hiera
27
30
  # convert our seperator in order to maintain yaml compatibility
28
31
  redis_key = args[:source].gsub('/', ':')
29
32
 
30
- if redis.type(redis_key) == "hash"
31
- redis.hget(redis_key, args[:key])
32
- else
33
- redis_key << ":#{args[:key]}"
34
- case redis.type(redis_key)
35
- when "set"
36
- redis.smembers(redis_key)
37
- when "hash"
38
- redis.hgetall(redis_key)
39
- when "list"
40
- redis.lrange(redis_key, 0, -1)
41
- when "string"
42
- redis.get(redis_key)
43
- when "zset"
44
- redis.zrange(redis_key, 0, -1)
33
+ begin
34
+ if redis.type(redis_key) == "hash"
35
+ redis.hget(redis_key, args[:key])
45
36
  else
46
- Hiera.debug("No such key: #{redis_key}")
47
- nil
37
+ redis_key << ":#{args[:key]}"
38
+ case redis.type(redis_key)
39
+ when "set"
40
+ redis.smembers(redis_key)
41
+ when "hash"
42
+ redis.hgetall(redis_key)
43
+ when "list"
44
+ redis.lrange(redis_key, 0, -1)
45
+ when "string"
46
+ redis.get(redis_key)
47
+ when "zset"
48
+ redis.zrange(redis_key, 0, -1)
49
+ else
50
+ Hiera.debug("No such key: #{redis_key}")
51
+ nil
52
+ end
48
53
  end
54
+ rescue Redis::CannotConnectError => e
55
+ raise e unless @soft_connection_failure
56
+ Hiera.warn("Cannot connect to Redis server")
57
+ nil
49
58
  end
50
59
  end
51
60
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera-redis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Kosmin c/o Reliant Security, Inc.
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-30 00:00:00 Z
18
+ date: 2012-07-23 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Allows hiera functions to pull data from a Redis database.