Sha256: 32ae213d8a0b7ca7c161479fe7260aa5e96eadaf881152cfe8d4c57eb578fc44

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'lib/redis/dump'

@uri_base = "redis://127.0.0.1:6371"

Redis::Dump.debug = false
Redis::Dump.safe = true

## Connect to DB
@rdump = Redis::Dump.new 0, @uri_base
@rdump.redis_connections.size
#=> 1

## Populate
@rdump.redis(0).set 'stringkey', 'stringvalue'
@rdump.redis(0).expire 'stringkey', 100
@rdump.redis(0).hset 'hashkey', 'field_a', 'value_a'
@rdump.redis(0).hset 'hashkey', 'field_b', 'value_b'
@rdump.redis(0).hset 'hashkey', 'field_c', 'value_c'
3.times { |idx| @rdump.redis(0).rpush 'listkey', "value_#{idx}" }
4.times { |idx| @rdump.redis(0).sadd 'setkey', "value_#{idx}" }
5.times { |idx| @rdump.redis(0).zadd 'zsetkey', idx.zero? ? 100 : 100*idx, "value_#{idx}" }
@rdump.redis(0).keys.size
#=> 5

## Can dump
@values = @rdump.dump
@values.size
#=> 5

# Clear DB 0
db0 = Redis::Dump.new 0, @uri_base
db0.redis(0).flushdb
db0.redis(0).keys.size
#=> 0

## Can load data
@rdump.load @values.join
@rdump.redis(0).keys.size
#=> 5

## DB 0 content matches previous dump content
values = @rdump.dump
values.sort
#=> @values.sort

## Won't load data in safe mode if records exist
@rdump.load @values.join
#=> 0

## Will load data if records exist and safe mode is disabled
Redis::Dump.safe = false
@rdump.load @values.join
#=> 5

Redis::Dump.safe = true
db0 = Redis::Dump.new 0, @uri_base
db0.redis(0).flushdb

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redis-dump-0.1.0 try/10_redis_dump_try.rb