ruote-redis 2.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +9 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +73 -0
- data/Rakefile +78 -0
- data/TODO.txt +10 -0
- data/lib/ruote-redis.rb +3 -0
- data/lib/ruote/redis.rb +3 -0
- data/lib/ruote/redis/storage.rb +297 -0
- data/lib/ruote/redis/version.rb +7 -0
- data/ruote-redis.gemspec +67 -0
- data/test/functional_connection.rb +31 -0
- metadata +136 -0
    
        data/CHANGELOG.txt
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            Copyright (c) 2001-2010, John Mettraux, jmettraux@gmail.com
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 5 | 
            +
            of this software and associated documentation files (the "Software"), to deal
         | 
| 6 | 
            +
            in the Software without restriction, including without limitation the rights
         | 
| 7 | 
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 8 | 
            +
            copies of the Software, and to permit persons to whom the Software is
         | 
| 9 | 
            +
            furnished to do so, subject to the following conditions:
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            The above copyright notice and this permission notice shall be included in
         | 
| 12 | 
            +
            all copies or substantial portions of the Software.
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 15 | 
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 16 | 
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 17 | 
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 18 | 
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 19 | 
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         | 
| 20 | 
            +
            THE SOFTWARE.
         | 
| 21 | 
            +
             | 
    
        data/README.rdoc
    ADDED
    
    | @@ -0,0 +1,73 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            = ruote-redis
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Redis persistence for ruote 2.1 (a ruby workflow engine)
         | 
| 5 | 
            +
             | 
| 6 | 
            +
             | 
| 7 | 
            +
            == usage
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            The storage is instantiate by passing a redis-rb instance to the storage.
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              require 'redis' # gem install redis
         | 
| 12 | 
            +
              require 'ruote' # gem install ruote
         | 
| 13 | 
            +
              require 'ruote-redis' # gem install ruote-redis
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              engine = Ruote::Engine.new(
         | 
| 16 | 
            +
                Ruote::Worker.new(
         | 
| 17 | 
            +
                  Ruote::Redis::RedisStorage.new(
         | 
| 18 | 
            +
                    ::Redis.new(:db => 14, :thread_safe => true), {})))
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              # ...
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            Passing an em-redis instance might work, but I haven't tried.
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            Tested with Redis 1.3.8 (redis-rb 2.0.1).
         | 
| 25 | 
            +
             | 
| 26 | 
            +
             | 
| 27 | 
            +
            == running tests
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            assuming you have
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              ruote/
         | 
| 32 | 
            +
              ruote-redis/
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            start a redis server instance (port 6379) and then 
         | 
| 35 | 
            +
             | 
| 36 | 
            +
             | 
| 37 | 
            +
            * unit tests :
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            get into ruote/ and do
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              ruby test/unit/storage.rb --redis
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            * functional tests :
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            get into ruote/ and do
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              ruby test/functional/test.rb --redis
         | 
| 48 | 
            +
             | 
| 49 | 
            +
             | 
| 50 | 
            +
            == license
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            MIT
         | 
| 53 | 
            +
             | 
| 54 | 
            +
             | 
| 55 | 
            +
            == links
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            * http://code.google.com/p/redis/
         | 
| 58 | 
            +
            * http://github.com/ezmobius/redis-rb
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            * http://ruote.rubyforge.org/
         | 
| 61 | 
            +
            * http://github.com/jmettraux/ruote-redis
         | 
| 62 | 
            +
             | 
| 63 | 
            +
             | 
| 64 | 
            +
            == feedback
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            mailing list : http://groups.google.com/group/openwferu-users
         | 
| 67 | 
            +
            irc : irc.freenode.net #ruote
         | 
| 68 | 
            +
             | 
| 69 | 
            +
             | 
| 70 | 
            +
            == many thanks to
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            - the Redis authors and the redis-rb authors
         | 
| 73 | 
            +
             | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,78 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            require 'rubygems'
         | 
| 3 | 
            +
            require 'rake'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            require 'lib/ruote/redis/version.rb'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            #
         | 
| 8 | 
            +
            # CLEAN
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            require 'rake/clean'
         | 
| 11 | 
            +
            CLEAN.include('pkg', 'tmp', 'html')
         | 
| 12 | 
            +
            task :default => [ :clean ]
         | 
| 13 | 
            +
             | 
| 14 | 
            +
             | 
| 15 | 
            +
            #
         | 
| 16 | 
            +
            # GEM
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            require 'jeweler'
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            Jeweler::Tasks.new do |gem|
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              gem.version = Ruote::Redis::VERSION
         | 
| 23 | 
            +
              gem.name = 'ruote-redis'
         | 
| 24 | 
            +
              gem.summary = 'Redis storage for ruote (a ruby workflow engine)'
         | 
| 25 | 
            +
              gem.description = %{
         | 
| 26 | 
            +
            Redis storage for ruote (a ruby workflow engine)
         | 
| 27 | 
            +
              }.strip
         | 
| 28 | 
            +
              gem.email = 'jmettraux@gmail.com'
         | 
| 29 | 
            +
              gem.homepage = 'http://github.com/jmettraux/ruote-redis'
         | 
| 30 | 
            +
              gem.authors = [ 'John Mettraux' ]
         | 
| 31 | 
            +
              gem.rubyforge_project = 'ruote'
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              #gem.test_file = 'test/test.rb'
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              gem.add_dependency 'ruote', ">= #{Ruote::Redis::VERSION}"
         | 
| 36 | 
            +
              gem.add_dependency 'redis', '>= 2.0.1'
         | 
| 37 | 
            +
              gem.add_development_dependency 'yard'
         | 
| 38 | 
            +
              gem.add_development_dependency 'rake'
         | 
| 39 | 
            +
              gem.add_development_dependency 'jeweler'
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              # gemspec spec : http://www.rubygems.org/read/chapter/20
         | 
| 42 | 
            +
            end
         | 
| 43 | 
            +
            Jeweler::GemcutterTasks.new
         | 
| 44 | 
            +
             | 
| 45 | 
            +
             | 
| 46 | 
            +
            #
         | 
| 47 | 
            +
            # DOC
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            begin
         | 
| 50 | 
            +
             | 
| 51 | 
            +
              require 'yard'
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              YARD::Rake::YardocTask.new do |doc|
         | 
| 54 | 
            +
                doc.options = [
         | 
| 55 | 
            +
                  '-o', 'html/ruote-redis', '--title',
         | 
| 56 | 
            +
                  "ruote-redis #{Ruote::Redis::VERSION}"
         | 
| 57 | 
            +
                ]
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            rescue LoadError
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              task :yard do
         | 
| 63 | 
            +
                abort "YARD is not available : sudo gem install yard"
         | 
| 64 | 
            +
              end
         | 
| 65 | 
            +
            end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
             | 
| 68 | 
            +
            #
         | 
| 69 | 
            +
            # TO THE WEB
         | 
| 70 | 
            +
             | 
| 71 | 
            +
            task :upload_website => [ :clean, :yard ] do
         | 
| 72 | 
            +
             | 
| 73 | 
            +
              account = 'jmettraux@rubyforge.org'
         | 
| 74 | 
            +
              webdir = '/var/www/gforge-projects/ruote'
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              sh "rsync -azv -e ssh html/ruote-redis #{account}:#{webdir}/"
         | 
| 77 | 
            +
            end
         | 
| 78 | 
            +
             | 
    
        data/TODO.txt
    ADDED
    
    | @@ -0,0 +1,10 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            [x] methods specific to StorageParticipant
         | 
| 3 | 
            +
            [o] redis -> @redis
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            [ ] 1 ::Redis instance per thread ? (instead of :thread_safe => true)
         | 
| 6 | 
            +
            [ ] update to redis-rb 2.0 (which has sthing about threads)
         | 
| 7 | 
            +
                http://blog.citrusbyte.com/2010/05/14/redis-rb-200/
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            [ ] double-check for deletion of old keys
         | 
| 10 | 
            +
             | 
    
        data/lib/ruote-redis.rb
    ADDED
    
    
    
        data/lib/ruote/redis.rb
    ADDED
    
    
| @@ -0,0 +1,297 @@ | |
| 1 | 
            +
            #--
         | 
| 2 | 
            +
            # Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
         | 
| 3 | 
            +
            #
         | 
| 4 | 
            +
            # Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 5 | 
            +
            # of this software and associated documentation files (the "Software"), to deal
         | 
| 6 | 
            +
            # in the Software without restriction, including without limitation the rights
         | 
| 7 | 
            +
            # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 8 | 
            +
            # copies of the Software, and to permit persons to whom the Software is
         | 
| 9 | 
            +
            # furnished to do so, subject to the following conditions:
         | 
| 10 | 
            +
            #
         | 
| 11 | 
            +
            # The above copyright notice and this permission notice shall be included in
         | 
| 12 | 
            +
            # all copies or substantial portions of the Software.
         | 
| 13 | 
            +
            #
         | 
| 14 | 
            +
            # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 15 | 
            +
            # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 16 | 
            +
            # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 17 | 
            +
            # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 18 | 
            +
            # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 19 | 
            +
            # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         | 
| 20 | 
            +
            # THE SOFTWARE.
         | 
| 21 | 
            +
            #
         | 
| 22 | 
            +
            # Made in Japan.
         | 
| 23 | 
            +
            #++
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            #require 'redis'
         | 
| 26 | 
            +
              # now letting the end-user doing this require
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            require 'rufus-json'
         | 
| 29 | 
            +
            require 'ruote/storage/base'
         | 
| 30 | 
            +
            require 'ruote/redis/version'
         | 
| 31 | 
            +
             | 
| 32 | 
            +
             | 
| 33 | 
            +
            module Ruote
         | 
| 34 | 
            +
            module Redis
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              #
         | 
| 37 | 
            +
              # A Redis storage for ruote.
         | 
| 38 | 
            +
              #
         | 
| 39 | 
            +
              # The constructor accepts two arguments, the first one is a Redis instance
         | 
| 40 | 
            +
              # ( see http://github.com/ezmobius/redis-rb ), the second one is the classic
         | 
| 41 | 
            +
              # ruote engine options ( see
         | 
| 42 | 
            +
              # http://ruote.rubyforge.org/configuration.html#engine )
         | 
| 43 | 
            +
              #
         | 
| 44 | 
            +
              #   require 'redis' # gem install redis
         | 
| 45 | 
            +
              #   require 'ruote' # gem install ruote
         | 
| 46 | 
            +
              #   require 'ruote-redis' # gem install ruote-redis
         | 
| 47 | 
            +
              #
         | 
| 48 | 
            +
              #   engine = Ruote::Engine.new(
         | 
| 49 | 
            +
              #     Ruote::Worker.new(
         | 
| 50 | 
            +
              #       Ruote::Redis::RedisStorage.new(
         | 
| 51 | 
            +
              #         ::Redis.new(:db => 14, :thread_safe => true), {})))
         | 
| 52 | 
            +
              #
         | 
| 53 | 
            +
              #
         | 
| 54 | 
            +
              # == em-redis
         | 
| 55 | 
            +
              #
         | 
| 56 | 
            +
              # Not tried, but I guess, that substituting an instance of em-redis for
         | 
| 57 | 
            +
              # the redis instance passed to the constructor might work.
         | 
| 58 | 
            +
              # http://github.com/madsimian/em-redis
         | 
| 59 | 
            +
              #
         | 
| 60 | 
            +
              # If you try and it works, feedback is welcome
         | 
| 61 | 
            +
              # http://groups.google.com/group/openwferu-users
         | 
| 62 | 
            +
              #
         | 
| 63 | 
            +
              class RedisStorage
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                include Ruote::StorageBase
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                attr_reader :redis
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                def initialize (redis, options={})
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                  @redis = redis
         | 
| 72 | 
            +
                  @options = options
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                  def @redis.keys_to_a (opt)
         | 
| 75 | 
            +
                    r = keys(opt)
         | 
| 76 | 
            +
                    r.is_a?(Array) ? r : r.split(' ')
         | 
| 77 | 
            +
                  end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                  put_configuration
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                def reserve (doc)
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                  @redis.del(key_for(doc))
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                def put_msg (action, options)
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  doc = prepare_msg_doc(action, options)
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                  @redis.set(key_for(doc), to_json(doc))
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                  nil
         | 
| 94 | 
            +
                end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                def put_schedule (flavour, owner_fei, s, msg)
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                  if doc = prepare_schedule_doc(flavour, owner_fei, s, msg)
         | 
| 99 | 
            +
                    @redis.set(key_for(doc), to_json(doc))
         | 
| 100 | 
            +
                    return doc['_id']
         | 
| 101 | 
            +
                  end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                  nil
         | 
| 104 | 
            +
                end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                def delete_schedule (schedule_id)
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                  @redis.del(key_for('schedules', schedule_id))
         | 
| 109 | 
            +
                end
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                def put (doc, opts={})
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                  rev = doc['_rev'].to_i
         | 
| 114 | 
            +
                  key = key_for(doc)
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                  current_rev = @redis.get(key).to_i
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                  return true if current_rev == 0 && rev > 0
         | 
| 119 | 
            +
                  return do_get(doc, current_rev) if rev != current_rev
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                  nrev = rev + 1
         | 
| 122 | 
            +
             | 
| 123 | 
            +
                  # the setnx here is crucial in multiple workers env...
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                  r = @redis.setnx(
         | 
| 126 | 
            +
                    key_rev_for(doc, nrev),
         | 
| 127 | 
            +
                    to_json(doc.merge('_rev' => nrev), opts))
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                  return get(doc['type'], doc['_id']) if r == false
         | 
| 130 | 
            +
             | 
| 131 | 
            +
                  @redis.set(key, nrev)
         | 
| 132 | 
            +
                  @redis.del(key_rev_for(doc, rev)) if rev > 0
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                  doc['_rev'] = nrev if opts[:update_rev]
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                  nil
         | 
| 137 | 
            +
                end
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                def get (type, key)
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                  do_get(type, key, @redis.get(key_for(type, key)))
         | 
| 142 | 
            +
                end
         | 
| 143 | 
            +
             | 
| 144 | 
            +
                def delete (doc)
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                  raise ArgumentError.new(
         | 
| 147 | 
            +
                    "can't delete doc without _rev") unless doc['_rev']
         | 
| 148 | 
            +
             | 
| 149 | 
            +
                  r = put(doc, :delete => true)
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                  return r if r != nil
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                  @redis.keys_to_a("#{key_for(doc)}*").sort.each { |k|
         | 
| 154 | 
            +
                    Thread.pass # lingering a bit...
         | 
| 155 | 
            +
                    @redis.del(k)
         | 
| 156 | 
            +
                  }
         | 
| 157 | 
            +
                    # deleting the key_rev last and making 1 'keys' call preliminarily
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                  nil
         | 
| 160 | 
            +
                end
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                def get_many (type, key=nil, opts={})
         | 
| 163 | 
            +
             | 
| 164 | 
            +
                  keys = "#{type}/*"
         | 
| 165 | 
            +
             | 
| 166 | 
            +
                  ids = if type == 'msgs' || type == 'schedules'
         | 
| 167 | 
            +
             | 
| 168 | 
            +
                    @redis.keys_to_a(keys)
         | 
| 169 | 
            +
             | 
| 170 | 
            +
                  else
         | 
| 171 | 
            +
             | 
| 172 | 
            +
                    @redis.keys_to_a(keys).inject({}) { |h, k|
         | 
| 173 | 
            +
             | 
| 174 | 
            +
                      if m = k.match(/^[^\/]+\/([^\/]+)\/(\d+)$/)
         | 
| 175 | 
            +
             | 
| 176 | 
            +
                        if ( ! key) || m[1].match(key)
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                          o = h[m[1]]
         | 
| 179 | 
            +
                          n = [ m[2].to_i, k ]
         | 
| 180 | 
            +
                          h[m[1]] = [ m[2].to_i, k ] if ( ! o) || o.first < n.first
         | 
| 181 | 
            +
                        end
         | 
| 182 | 
            +
                      end
         | 
| 183 | 
            +
             | 
| 184 | 
            +
                      h
         | 
| 185 | 
            +
                    }.values.collect { |i| i[1] }
         | 
| 186 | 
            +
                  end
         | 
| 187 | 
            +
             | 
| 188 | 
            +
                  if l = opts[:limit]
         | 
| 189 | 
            +
                    ids = ids[0, l]
         | 
| 190 | 
            +
                  end
         | 
| 191 | 
            +
             | 
| 192 | 
            +
                  ids.inject([]) do |a, i|
         | 
| 193 | 
            +
                    v = @redis.get(i)
         | 
| 194 | 
            +
                    a << Rufus::Json.decode(v) if v
         | 
| 195 | 
            +
                    a
         | 
| 196 | 
            +
                  end
         | 
| 197 | 
            +
                end
         | 
| 198 | 
            +
             | 
| 199 | 
            +
                def ids (type)
         | 
| 200 | 
            +
             | 
| 201 | 
            +
                  @redis.keys_to_a("#{type}/*").inject([]) { |a, k|
         | 
| 202 | 
            +
             | 
| 203 | 
            +
                    if m = k.match(/^[^\/]+\/([^\/]+)$/)
         | 
| 204 | 
            +
                      a << m[1]
         | 
| 205 | 
            +
                    end
         | 
| 206 | 
            +
             | 
| 207 | 
            +
                    a
         | 
| 208 | 
            +
                  }.sort
         | 
| 209 | 
            +
                end
         | 
| 210 | 
            +
             | 
| 211 | 
            +
                def purge!
         | 
| 212 | 
            +
             | 
| 213 | 
            +
                  @redis.keys_to_a('*').each { |k| @redis.del(k) }
         | 
| 214 | 
            +
                end
         | 
| 215 | 
            +
             | 
| 216 | 
            +
                #def dump (type)
         | 
| 217 | 
            +
                #  @dbs[type].dump
         | 
| 218 | 
            +
                #end
         | 
| 219 | 
            +
             | 
| 220 | 
            +
                def shutdown
         | 
| 221 | 
            +
                end
         | 
| 222 | 
            +
             | 
| 223 | 
            +
                # Mainly used by ruote's test/unit/ut_17_storage.rb
         | 
| 224 | 
            +
                #
         | 
| 225 | 
            +
                def add_type (type)
         | 
| 226 | 
            +
                end
         | 
| 227 | 
            +
             | 
| 228 | 
            +
                # Nukes a db type and reputs it (losing all the documents that were in it).
         | 
| 229 | 
            +
                #
         | 
| 230 | 
            +
                def purge_type! (type)
         | 
| 231 | 
            +
             | 
| 232 | 
            +
                  @redis.keys_to_a("#{type}/*").each { |k| @redis.del(k) }
         | 
| 233 | 
            +
                end
         | 
| 234 | 
            +
             | 
| 235 | 
            +
                protected
         | 
| 236 | 
            +
             | 
| 237 | 
            +
                #   key_for(doc)
         | 
| 238 | 
            +
                #   key_for(type, key)
         | 
| 239 | 
            +
                #
         | 
| 240 | 
            +
                def key_for (*args)
         | 
| 241 | 
            +
             | 
| 242 | 
            +
                  a = args.first
         | 
| 243 | 
            +
             | 
| 244 | 
            +
                  (a.is_a?(Hash) ? [ a['type'], a['_id'] ] : args[0, 2]).join('/')
         | 
| 245 | 
            +
                end
         | 
| 246 | 
            +
             | 
| 247 | 
            +
                #   key_rev_for(doc)
         | 
| 248 | 
            +
                #   key_rev_for(doc, rev)
         | 
| 249 | 
            +
                #   key_rev_for(type, key, rev)
         | 
| 250 | 
            +
                #
         | 
| 251 | 
            +
                def key_rev_for (*args)
         | 
| 252 | 
            +
             | 
| 253 | 
            +
                  as = nil
         | 
| 254 | 
            +
                  a = args.first
         | 
| 255 | 
            +
             | 
| 256 | 
            +
                  if a.is_a?(Hash)
         | 
| 257 | 
            +
                    as = [ a['type'], a['_id'], a['_rev'] ] if a.is_a?(Hash)
         | 
| 258 | 
            +
                    as[2] = args[1] if args[1]
         | 
| 259 | 
            +
                  else
         | 
| 260 | 
            +
                    as = args[0, 3]
         | 
| 261 | 
            +
                  end
         | 
| 262 | 
            +
             | 
| 263 | 
            +
                  as.join('/')
         | 
| 264 | 
            +
                end
         | 
| 265 | 
            +
             | 
| 266 | 
            +
                def do_get (*args)
         | 
| 267 | 
            +
             | 
| 268 | 
            +
                  d = @redis.get(key_rev_for(*args))
         | 
| 269 | 
            +
             | 
| 270 | 
            +
                  d ? Rufus::Json.decode(d) : nil
         | 
| 271 | 
            +
                end
         | 
| 272 | 
            +
             | 
| 273 | 
            +
                def to_json (doc, opts={})
         | 
| 274 | 
            +
             | 
| 275 | 
            +
                  doc = if opts[:delete]
         | 
| 276 | 
            +
                    nil
         | 
| 277 | 
            +
                  else
         | 
| 278 | 
            +
                    doc.merge('put_at' => Ruote.now_to_utc_s)
         | 
| 279 | 
            +
                  end
         | 
| 280 | 
            +
             | 
| 281 | 
            +
                  Rufus::Json.encode(doc)
         | 
| 282 | 
            +
                end
         | 
| 283 | 
            +
             | 
| 284 | 
            +
                # Don't put configuration if it's already in
         | 
| 285 | 
            +
                #
         | 
| 286 | 
            +
                # (avoid storages from trashing configuration...)
         | 
| 287 | 
            +
                #
         | 
| 288 | 
            +
                def put_configuration
         | 
| 289 | 
            +
             | 
| 290 | 
            +
                  return if get('configurations', 'engine')
         | 
| 291 | 
            +
             | 
| 292 | 
            +
                  put({ '_id' => 'engine', 'type' => 'configurations' }.merge(@options))
         | 
| 293 | 
            +
                end
         | 
| 294 | 
            +
              end
         | 
| 295 | 
            +
            end
         | 
| 296 | 
            +
            end
         | 
| 297 | 
            +
             | 
    
        data/ruote-redis.gemspec
    ADDED
    
    | @@ -0,0 +1,67 @@ | |
| 1 | 
            +
            # Generated by jeweler
         | 
| 2 | 
            +
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 | 
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
         | 
| 4 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |s|
         | 
| 7 | 
            +
              s.name = %q{ruote-redis}
         | 
| 8 | 
            +
              s.version = "2.1.10"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 | 
            +
              s.authors = ["John Mettraux"]
         | 
| 12 | 
            +
              s.date = %q{2010-06-15}
         | 
| 13 | 
            +
              s.description = %q{Redis storage for ruote (a ruby workflow engine)}
         | 
| 14 | 
            +
              s.email = %q{jmettraux@gmail.com}
         | 
| 15 | 
            +
              s.extra_rdoc_files = [
         | 
| 16 | 
            +
                "LICENSE.txt",
         | 
| 17 | 
            +
                 "README.rdoc"
         | 
| 18 | 
            +
              ]
         | 
| 19 | 
            +
              s.files = [
         | 
| 20 | 
            +
                "CHANGELOG.txt",
         | 
| 21 | 
            +
                 "LICENSE.txt",
         | 
| 22 | 
            +
                 "README.rdoc",
         | 
| 23 | 
            +
                 "Rakefile",
         | 
| 24 | 
            +
                 "TODO.txt",
         | 
| 25 | 
            +
                 "lib/ruote-redis.rb",
         | 
| 26 | 
            +
                 "lib/ruote/redis.rb",
         | 
| 27 | 
            +
                 "lib/ruote/redis/storage.rb",
         | 
| 28 | 
            +
                 "lib/ruote/redis/version.rb",
         | 
| 29 | 
            +
                 "ruote-redis.gemspec",
         | 
| 30 | 
            +
                 "test/functional_connection.rb"
         | 
| 31 | 
            +
              ]
         | 
| 32 | 
            +
              s.homepage = %q{http://github.com/jmettraux/ruote-redis}
         | 
| 33 | 
            +
              s.rdoc_options = ["--charset=UTF-8"]
         | 
| 34 | 
            +
              s.require_paths = ["lib"]
         | 
| 35 | 
            +
              s.rubyforge_project = %q{ruote}
         | 
| 36 | 
            +
              s.rubygems_version = %q{1.3.6}
         | 
| 37 | 
            +
              s.summary = %q{Redis storage for ruote (a ruby workflow engine)}
         | 
| 38 | 
            +
              s.test_files = [
         | 
| 39 | 
            +
                "test/functional_connection.rb"
         | 
| 40 | 
            +
              ]
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              if s.respond_to? :specification_version then
         | 
| 43 | 
            +
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         | 
| 44 | 
            +
                s.specification_version = 3
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
         | 
| 47 | 
            +
                  s.add_runtime_dependency(%q<ruote>, [">= 2.1.10"])
         | 
| 48 | 
            +
                  s.add_runtime_dependency(%q<redis>, [">= 2.0.1"])
         | 
| 49 | 
            +
                  s.add_development_dependency(%q<yard>, [">= 0"])
         | 
| 50 | 
            +
                  s.add_development_dependency(%q<rake>, [">= 0"])
         | 
| 51 | 
            +
                  s.add_development_dependency(%q<jeweler>, [">= 0"])
         | 
| 52 | 
            +
                else
         | 
| 53 | 
            +
                  s.add_dependency(%q<ruote>, [">= 2.1.10"])
         | 
| 54 | 
            +
                  s.add_dependency(%q<redis>, [">= 2.0.1"])
         | 
| 55 | 
            +
                  s.add_dependency(%q<yard>, [">= 0"])
         | 
| 56 | 
            +
                  s.add_dependency(%q<rake>, [">= 0"])
         | 
| 57 | 
            +
                  s.add_dependency(%q<jeweler>, [">= 0"])
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              else
         | 
| 60 | 
            +
                s.add_dependency(%q<ruote>, [">= 2.1.10"])
         | 
| 61 | 
            +
                s.add_dependency(%q<redis>, [">= 2.0.1"])
         | 
| 62 | 
            +
                s.add_dependency(%q<yard>, [">= 0"])
         | 
| 63 | 
            +
                s.add_dependency(%q<rake>, [">= 0"])
         | 
| 64 | 
            +
                s.add_dependency(%q<jeweler>, [">= 0"])
         | 
| 65 | 
            +
              end
         | 
| 66 | 
            +
            end
         | 
| 67 | 
            +
             | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            #
         | 
| 3 | 
            +
            # testing ruote-redis
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # Thu Apr  1 21:35:07 JST 2010
         | 
| 6 | 
            +
            #
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            require 'yajl' rescue require 'json'
         | 
| 9 | 
            +
            require 'rufus-json'
         | 
| 10 | 
            +
            Rufus::Json.detect_backend
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            require 'redis'
         | 
| 13 | 
            +
            require 'ruote-redis'
         | 
| 14 | 
            +
             | 
| 15 | 
            +
             | 
| 16 | 
            +
            class RrLogger
         | 
| 17 | 
            +
              def method_missing (m, *args)
         | 
| 18 | 
            +
                super if args.length != 1
         | 
| 19 | 
            +
                puts ". #{Time.now.to_f} #{Thread.current.object_id} #{args.first}"
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
             | 
| 24 | 
            +
            def new_storage (opts)
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              Ruote::Redis::RedisStorage.new(
         | 
| 27 | 
            +
                ::Redis.new(:db => 14, :thread_safe => true),
         | 
| 28 | 
            +
                #::Redis.new(:db => 14, :thread_safe => true, :logger => RrLogger.new),
         | 
| 29 | 
            +
                opts)
         | 
| 30 | 
            +
            end
         | 
| 31 | 
            +
             | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,136 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: ruote-redis
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              prerelease: false
         | 
| 5 | 
            +
              segments: 
         | 
| 6 | 
            +
              - 2
         | 
| 7 | 
            +
              - 1
         | 
| 8 | 
            +
              - 10
         | 
| 9 | 
            +
              version: 2.1.10
         | 
| 10 | 
            +
            platform: ruby
         | 
| 11 | 
            +
            authors: 
         | 
| 12 | 
            +
            - John Mettraux
         | 
| 13 | 
            +
            autorequire: 
         | 
| 14 | 
            +
            bindir: bin
         | 
| 15 | 
            +
            cert_chain: []
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            date: 2010-06-15 00:00:00 +09:00
         | 
| 18 | 
            +
            default_executable: 
         | 
| 19 | 
            +
            dependencies: 
         | 
| 20 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 21 | 
            +
              name: ruote
         | 
| 22 | 
            +
              prerelease: false
         | 
| 23 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 24 | 
            +
                requirements: 
         | 
| 25 | 
            +
                - - ">="
         | 
| 26 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 27 | 
            +
                    segments: 
         | 
| 28 | 
            +
                    - 2
         | 
| 29 | 
            +
                    - 1
         | 
| 30 | 
            +
                    - 10
         | 
| 31 | 
            +
                    version: 2.1.10
         | 
| 32 | 
            +
              type: :runtime
         | 
| 33 | 
            +
              version_requirements: *id001
         | 
| 34 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 35 | 
            +
              name: redis
         | 
| 36 | 
            +
              prerelease: false
         | 
| 37 | 
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 38 | 
            +
                requirements: 
         | 
| 39 | 
            +
                - - ">="
         | 
| 40 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 41 | 
            +
                    segments: 
         | 
| 42 | 
            +
                    - 2
         | 
| 43 | 
            +
                    - 0
         | 
| 44 | 
            +
                    - 1
         | 
| 45 | 
            +
                    version: 2.0.1
         | 
| 46 | 
            +
              type: :runtime
         | 
| 47 | 
            +
              version_requirements: *id002
         | 
| 48 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 49 | 
            +
              name: yard
         | 
| 50 | 
            +
              prerelease: false
         | 
| 51 | 
            +
              requirement: &id003 !ruby/object:Gem::Requirement 
         | 
| 52 | 
            +
                requirements: 
         | 
| 53 | 
            +
                - - ">="
         | 
| 54 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 55 | 
            +
                    segments: 
         | 
| 56 | 
            +
                    - 0
         | 
| 57 | 
            +
                    version: "0"
         | 
| 58 | 
            +
              type: :development
         | 
| 59 | 
            +
              version_requirements: *id003
         | 
| 60 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 61 | 
            +
              name: rake
         | 
| 62 | 
            +
              prerelease: false
         | 
| 63 | 
            +
              requirement: &id004 !ruby/object:Gem::Requirement 
         | 
| 64 | 
            +
                requirements: 
         | 
| 65 | 
            +
                - - ">="
         | 
| 66 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 67 | 
            +
                    segments: 
         | 
| 68 | 
            +
                    - 0
         | 
| 69 | 
            +
                    version: "0"
         | 
| 70 | 
            +
              type: :development
         | 
| 71 | 
            +
              version_requirements: *id004
         | 
| 72 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 73 | 
            +
              name: jeweler
         | 
| 74 | 
            +
              prerelease: false
         | 
| 75 | 
            +
              requirement: &id005 !ruby/object:Gem::Requirement 
         | 
| 76 | 
            +
                requirements: 
         | 
| 77 | 
            +
                - - ">="
         | 
| 78 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 79 | 
            +
                    segments: 
         | 
| 80 | 
            +
                    - 0
         | 
| 81 | 
            +
                    version: "0"
         | 
| 82 | 
            +
              type: :development
         | 
| 83 | 
            +
              version_requirements: *id005
         | 
| 84 | 
            +
            description: Redis storage for ruote (a ruby workflow engine)
         | 
| 85 | 
            +
            email: jmettraux@gmail.com
         | 
| 86 | 
            +
            executables: []
         | 
| 87 | 
            +
             | 
| 88 | 
            +
            extensions: []
         | 
| 89 | 
            +
             | 
| 90 | 
            +
            extra_rdoc_files: 
         | 
| 91 | 
            +
            - LICENSE.txt
         | 
| 92 | 
            +
            - README.rdoc
         | 
| 93 | 
            +
            files: 
         | 
| 94 | 
            +
            - CHANGELOG.txt
         | 
| 95 | 
            +
            - LICENSE.txt
         | 
| 96 | 
            +
            - README.rdoc
         | 
| 97 | 
            +
            - Rakefile
         | 
| 98 | 
            +
            - TODO.txt
         | 
| 99 | 
            +
            - lib/ruote-redis.rb
         | 
| 100 | 
            +
            - lib/ruote/redis.rb
         | 
| 101 | 
            +
            - lib/ruote/redis/storage.rb
         | 
| 102 | 
            +
            - lib/ruote/redis/version.rb
         | 
| 103 | 
            +
            - ruote-redis.gemspec
         | 
| 104 | 
            +
            - test/functional_connection.rb
         | 
| 105 | 
            +
            has_rdoc: true
         | 
| 106 | 
            +
            homepage: http://github.com/jmettraux/ruote-redis
         | 
| 107 | 
            +
            licenses: []
         | 
| 108 | 
            +
             | 
| 109 | 
            +
            post_install_message: 
         | 
| 110 | 
            +
            rdoc_options: 
         | 
| 111 | 
            +
            - --charset=UTF-8
         | 
| 112 | 
            +
            require_paths: 
         | 
| 113 | 
            +
            - lib
         | 
| 114 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 115 | 
            +
              requirements: 
         | 
| 116 | 
            +
              - - ">="
         | 
| 117 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 118 | 
            +
                  segments: 
         | 
| 119 | 
            +
                  - 0
         | 
| 120 | 
            +
                  version: "0"
         | 
| 121 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 122 | 
            +
              requirements: 
         | 
| 123 | 
            +
              - - ">="
         | 
| 124 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 125 | 
            +
                  segments: 
         | 
| 126 | 
            +
                  - 0
         | 
| 127 | 
            +
                  version: "0"
         | 
| 128 | 
            +
            requirements: []
         | 
| 129 | 
            +
             | 
| 130 | 
            +
            rubyforge_project: ruote
         | 
| 131 | 
            +
            rubygems_version: 1.3.6
         | 
| 132 | 
            +
            signing_key: 
         | 
| 133 | 
            +
            specification_version: 3
         | 
| 134 | 
            +
            summary: Redis storage for ruote (a ruby workflow engine)
         | 
| 135 | 
            +
            test_files: 
         | 
| 136 | 
            +
            - test/functional_connection.rb
         |