familia 0.10.2 → 1.0.0.pre.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.pre-commit-config.yaml +1 -1
- data/.rubocop.yml +75 -0
- data/.rubocop_todo.yml +63 -0
- data/Gemfile +6 -1
- data/Gemfile.lock +47 -15
- data/README.md +65 -13
- data/VERSION.yml +4 -3
- data/familia.gemspec +18 -13
- data/lib/familia/base.rb +33 -0
- data/lib/familia/connection.rb +87 -0
- data/lib/familia/core_ext.rb +119 -124
- data/lib/familia/errors.rb +33 -0
- data/lib/familia/features/api_version.rb +19 -0
- data/lib/familia/features/atomic_saves.rb +8 -0
- data/lib/familia/features/quantizer.rb +35 -0
- data/lib/familia/features/safe_dump.rb +194 -0
- data/lib/familia/features.rb +51 -0
- data/lib/familia/horreum/class_methods.rb +292 -0
- data/lib/familia/horreum/commands.rb +106 -0
- data/lib/familia/horreum/relations_management.rb +141 -0
- data/lib/familia/horreum/serialization.rb +193 -0
- data/lib/familia/horreum/settings.rb +63 -0
- data/lib/familia/horreum/utils.rb +44 -0
- data/lib/familia/horreum.rb +248 -0
- data/lib/familia/logging.rb +232 -0
- data/lib/familia/redistype/commands.rb +56 -0
- data/lib/familia/redistype/serialization.rb +110 -0
- data/lib/familia/redistype.rb +185 -0
- data/lib/familia/refinements.rb +88 -0
- data/lib/familia/settings.rb +38 -0
- data/lib/familia/types/hashkey.rb +107 -0
- data/lib/familia/types/list.rb +155 -0
- data/lib/familia/types/sorted_set.rb +234 -0
- data/lib/familia/types/string.rb +115 -0
- data/lib/familia/types/unsorted_set.rb +123 -0
- data/lib/familia/utils.rb +125 -0
- data/lib/familia/version.rb +25 -0
- data/lib/familia.rb +57 -161
- data/lib/redis_middleware.rb +109 -0
- data/try/00_familia_try.rb +5 -4
- data/try/10_familia_try.rb +21 -17
- data/try/20_redis_type_try.rb +67 -0
- data/try/{21_redis_object_zset_try.rb → 21_redis_type_zset_try.rb} +2 -2
- data/try/{22_redis_object_set_try.rb → 22_redis_type_set_try.rb} +2 -2
- data/try/{23_redis_object_list_try.rb → 23_redis_type_list_try.rb} +2 -2
- data/try/{24_redis_object_string_try.rb → 24_redis_type_string_try.rb} +6 -6
- data/try/{25_redis_object_hash_try.rb → 25_redis_type_hash_try.rb} +3 -3
- data/try/26_redis_bool_try.rb +10 -6
- data/try/27_redis_horreum_try.rb +93 -0
- data/try/30_familia_object_try.rb +21 -20
- data/try/35_feature_safedump_try.rb +83 -0
- data/try/40_customer_try.rb +140 -0
- data/try/41_customer_safedump_try.rb +86 -0
- data/try/test_helpers.rb +194 -0
- metadata +51 -47
- data/lib/familia/helpers.rb +0 -70
- data/lib/familia/object.rb +0 -533
- data/lib/familia/redisobject.rb +0 -1017
- data/lib/familia/test_helpers.rb +0 -40
- data/lib/familia/tools.rb +0 -67
- data/try/20_redis_object_try.rb +0 -44
data/lib/familia/test_helpers.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'storable'
|
2
|
-
|
3
|
-
class Bone < Storable
|
4
|
-
include Familia
|
5
|
-
index [:token, :name]
|
6
|
-
field :token
|
7
|
-
field :name
|
8
|
-
list :owners
|
9
|
-
set :tags
|
10
|
-
zset :metrics
|
11
|
-
hash :props
|
12
|
-
string :value, :default => "GREAT!"
|
13
|
-
end
|
14
|
-
|
15
|
-
class Session < Storable
|
16
|
-
include Familia
|
17
|
-
index :sessid
|
18
|
-
field :sessid
|
19
|
-
field :custid
|
20
|
-
include Familia::Stamps
|
21
|
-
ttl 60 # seconds to live
|
22
|
-
end
|
23
|
-
|
24
|
-
class Customer < Storable
|
25
|
-
include Familia
|
26
|
-
index :custid
|
27
|
-
field :custid => Symbol
|
28
|
-
field :name
|
29
|
-
include Familia::Stamps
|
30
|
-
# string :object, :class => self # example of manual override
|
31
|
-
class_list :customers, :suffix => []
|
32
|
-
class_string :message
|
33
|
-
end
|
34
|
-
|
35
|
-
class Limiter < Storable
|
36
|
-
include Familia
|
37
|
-
index :name
|
38
|
-
field :name
|
39
|
-
string :counter, :ttl => 1.hour, :quantize => [10.minutes, '%H:%M', 1302468980]
|
40
|
-
end
|
data/lib/familia/tools.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
|
2
|
-
module Familia
|
3
|
-
module Tools
|
4
|
-
extend self
|
5
|
-
def move_keys(filter, source_uri, target_uri, &each_key)
|
6
|
-
if target_uri == source_uri
|
7
|
-
raise "Source and target are the same (#{target_uri})"
|
8
|
-
end
|
9
|
-
Familia.connect target_uri
|
10
|
-
source_keys = Familia.redis(source_uri).keys(filter)
|
11
|
-
puts "Moving #{source_keys.size} keys from #{source_uri} to #{target_uri} (filter: #{filter})"
|
12
|
-
source_keys.each_with_index do |key,idx|
|
13
|
-
type = Familia.redis(source_uri).type key
|
14
|
-
ttl = Familia.redis(source_uri).ttl key
|
15
|
-
if source_uri.host == target_uri.host && source_uri.port == target_uri.port
|
16
|
-
Familia.redis(source_uri).move key, target_uri.db
|
17
|
-
else
|
18
|
-
case type
|
19
|
-
when "string"
|
20
|
-
value = Familia.redis(source_uri).get key
|
21
|
-
when "list"
|
22
|
-
value = Familia.redis(source_uri).lrange key, 0, -1
|
23
|
-
when "set"
|
24
|
-
value = Familia.redis(source_uri).smembers key
|
25
|
-
else
|
26
|
-
raise Familia::Problem, "unknown key type: #{type}"
|
27
|
-
end
|
28
|
-
raise "Not implemented"
|
29
|
-
end
|
30
|
-
each_key.call(idx, type, key, ttl) unless each_key.nil?
|
31
|
-
end
|
32
|
-
end
|
33
|
-
# Use the return value from each_key as the new key name
|
34
|
-
def rename(filter, source_uri, target_uri=nil, &each_key)
|
35
|
-
target_uri ||= source_uri
|
36
|
-
move_keys filter, source_uri, target_uri if source_uri != target_uri
|
37
|
-
source_keys = Familia.redis(source_uri).keys(filter)
|
38
|
-
puts "Renaming #{source_keys.size} keys from #{source_uri} (filter: #{filter})"
|
39
|
-
source_keys.each_with_index do |key,idx|
|
40
|
-
Familia.trace :RENAME1, Familia.redis(source_uri), "#{key}", ''
|
41
|
-
type = Familia.redis(source_uri).type key
|
42
|
-
ttl = Familia.redis(source_uri).ttl key
|
43
|
-
newkey = each_key.call(idx, type, key, ttl) unless each_key.nil?
|
44
|
-
Familia.trace :RENAME2, Familia.redis(source_uri), "#{key} -> #{newkey}", caller[0]
|
45
|
-
ret = Familia.redis(source_uri).renamenx key, newkey
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def get_any keyname, uri=nil
|
50
|
-
type = Familia.redis(uri).type keyname
|
51
|
-
case type
|
52
|
-
when "string"
|
53
|
-
Familia.redis(uri).get keyname
|
54
|
-
when "list"
|
55
|
-
Familia.redis(uri).lrange(keyname, 0, -1) || []
|
56
|
-
when "set"
|
57
|
-
Familia.redis(uri).smembers( keyname) || []
|
58
|
-
when "zset"
|
59
|
-
Familia.redis(uri).zrange(keyname, 0, -1) || []
|
60
|
-
when "hash"
|
61
|
-
Familia.redis(uri).hgetall(keyname) || {}
|
62
|
-
else
|
63
|
-
nil
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/try/20_redis_object_try.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'familia'
|
3
|
-
require 'familia/test_helpers'
|
4
|
-
Familia.apiversion = 'v1'
|
5
|
-
|
6
|
-
|
7
|
-
## Redis Objects are unique per instance of a Familia class
|
8
|
-
@a = Bone.new 'atoken', :name1
|
9
|
-
@b = Bone.new 'atoken', :name2
|
10
|
-
@a.owners.rediskey.eql?(@b.owners.rediskey)
|
11
|
-
#=> false
|
12
|
-
|
13
|
-
## Redis Objects are frozen
|
14
|
-
@a.owners.frozen?
|
15
|
-
#=> true
|
16
|
-
|
17
|
-
## Limiter#qstamp
|
18
|
-
@limiter = Limiter.new :requests
|
19
|
-
@limiter.counter.qstamp 10.minutes, '%H:%M', 1302468980
|
20
|
-
#=> '20:50'
|
21
|
-
|
22
|
-
## Redis Objects can be stored to quantized keys
|
23
|
-
@limiter.counter.rediskey
|
24
|
-
#=> "v1:limiter:requests:counter:20:50"
|
25
|
-
|
26
|
-
## Increment counter
|
27
|
-
@limiter.counter.clear
|
28
|
-
@limiter.counter.increment
|
29
|
-
#=> 1
|
30
|
-
|
31
|
-
## Check ttl
|
32
|
-
@limiter.counter.ttl
|
33
|
-
#=> 3600.0
|
34
|
-
|
35
|
-
## Check ttl for a different instance
|
36
|
-
## (this exists to make sure options are cloned for each instance)
|
37
|
-
@limiter2 = Limiter.new :requests
|
38
|
-
@limiter2.counter.ttl
|
39
|
-
#=> 3600.0
|
40
|
-
|
41
|
-
## Check realttl
|
42
|
-
sleep 1
|
43
|
-
@limiter.counter.realttl
|
44
|
-
#=> 3600-1
|