nest 1.1.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 610bc2190ba05babfba5f60c066cc5490275ec84
4
+ data.tar.gz: ab916a8881519a70bb419e6123a110e1ac5b2b8d
5
+ SHA512:
6
+ metadata.gz: 082e573734a5b6ea7fb562d53738140bd0508fbe3b7dba6f5608f545e220b70bf8aff329019982f5e6592cda997f4846ff2734cea11e89b6ad122e459c88f518
7
+ data.tar.gz: e3cc7a3c657c56c0de9255b045fc932498d753906aa68faac7fc6e789aeb7b8cb5de24c94d16989dd525b48ddb2cce075730038ba497a4f7ee63e97e976fbffe
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Michel Martens & Damian Janowski
1
+ Copyright (c) 2010-2015 Michel Martens & Damian Janowski
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -6,104 +6,117 @@ Object Oriented Keys for Redis.
6
6
  Description
7
7
  -----------
8
8
 
9
- If you are familiar with databases like [Redis](http://code.google.com/p/redis)
9
+ If you are familiar with databases like [Redis](http://redis.io)
10
10
  and libraries like [Ohm](http://ohm.keyvalue.org) you already know how
11
11
  important it is to craft the keys that will hold the data.
12
12
 
13
- >> redis = Redis.new
14
- >> redis.sadd("event:3:attendees", "Albert")
15
- >> redis.smembers("event:3:attendees")
16
- => ["Albert"]
13
+ ```ruby
14
+ >> redis = Redic.new
15
+ >> redis.call("SADD", "event:3:attendees", "Albert")
16
+ >> redis.call("SMEMBERS", "event:3:attendees")
17
+ => ["Albert"]
18
+ ```
17
19
 
18
20
  It is a design pattern in key-value databases to use the key to simulate
19
21
  structure, and you can read more about this in the [case study for a
20
- Twitter clone](http://code.google.com/p/redis/wiki/TwitterAlikeExample).
22
+ Twitter clone](http://redis.io/topics/twitter-clone).
21
23
 
22
24
  Nest helps you generate those keys by providing chainable namespaces that are
23
25
  already connected to Redis:
24
26
 
25
- >> event = Nest.new("event")
26
- >> event[3][:attendees].sadd("Albert")
27
- >> event[3][:attendees].smembers
28
- => ["Albert"]
27
+ ```ruby
28
+ >> event = Nest.new("event")
29
+ >> event[3][:attendees].sadd("Albert")
30
+ >> event[3][:attendees].smembers
31
+ => ["Albert"]
32
+ ```
29
33
 
30
34
  Usage
31
35
  -----
32
36
 
33
37
  To create a new namespace:
34
38
 
35
- >> ns = Nest.new("foo")
36
- => "foo"
39
+ ```ruby
40
+ >> ns = Nest.new("foo")
41
+ => "foo"
37
42
 
38
- >> ns["bar"]
39
- => "foo:bar"
43
+ >> ns["bar"]
44
+ => "foo:bar"
40
45
 
41
- >> ns["bar"]["baz"]["qux"]
42
- => "foo:bar:baz:qux"
46
+ >> ns["bar"]["baz"]["qux"]
47
+ => "foo:bar:baz:qux"
48
+ ```
43
49
 
44
50
  And you can use any object as a key, not only strings:
45
51
 
46
- >> ns[:bar][42]
47
- => "foo:bar:42"
52
+ ```ruby
53
+ >> ns[:bar][42]
54
+ => "foo:bar:42"
55
+ ```
48
56
 
49
57
  In a more realistic tone, lets assume you are working with Redis and
50
58
  dealing with events:
51
59
 
52
- >> events = Nest.new("events")
53
- => "events"
60
+ ```ruby
61
+ >> events = Nest.new("events")
62
+ => "events"
54
63
 
55
- >> id = events[:id].incr
56
- => 1
64
+ >> id = events[:id].incr
65
+ => 1
57
66
 
58
- >> events[id][:attendees].sadd("Albert")
59
- => "OK"
67
+ >> events[id][:attendees].sadd("Albert")
68
+ => "OK"
60
69
 
61
- >> meetup = events[id]
62
- => "events:1"
70
+ >> meetup = events[id]
71
+ => "events:1"
63
72
 
64
- >> meetup[:attendees].smembers
65
- => ["Albert"]
73
+ >> meetup[:attendees].smembers
74
+ => ["Albert"]
75
+ ```
66
76
 
67
77
  Supplying your existing Redis instance
68
78
  --------------------------------------
69
79
 
70
- You can supply a `Redis` instance as a second parameter. If you don't, a default
71
- instance is created for you:
80
+ You can supply a [Redic](https://github.com/amakawa/redic) instance as
81
+ a second parameter. If you don't, a default instance is created for you:
72
82
 
73
- >> redis = Redis.new
74
- => #<Redis::Client...>
83
+ ```ruby
84
+ >> redis = Redic.new("redis://localhost:6379")
85
+ => #<Redic:0x007fa640845f10 ...>
75
86
 
76
- >> users = Nest.new("users", redis)
77
- => "users"
87
+ >> users = Nest.new("users", redis)
88
+ => "users"
78
89
 
79
- >> id = users[:id].incr
80
- => 1
90
+ >> id = users[:id].incr
91
+ => 1
81
92
 
82
- >> users[id].hset(:name, "Albert")
83
- => "OK"
93
+ >> users[id].hset(:name, "Albert")
94
+ => "OK"
95
+ ```
84
96
 
85
- `Nest` objects respond to `redis` and return a `Redis` instance. It is
97
+ `Nest` objects respond to `redis` and return a `Redic` instance. It is
86
98
  automatically reused when you create a new namespace, and you can reuse it when
87
99
  creating a new instance of Nest:
88
100
 
89
- >> events = Nest.new("events", meetup.redis)
90
- => "events"
101
+ ```ruby
102
+ >> events = Nest.new("events", meetup.redis)
103
+ => "events"
91
104
 
92
- >> events.sadd(meetup)
93
- => true
105
+ >> events.sadd(meetup)
106
+ => true
94
107
 
95
- >> events.sismember(meetup)
96
- => true
108
+ >> events.sismember(meetup)
109
+ => true
97
110
 
98
- >> events.smembers
99
- => ["events:1"]
111
+ >> events.smembers
112
+ => ["events:1"]
100
113
 
101
- >> events.del
102
- >> true
114
+ >> events.del
115
+ >> true
116
+ ```
103
117
 
104
118
  Nest allows you to execute all the Redis commands that expect a key as the
105
- first parameter. Think of it as a
106
- [curried](http://en.wikipedia.org/wiki/Currying) Redis client.
119
+ first parameter.
107
120
 
108
121
  Differences with redis-namespace
109
122
  --------------------------------
@@ -138,30 +151,6 @@ of Nest will let you extend Ohm to suit your needs.
138
151
  Installation
139
152
  ------------
140
153
 
141
- $ gem install nest
142
-
143
- License
144
- -------
145
-
146
- Copyright (c) 2010 Michel Martens & Damian Janowski
147
-
148
- Permission is hereby granted, free of charge, to any person
149
- obtaining a copy of this software and associated documentation
150
- files (the "Software"), to deal in the Software without
151
- restriction, including without limitation the rights to use,
152
- copy, modify, merge, publish, distribute, sublicense, and/or sell
153
- copies of the Software, and to permit persons to whom the
154
- Software is furnished to do so, subject to the following
155
- conditions:
156
-
157
- The above copyright notice and this permission notice shall be
158
- included in all copies or substantial portions of the Software.
159
-
160
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
161
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
162
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
163
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
164
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
165
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
166
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
167
- OTHER DEALINGS IN THE SOFTWARE.
154
+ ```
155
+ $ gem install nest
156
+ ```
data/Rakefile CHANGED
@@ -7,7 +7,6 @@ task :default => :test
7
7
 
8
8
  task :commands do
9
9
  require "open-uri"
10
- require "par"
11
10
  require "json"
12
11
 
13
12
  file = File.expand_path("lib/nest.rb", File.dirname(__FILE__))
@@ -31,7 +30,7 @@ task :commands do
31
30
  commands.delete(:mget)
32
31
 
33
32
  source = File.read(file).sub(/ METHODS = .+?\n\n/m) do
34
- Par.new(" METHODS = #{commands.inspect}\n\n", p: 2)
33
+ " METHODS = #{commands.inspect}\n\n"
35
34
  end
36
35
 
37
36
  File.open(file, "w") { |f| f.write source }
data/lib/nest.rb CHANGED
@@ -1,25 +1,27 @@
1
- require "redis"
1
+ require "redic"
2
2
 
3
3
  class Nest < String
4
- METHODS = [:append, :bitcount, :blpop, :brpop, :brpoplpush, :decr,
5
- :decrby, :del, :dump, :exists, :expire, :expireat, :get, :getbit,
6
- :getrange, :getset, :hdel, :hexists, :hget, :hgetall, :hincrby,
7
- :hincrbyfloat, :hkeys, :hlen, :hmget, :hmset, :hset, :hsetnx, :hvals,
8
- :incr, :incrby, :incrbyfloat, :lindex, :linsert, :llen, :lpop,
9
- :lpush, :lpushx, :lrange, :lrem, :lset, :ltrim, :move, :persist,
10
- :pexpire, :pexpireat, :psetex, :pttl, :publish, :rename, :renamenx,
11
- :restore, :rpop, :rpoplpush, :rpush, :rpushx, :sadd, :scard,
12
- :sdiff, :sdiffstore, :set, :setbit, :setex, :setnx, :setrange,
13
- :sinter, :sinterstore, :sismember, :smembers, :smove, :sort, :spop,
14
- :srandmember, :srem, :strlen, :subscribe, :sunion, :sunionstore,
15
- :ttl, :type, :unsubscribe, :watch, :zadd, :zcard, :zcount,
16
- :zincrby, :zinterstore, :zrange, :zrangebyscore, :zrank, :zrem,
17
- :zremrangebyrank, :zremrangebyscore, :zrevrange, :zrevrangebyscore,
18
- :zrevrank, :zscore, :zunionstore]
4
+ METHODS = [:append, :bitcount, :bitpos, :blpop, :brpop, :brpoplpush,
5
+ :decr, :decrby, :del, :dump, :exists, :expire, :expireat, :get,
6
+ :getbit, :getrange, :getset, :hdel, :hexists, :hget, :hgetall,
7
+ :hincrby, :hincrbyfloat, :hkeys, :hlen, :hmget, :hmset, :hset,
8
+ :hsetnx, :hstrlen, :hvals, :incr, :incrby, :incrbyfloat, :lindex,
9
+ :linsert, :llen, :lpop, :lpush, :lpushx, :lrange, :lrem, :lset,
10
+ :ltrim, :move, :persist, :pexpire, :pexpireat, :pfadd, :pfcount,
11
+ :pfmerge, :psetex, :pttl, :publish, :rename, :renamenx, :restore,
12
+ :rpop, :rpoplpush, :rpush, :rpushx, :sadd, :scard, :sdiff, :sdiffstore,
13
+ :set, :setbit, :setex, :setnx, :setrange, :sinter, :sinterstore,
14
+ :sismember, :smembers, :smove, :sort, :spop, :srandmember, :srem,
15
+ :strlen, :subscribe, :sunion, :sunionstore, :ttl, :type, :unsubscribe,
16
+ :watch, :zadd, :zcard, :zcount, :zincrby, :zinterstore, :zlexcount,
17
+ :zrange, :zrangebylex, :zrevrangebylex, :zrangebyscore, :zrank,
18
+ :zrem, :zremrangebylex, :zremrangebyrank, :zremrangebyscore,
19
+ :zrevrange, :zrevrangebyscore, :zrevrank, :zscore, :zunionstore,
20
+ :sscan, :hscan, :zscan]
19
21
 
20
22
  attr :redis
21
23
 
22
- def initialize(key, redis = Redis.current)
24
+ def initialize(key, redis = Redic.new)
23
25
  super(key.to_s)
24
26
  @redis = redis
25
27
  end
@@ -29,8 +31,8 @@ class Nest < String
29
31
  end
30
32
 
31
33
  METHODS.each do |meth|
32
- define_method(meth) do |*args, &block|
33
- redis.send(meth, self, *args, &block)
34
+ define_method(meth) do |*args|
35
+ redis.call(meth, self, *args)
34
36
  end
35
37
  end
36
38
  end
data/nest.gemspec CHANGED
@@ -1,13 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "nest"
3
- s.version = "1.1.2"
3
+ s.version = "2.0.0"
4
4
  s.summary = "Object-oriented keys for Redis."
5
5
  s.description = "It is a design pattern in key-value databases to use the key to simulate structure, and Nest can take care of that."
6
+ s.licenses = ["MIT"]
6
7
  s.authors = ["Michel Martens"]
7
8
  s.email = ["michel@soveran.com"]
8
9
  s.homepage = "http://github.com/soveran/nest"
9
10
 
10
- s.add_dependency "redis"
11
+ s.add_dependency "redic"
11
12
 
12
13
  s.files = Dir[
13
14
  "LICENSE",
data/test/helper.rb ADDED
@@ -0,0 +1 @@
1
+ require_relative "../lib/nest"
data/test/nest_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.expand_path("test_helper", File.dirname(__FILE__))
1
+ require_relative "helper"
2
2
 
3
3
  # Creating namespaces.
4
4
  scope do
@@ -37,8 +37,8 @@ end
37
37
  # Operating with redis.
38
38
  scope do
39
39
  prepare do
40
- @redis = Redis.new
41
- @redis.flushdb
40
+ @redis = Redic.new
41
+ @redis.call("FLUSHDB")
42
42
  end
43
43
 
44
44
  test "work if no redis instance was passed" do
@@ -58,53 +58,6 @@ scope do
58
58
  test "pass the redis instance to new keys" do
59
59
  n1 = Nest.new("foo", @redis)
60
60
 
61
- assert @redis.id == n1["bar"].redis.id
62
- end
63
-
64
- test "PubSub" do
65
- foo = Nest.new("foo", @redis)
66
- listening = false
67
- message_received = false
68
-
69
- Thread.new do
70
- while !listening; end
71
- Nest.new("foo", Redis.new(:db => 15)).publish("")
72
- end
73
-
74
- foo.subscribe do |on|
75
- on.message do
76
- message_received = true
77
-
78
- foo.unsubscribe
79
- end
80
-
81
- listening = true
82
- end
83
-
84
- assert message_received
85
- end
86
- end
87
-
88
- scope do
89
- prepare do
90
- @redis1 = Redis.connect(:db => 15)
91
- @redis2 = Redis.connect(:db => 14)
92
-
93
- @redis1.flushdb
94
- @redis2.flushdb
95
- end
96
-
97
- test "honors Redis.current" do
98
- Redis.current = @redis1
99
-
100
- foo = Nest.new("foo")
101
-
102
- foo.set("bar")
103
-
104
- assert_equal "bar", foo.get
105
-
106
- Redis.current = @redis2
107
-
108
- assert_equal nil, Nest.new("foo").get
61
+ assert @redis.object_id == n1["bar"].redis.object_id
109
62
  end
110
63
  end
metadata CHANGED
@@ -1,38 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michel Martens
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-01 00:00:00.000000000 Z
11
+ date: 2015-03-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: redis
16
- requirement: &2156217380 !ruby/object:Gem::Requirement
17
- none: false
14
+ name: redic
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *2156217380
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: cutest
27
- requirement: &2156229820 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *2156229820
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  description: It is a design pattern in key-value databases to use the key to simulate
37
42
  structure, and Nest can take care of that.
38
43
  email:
@@ -46,30 +51,30 @@ files:
46
51
  - Rakefile
47
52
  - lib/nest.rb
48
53
  - nest.gemspec
54
+ - test/helper.rb
49
55
  - test/nest_test.rb
50
- - test/test_helper.rb
51
56
  homepage: http://github.com/soveran/nest
52
- licenses: []
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
53
60
  post_install_message:
54
61
  rdoc_options: []
55
62
  require_paths:
56
63
  - lib
57
64
  required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
65
  requirements:
60
- - - ! '>='
66
+ - - '>='
61
67
  - !ruby/object:Gem::Version
62
68
  version: '0'
63
69
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
70
  requirements:
66
- - - ! '>='
71
+ - - '>='
67
72
  - !ruby/object:Gem::Version
68
73
  version: '0'
69
74
  requirements: []
70
75
  rubyforge_project:
71
- rubygems_version: 1.8.11
76
+ rubygems_version: 2.0.14
72
77
  signing_key:
73
- specification_version: 3
78
+ specification_version: 4
74
79
  summary: Object-oriented keys for Redis.
75
80
  test_files: []
data/test/test_helper.rb DELETED
@@ -1,3 +0,0 @@
1
- require "rubygems"
2
- require "cutest"
3
- require File.join(File.dirname(__FILE__), "..", "lib", "nest")