rediscan 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gems +3 -0
- data/.gitignore +1 -0
- data/LICENSE +19 -0
- data/README.md +52 -0
- data/lib/rediscan.rb +20 -0
- data/makefile +2 -0
- data/rediscan.gemspec +15 -0
- data/tests/rediscan_test.rb +24 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 55923a1180bce348df51b1dfa0a29bf4ea229bd8
|
4
|
+
data.tar.gz: 35c0664c69da14d97b43c84b1d9a4d58c5d1b7ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c1d1e175655b6b5eca476739919816d69dcf4567a5acb4e4fcf88d8291c0f538fecaac21c36030094e78dfedf29dec3d97b759341bcc9b19d32f319666af6ac
|
7
|
+
data.tar.gz: 45757631d3b2a89d518a336f2b6527b04467db82f2f74c88efa9a6c54ce6a7157f510c1326aa879a1cb445a41bbe1798376d58e7bbc0d62b0b7e2aa8c2e01f5b
|
data/.gems
ADDED
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/.gs
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Michel Martens
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
Rediscan
|
2
|
+
========
|
3
|
+
|
4
|
+
Scanner for Redis keyspace
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Rediscan lets you iterate over the Redis keyspace and execute a
|
10
|
+
block for each match.
|
11
|
+
|
12
|
+
Usage
|
13
|
+
-----
|
14
|
+
|
15
|
+
You need to suply a Redis client. There are no restrictions
|
16
|
+
regarding the type of the Redis client, but it must respond to
|
17
|
+
`call` and the signature must be identical to that of
|
18
|
+
[Redic][redic].
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
r = Rediscan.new(Redic.new)
|
22
|
+
```
|
23
|
+
|
24
|
+
Once you have the `Rediscan` instance, you can use it as follows:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
r.each do |key|
|
28
|
+
# Do something with `key`
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
You can also provide `match` and `count` arguments:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
r.each(match: "ost:*", count: 4) do |key|
|
36
|
+
# Do something with `key`
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
For the meaning for `match` and `count`, check the documentation
|
41
|
+
for the [SCAN command][scan]
|
42
|
+
|
43
|
+
## Installation
|
44
|
+
|
45
|
+
You can install it using rubygems.
|
46
|
+
|
47
|
+
```
|
48
|
+
$ gem install rediscan
|
49
|
+
```
|
50
|
+
|
51
|
+
[redic]: https://github.com/amakawa/redic
|
52
|
+
[scan]: http://redis.io/commands/scan
|
data/lib/rediscan.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class Rediscan
|
2
|
+
def initialize(redis)
|
3
|
+
@redis = redis
|
4
|
+
@cursor = "0"
|
5
|
+
end
|
6
|
+
|
7
|
+
def each(match: nil, count: nil, &block)
|
8
|
+
done = false
|
9
|
+
args = []
|
10
|
+
args.push("MATCH", match) if match
|
11
|
+
args.push("COUNT", count) if count
|
12
|
+
|
13
|
+
until done
|
14
|
+
@cursor, keys = @redis.call("SCAN", @cursor, *args)
|
15
|
+
done = @cursor == "0"
|
16
|
+
|
17
|
+
keys.each(&block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/makefile
ADDED
data/rediscan.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "rediscan"
|
5
|
+
s.version = "0.0.1"
|
6
|
+
s.summary = "Scanner for Redis keyspace"
|
7
|
+
s.description = "Scanner for Redis keyspace"
|
8
|
+
s.authors = ["Michel Martens"]
|
9
|
+
s.email = ["michel@soveran.com"]
|
10
|
+
s.homepage = "https://github.com/soveran/rediscan"
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.license = "MIT"
|
13
|
+
|
14
|
+
s.add_dependency "redic"
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "../lib/rediscan"
|
2
|
+
|
3
|
+
REDIS_URL = "redis://localhost:6379/3"
|
4
|
+
|
5
|
+
prepare do
|
6
|
+
Redic.new(REDIS_URL).call("FLUSHDB")
|
7
|
+
end
|
8
|
+
|
9
|
+
setup do
|
10
|
+
c = Redic.new(REDIS_URL)
|
11
|
+
s = Rediscan.new(c)
|
12
|
+
|
13
|
+
[c, s]
|
14
|
+
end
|
15
|
+
|
16
|
+
test do |c, s|
|
17
|
+
assert_equal 0, c.call("DBSIZE")
|
18
|
+
|
19
|
+
c.call("SET", "ost:1", "1")
|
20
|
+
|
21
|
+
s.each(match: "ost:*", count: 10) do |key|
|
22
|
+
assert_equal "ost:1", key
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rediscan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michel Martens
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redic
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Scanner for Redis keyspace
|
28
|
+
email:
|
29
|
+
- michel@soveran.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gems
|
35
|
+
- .gitignore
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- lib/rediscan.rb
|
39
|
+
- makefile
|
40
|
+
- rediscan.gemspec
|
41
|
+
- tests/rediscan_test.rb
|
42
|
+
homepage: https://github.com/soveran/rediscan
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.0.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Scanner for Redis keyspace
|
66
|
+
test_files: []
|