Skip to content
Audit and Rollback operations on a Redis DB. Meant to help in testing Redis-based models atomically. This is a simple concept right now and nothing more. It breaks stuff.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
spec
README.rdoc
Rakefile
VERSION

README.rdoc

when testing an application using Redis there is no way to have atomic examples. Operation effects remain in the database between examples. This is a first step into possibly changing that.

A Little History

require 'redis'
require 'redis-rollbacks'

r = Redis.new
r.set 'abc', '123'
r.last_command # ['set', 'abc', '123']

r.start_audit
r.set 'abc', '345'
r.lpush 'my_list', 'aval'
r.lpush 'my_list, 'aval2'
r.last_command # ['lpush', 'my_list', 'aval2']
r.last_command(1) # ['lpush', 'my_list', 'aval2']
r.last_command(2) # [['lpush', 'my_list', 'aval2'],['lpush', 'my_list', 'aval']]
r.get 'abc'
r.last_command(3) # [['get', 'abc'],['lpush', 'my_list', 'aval2'],['lpush', 'my_list', 'aval']]
r.stop_audit
r.last_command # ['set', 'abc', '123']

Rolling Back

a SET operation that creates a key

r = Redis.new 
r.delete 'key' # just so you know its not there for purposes of this example
r.set 'key', 'abc'
r.last_effect  # :create
r.rollback_last
r.get 'key'    # nil

a SET operation that updates a key

r = Redis.new
r.set 'key', 'abc'
r.set 'key', 'def'
r.last_effect # :update
r.rollback_last
r.get 'key' # 'abc'

A DELETE operation on a string or key

r = Redis.new
r.set 'key', 'abc'
r.delete
r.last_effect # :destroy
r.rollback_last
r.get 'key' # 'abc'
r.delete 'key'
r.lpush 'key', 1
r.lpush 'key', 2
r.delete 'key'
r.rollback_last
r.lrange 'key', 0, -1 # ['2', '1']

Operations this has been tested again

* SET
* DELETE (of strings and lists)

yes I know but like I said this is just a concept for now

Something went wrong with that request. Please try again.