rediska 0.1.12 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -7
- data/lib/rediska/driver.rb +35 -0
- data/lib/rediska/version.rb +1 -1
- data/spec/support/keys.rb +92 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ec9829d3cd104273bee44047fcf203d762013c8
|
4
|
+
data.tar.gz: 61e479768ba49b7b1ab7d9def68c60ef8648fb24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35d0a35359099b4dfa0efa37085a17d277155cbc2caaf67e92bc66d016a826a64eb64ddacc887912063a38e1fba410016e1e3a98b9aeaea56dc5716215280f1b
|
7
|
+
data.tar.gz: a3b49dc3a061032054fc54123b5f3e3939cf7240555c10439333964a9aa5c1a532614d83d8833a0b25ea0243802c10a819f631f33083a033c55b48adb9272b1c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rediska (0.
|
4
|
+
rediska (0.2.0)
|
5
5
|
redis (>= 3)
|
6
6
|
|
7
7
|
GEM
|
@@ -35,12 +35,12 @@ GEM
|
|
35
35
|
rspec-core (~> 3.1.0)
|
36
36
|
rspec-expectations (~> 3.1.0)
|
37
37
|
rspec-mocks (~> 3.1.0)
|
38
|
-
rspec-core (3.1.
|
38
|
+
rspec-core (3.1.4)
|
39
39
|
rspec-support (~> 3.1.0)
|
40
|
-
rspec-expectations (3.1.
|
40
|
+
rspec-expectations (3.1.1)
|
41
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
42
|
rspec-support (~> 3.1.0)
|
43
|
-
rspec-mocks (3.1.
|
43
|
+
rspec-mocks (3.1.1)
|
44
44
|
rspec-support (~> 3.1.0)
|
45
45
|
rspec-support (3.1.0)
|
46
46
|
sidekiq (3.2.5)
|
@@ -49,16 +49,16 @@ GEM
|
|
49
49
|
json
|
50
50
|
redis (>= 3.0.6)
|
51
51
|
redis-namespace (>= 1.3.1)
|
52
|
-
simplecov (0.9.
|
52
|
+
simplecov (0.9.1)
|
53
53
|
docile (~> 1.1.0)
|
54
|
-
multi_json
|
54
|
+
multi_json (~> 1.0)
|
55
55
|
simplecov-html (~> 0.8.0)
|
56
56
|
simplecov-html (0.8.0)
|
57
57
|
term-ansicolor (1.3.0)
|
58
58
|
tins (~> 1.0)
|
59
59
|
thor (0.19.1)
|
60
60
|
timers (1.1.0)
|
61
|
-
tins (1.3.
|
61
|
+
tins (1.3.3)
|
62
62
|
|
63
63
|
PLATFORMS
|
64
64
|
ruby
|
data/lib/rediska/driver.rb
CHANGED
@@ -84,6 +84,41 @@ module Rediska
|
|
84
84
|
true
|
85
85
|
end
|
86
86
|
|
87
|
+
def dump(key)
|
88
|
+
return nil unless exists(key)
|
89
|
+
|
90
|
+
Marshal.dump(value: data[key], version: Rediska::VERSION)
|
91
|
+
end
|
92
|
+
|
93
|
+
def restore(key, ttl, serialized_value)
|
94
|
+
raise Redis::CommandError, 'ERR Target key name is busy.' if exists(key)
|
95
|
+
|
96
|
+
if serialized_value.nil?
|
97
|
+
raise Redis::CommandError, 'ERR DUMP payload version or checksum are wrong'
|
98
|
+
end
|
99
|
+
|
100
|
+
parsed_value = begin
|
101
|
+
Marshal.load(serialized_value)
|
102
|
+
rescue TypeError
|
103
|
+
raise Redis::CommandError, 'ERR DUMP payload version or checksum are wrong'
|
104
|
+
end
|
105
|
+
|
106
|
+
if parsed_value[:version] != Rediska::VERSION
|
107
|
+
raise Redis::CommandError, 'ERR DUMP payload version or checksum are wrong'
|
108
|
+
end
|
109
|
+
|
110
|
+
# We could figure out what type the key was and set it with the public API here, or we could
|
111
|
+
# just assign the value. If we presume the serialized_value is only ever a return value from
|
112
|
+
# `dump` then we've only been given something that was in the internal data structure anyway.
|
113
|
+
data[key] = parsed_value[:value]
|
114
|
+
|
115
|
+
# Set a TTL if one has been passed
|
116
|
+
ttl = ttl.to_i # Makes nil into 0
|
117
|
+
expire(key, ttl / 1000) unless ttl.zero?
|
118
|
+
|
119
|
+
'OK'
|
120
|
+
end
|
121
|
+
|
87
122
|
def get(key)
|
88
123
|
data_type_check(key, String)
|
89
124
|
data[key]
|
data/lib/rediska/version.rb
CHANGED
data/spec/support/keys.rb
CHANGED
@@ -388,5 +388,97 @@ shared_examples 'keys' do
|
|
388
388
|
expect(subject.set('key2', '1', nx: true, xx: true)).to be_falsey
|
389
389
|
expect(subject.get('key2')).to be_nil
|
390
390
|
end
|
391
|
+
|
392
|
+
describe '#dump' do
|
393
|
+
it 'returns nil for unknown key' do
|
394
|
+
expect(subject.exists('key1')).to be_falsey
|
395
|
+
expect(subject.dump('key1')).to be_nil
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'dumps a single known key successfully' do
|
399
|
+
subject.set('key1', 'zomgwtf')
|
400
|
+
|
401
|
+
value = subject.dump('key1')
|
402
|
+
expect(value).not_to be_nil
|
403
|
+
expect(value).to be_a_kind_of(String)
|
404
|
+
end
|
405
|
+
|
406
|
+
it 'errors with more than one argument' do
|
407
|
+
expect {
|
408
|
+
subject.dump('key1', 'key2')
|
409
|
+
}.to raise_error(ArgumentError, /wrong number of arguments/)
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
describe "#restore" do
|
414
|
+
it 'errors with a missing payload' do
|
415
|
+
expect {
|
416
|
+
subject.restore('key1', 0, nil)
|
417
|
+
}.to raise_error(Redis::CommandError, 'ERR DUMP payload version or checksum are wrong')
|
418
|
+
end
|
419
|
+
|
420
|
+
it 'errors with an invalid payload' do
|
421
|
+
expect {
|
422
|
+
subject.restore('key1', 0, 'zomgwtf not valid')
|
423
|
+
}.to raise_error(Redis::CommandError, 'ERR DUMP payload version or checksum are wrong')
|
424
|
+
end
|
425
|
+
|
426
|
+
describe 'with a dumped value' do
|
427
|
+
before do
|
428
|
+
subject.set('key1', 'original value')
|
429
|
+
@dumped_value = subject.dump('key1')
|
430
|
+
|
431
|
+
subject.del('key1')
|
432
|
+
expect(subject.exists('key1')).to be_falsey
|
433
|
+
end
|
434
|
+
|
435
|
+
it 'restores to a new key successfully' do
|
436
|
+
response = subject.restore('key1', 0, @dumped_value)
|
437
|
+
expect(response).to eq('OK')
|
438
|
+
end
|
439
|
+
|
440
|
+
it 'errors trying to restore to an existing key' do
|
441
|
+
subject.set('key1', 'something else')
|
442
|
+
|
443
|
+
expect {
|
444
|
+
subject.restore('key1', 0, @dumped_value)
|
445
|
+
}.to raise_error(Redis::CommandError, 'ERR Target key name is busy.')
|
446
|
+
end
|
447
|
+
|
448
|
+
it 'restores successfully with a given expire time' do
|
449
|
+
subject.restore('key2', 2000, @dumped_value)
|
450
|
+
|
451
|
+
expect(subject.ttl('key2')).to eq(2)
|
452
|
+
end
|
453
|
+
|
454
|
+
it 'restores a list successfully' do
|
455
|
+
subject.lpush('key1', 'val1')
|
456
|
+
subject.lpush('key1', 'val2')
|
457
|
+
|
458
|
+
expect(subject.type('key1')).to eq('list')
|
459
|
+
|
460
|
+
dumped_value = subject.dump('key1')
|
461
|
+
|
462
|
+
response = subject.restore('key2', 0, dumped_value)
|
463
|
+
expect(response).to eq('OK')
|
464
|
+
|
465
|
+
expect(subject.type('key2')).to eq('list')
|
466
|
+
end
|
467
|
+
|
468
|
+
it 'restores a set successfully' do
|
469
|
+
subject.sadd('key1', 'val1')
|
470
|
+
subject.sadd('key1', 'val2')
|
471
|
+
|
472
|
+
expect(subject.type('key1')).to eq('set')
|
473
|
+
|
474
|
+
dumped_value = subject.dump('key1')
|
475
|
+
|
476
|
+
response = subject.restore('key2', 0, dumped_value)
|
477
|
+
expect(response).to eq('OK')
|
478
|
+
|
479
|
+
expect(subject.type('key2')).to eq('set')
|
480
|
+
end
|
481
|
+
end
|
482
|
+
end
|
391
483
|
end
|
392
484
|
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: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonid Beder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|