rediska 0.5.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/rediska/command_executor.rb +8 -3
- data/lib/rediska/driver.rb +50 -2
- data/lib/rediska/transaction_commands.rb +4 -4
- data/lib/rediska/version.rb +1 -1
- data/spec/support/connection.rb +1 -1
- data/spec/support/sets.rb +38 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42912927e01fc9f997529b763f267bfd3b38b54f
|
4
|
+
data.tar.gz: a1a484bc665c5b6464bfbde5731f2c3d120d8528
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f97da1ce65e96864840900755ffd52b3f3f129c1e99bb162bc6d769272168249f211ac4ae32a4e9656e554ec15e30c0a58a8a8c321792f70793d407acc8cab8a
|
7
|
+
data.tar.gz: a29ad9857dd640e4e17b32cc375f397a1abeafb83f460cadc2d94c3a1aeb10128ff9e65993f22155a43bc0e9340e763f755647cb3b45515ffeffc2e8c7d0b2fd
|
data/README.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
module Rediska
|
2
2
|
module CommandExecutor
|
3
3
|
def write(command)
|
4
|
-
meffod = command.
|
4
|
+
meffod = command[0].to_s.downcase.to_sym
|
5
|
+
args = command[1..-1]
|
5
6
|
|
6
7
|
if in_multi && !(TRANSACTION_COMMANDS.include? meffod) # queue commands
|
7
|
-
queued_commands << [meffod, *
|
8
|
+
queued_commands << [meffod, *args]
|
8
9
|
reply = 'QUEUED'
|
10
|
+
elsif respond_to?(meffod) && method(meffod).arity.zero?
|
11
|
+
reply = send(meffod)
|
9
12
|
elsif respond_to?(meffod)
|
10
|
-
reply = send(meffod, *
|
13
|
+
reply = send(meffod, *args)
|
11
14
|
else
|
12
15
|
raise Redis::CommandError, "ERR unknown command '#{meffod}'"
|
13
16
|
end
|
@@ -16,6 +19,8 @@ module Rediska
|
|
16
19
|
reply = 1
|
17
20
|
elsif reply == false
|
18
21
|
reply = 0
|
22
|
+
elsif reply.is_a?(Array)
|
23
|
+
reply = reply.map { |r| r == true ? 1 : r == false ? 0 : r }
|
19
24
|
end
|
20
25
|
|
21
26
|
replies << reply
|
data/lib/rediska/driver.rb
CHANGED
@@ -17,6 +17,16 @@ module Rediska
|
|
17
17
|
def disconnect
|
18
18
|
end
|
19
19
|
|
20
|
+
def client(command, _options = {})
|
21
|
+
case command
|
22
|
+
when :setname then true
|
23
|
+
when :getname then nil
|
24
|
+
when :client then true
|
25
|
+
else
|
26
|
+
raise Redis::CommandError, "ERR unknown command '#{command}'"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
20
30
|
def timeout=(usecs)
|
21
31
|
end
|
22
32
|
|
@@ -535,6 +545,44 @@ module Rediska
|
|
535
545
|
number.nil? ? srandmember_single(key) : srandmember_multiple(key, number)
|
536
546
|
end
|
537
547
|
|
548
|
+
def sscan(key, start_cursor, *args)
|
549
|
+
data_type_check(key, ::Set)
|
550
|
+
return ['0', []] unless data[key]
|
551
|
+
|
552
|
+
match = '*'
|
553
|
+
count = 10
|
554
|
+
|
555
|
+
if args.size.odd?
|
556
|
+
raise_argument_error('sscan')
|
557
|
+
end
|
558
|
+
|
559
|
+
if idx = args.index('MATCH')
|
560
|
+
match = args[idx + 1]
|
561
|
+
end
|
562
|
+
|
563
|
+
if idx = args.index('COUNT')
|
564
|
+
count = args[idx + 1]
|
565
|
+
end
|
566
|
+
|
567
|
+
start_cursor = start_cursor.to_i
|
568
|
+
|
569
|
+
cursor = start_cursor
|
570
|
+
next_keys = []
|
571
|
+
|
572
|
+
if start_cursor + count >= data[key].length
|
573
|
+
next_keys = (data[key].to_a)[start_cursor..-1]
|
574
|
+
cursor = 0
|
575
|
+
else
|
576
|
+
cursor = start_cursor + count
|
577
|
+
next_keys = (data[key].to_a)[start_cursor..cursor-1]
|
578
|
+
end
|
579
|
+
|
580
|
+
filtered_next_keys = next_keys.select{ |k,v| File.fnmatch(match, k)}
|
581
|
+
result = filtered_next_keys.flatten.map(&:to_s)
|
582
|
+
|
583
|
+
return ["#{cursor}", result]
|
584
|
+
end
|
585
|
+
|
538
586
|
def del(*keys)
|
539
587
|
keys = keys.flatten(1)
|
540
588
|
raise_argument_error('del') if keys.empty?
|
@@ -849,7 +897,7 @@ module Rediska
|
|
849
897
|
end
|
850
898
|
|
851
899
|
start_cursor = start_cursor.to_i
|
852
|
-
data_type_check(start_cursor,
|
900
|
+
data_type_check(start_cursor, Integer)
|
853
901
|
|
854
902
|
cursor = start_cursor
|
855
903
|
next_keys = []
|
@@ -1058,7 +1106,7 @@ module Rediska
|
|
1058
1106
|
end
|
1059
1107
|
|
1060
1108
|
start_cursor = start_cursor.to_i
|
1061
|
-
data_type_check(start_cursor,
|
1109
|
+
data_type_check(start_cursor, Integer)
|
1062
1110
|
|
1063
1111
|
cursor = start_cursor
|
1064
1112
|
next_keys = []
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Rediska
|
2
|
-
TRANSACTION_COMMANDS = [:discard, :exec, :multi, :watch, :unwatch]
|
2
|
+
TRANSACTION_COMMANDS = [:discard, :exec, :multi, :watch, :unwatch, :client]
|
3
3
|
|
4
4
|
module TransactionCommands
|
5
5
|
def self.included(klass)
|
@@ -46,7 +46,7 @@ module Rediska
|
|
46
46
|
raise Redis::CommandError, 'ERR EXEC without MULTI'
|
47
47
|
end
|
48
48
|
|
49
|
-
responses
|
49
|
+
responses = queued_commands.map do |cmd|
|
50
50
|
begin
|
51
51
|
send(*cmd)
|
52
52
|
rescue => e
|
@@ -54,8 +54,8 @@ module Rediska
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
self.queued_commands = []
|
58
|
-
self.in_multi = false
|
57
|
+
self.queued_commands = []
|
58
|
+
self.in_multi = false
|
59
59
|
|
60
60
|
responses
|
61
61
|
end
|
data/lib/rediska/version.rb
CHANGED
data/spec/support/connection.rb
CHANGED
data/spec/support/sets.rb
CHANGED
@@ -258,4 +258,42 @@ shared_examples 'sets' do
|
|
258
258
|
end
|
259
259
|
end
|
260
260
|
end
|
261
|
+
|
262
|
+
describe 'sscan' do
|
263
|
+
it 'with no arguments and few items, returns all items' do
|
264
|
+
subject.sadd('set', ['name', 'Jack', 'age', '33'])
|
265
|
+
result = subject.sscan('set', 0)
|
266
|
+
|
267
|
+
expect(result[0]).to eq('0')
|
268
|
+
expect(result[1]).to eq(['name', 'Jack', 'age', '33'])
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'with a count should return that number of members or more' do
|
272
|
+
subject.sadd('set', ['a', '1', 'b', '2', 'c', '3', 'd', '4', 'e', '5', 'f', '6', 'g', '7'])
|
273
|
+
result = subject.sscan('set', 0, count: 3)
|
274
|
+
expect(result[0]).to eq('3')
|
275
|
+
expect(result[1]).to eq([ 'a', '1', 'b'])
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'returns items starting at the provided cursor' do
|
279
|
+
subject.sadd('set', ['a', '1', 'b', '2', 'c', '3', 'd', '4', 'e', '5', 'f', '6', 'g', '7'])
|
280
|
+
result = subject.sscan('set', 2, count: 3)
|
281
|
+
expect(result[0]).to eq('5')
|
282
|
+
expect(result[1]).to eq(['b', '2', 'c'])
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'with match, returns items matching the given pattern' do
|
286
|
+
subject.sadd('set', ['aa', '1', 'b', '2', 'cc', '3', 'd', '4', 'ee', '5', 'f', '6', 'gg', '7'])
|
287
|
+
result = subject.sscan('set', 2, count: 7, match: '??')
|
288
|
+
expect(result[0]).to eq('9')
|
289
|
+
expect(result[1]).to eq(['cc','ee'])
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'returns an empty result if the key is not found' do
|
293
|
+
result = subject.sscan('set', 0)
|
294
|
+
|
295
|
+
expect(result[0]).to eq('0')
|
296
|
+
expect(result[1]).to eq([])
|
297
|
+
end
|
298
|
+
end
|
261
299
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rediska
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonid Beder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.6.14
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: A light-weighted redis driver for testing, development, and minimal environments
|
@@ -172,4 +172,3 @@ test_files:
|
|
172
172
|
- spec/support/strings.rb
|
173
173
|
- spec/support/transactions.rb
|
174
174
|
- spec/support/upcase_method_names.rb
|
175
|
-
has_rdoc:
|