lib/memcached-server/server.rb
# Runs a valid memcache command.
# Depends on MemcachedServer::Memcache method names.
# In some cases, when the #send method is used, the corresponding
# MemcachedServer::Memcache method must be equal to valid_command[:name] 
# 
# @param connection [TCPSocket] Client's socket
# @param valid_command [MatchData] It encapsulates all the results of a valid command pattern match
# @return [Boolean] false if valid_command[:name] != END else true
Runs a valid memcache command.
Depends on MemcachedServer::Memcache method names.
In some cases, when the #send method is used, the corresponding
MemcachedServer::Memcache method must be equal to valid_command[:name]
Runs a valid memcache command . Depends on MemcachedServer :: Memcache method names . In some cases when the #send method is used the corresponding MemcachedServer :: Memcache method must be equal to valid_command [ : name ]
def run_command(connection, valid_command)
            name = valid_command[:name]
            case name
            when 'set', 'add', 'replace'
                key = valid_command[:key]
                flags = valid_command[:flags].to_i
                exptime = valid_command[:exptime].to_i
                bytes = valid_command[:bytes].to_i
                noreply = !valid_command[:noreply].nil?
                data = self.read_bytes(connection, bytes)
                reply = @mc.send(name.to_sym, key, flags, exptime, bytes, data) unless data.nil?()
                connection.puts(reply) unless noreply || reply.nil?()
                return false
            when 'append', 'prepend'
                key = valid_command[:key]
                bytes = valid_command[:bytes].to_i
                data = self.read_bytes(connection, bytes)
                reply = @mc.send(name.to_sym, key, bytes, data) unless data.nil?()
                connection.puts(reply) unless noreply || reply.nil?()
                return false
            when 'cas'
                key = valid_command[:key]
                flags = valid_command[:flags].to_i
                exptime = valid_command[:exptime].to_i
                bytes = valid_command[:bytes].to_i
                noreply = !valid_command[:noreply].nil?
                data = self.read_bytes(connection, bytes)
                cas_id = valid_command[:cas_id].to_i()
                reply = @mc.cas(key, flags, exptime, bytes, cas_id, data) unless data.nil?()
                connection.puts(reply) unless noreply || reply.nil?()
                return false
            when 'get'
                keys = valid_command[:keys].split(' ')
                items = @mc.get(keys)
                for item in items
                    connection.puts(Reply::GET % [item.key, item.flags, item.bytes, item.data_block]) if item
                    connection.puts(Reply::END_)
                end
                return false
            when 'gets'
                keys = valid_command[:keys].split(' ')
                items = @mc.get(keys)
                for item in items
                    connection.puts(Reply::GETS % [item.key, item.flags, item.bytes, item.cas_id, item.data_block]) if item
                    connection.puts(Reply::END_)
                end
                return false
            else
                return true
            end
        end
def run_command ( connection , valid_command ) name = valid_command [ :name ] case name when 'set' , 'add' , 'replace' key = valid_command [ :key ] flags = valid_command [ :flags ] . to_i exptime = valid_command [ :exptime ] . to_i bytes = valid_command [ :bytes ] . to_i noreply = ! valid_command [ :noreply ] . nil? data = self . read_bytes ( connection , bytes ) reply = @mc . send ( name . to_sym , key , flags , exptime , bytes , data ) unless data . nil? ( ) connection . puts ( reply ) unless noreply || reply . nil? ( ) return false when 'append' , 'prepend' key = valid_command [ :key ] bytes = valid_command [ :bytes ] . to_i data = self . read_bytes ( connection , bytes ) reply = @mc . send ( name . to_sym , key , bytes , data ) unless data . nil? ( ) connection . puts ( reply ) unless noreply || reply . nil? ( ) return false when 'cas' key = valid_command [ :key ] flags = valid_command [ :flags ] . to_i exptime = valid_command [ :exptime ] . to_i bytes = valid_command [ :bytes ] . to_i noreply = ! valid_command [ :noreply ] . nil? data = self . read_bytes ( connection , bytes ) cas_id = valid_command [ :cas_id ] . to_i ( ) reply = @mc . cas ( key , flags , exptime , bytes , cas_id , data ) unless data . nil? ( ) connection . puts ( reply ) unless noreply || reply . nil? ( ) return false when 'get' keys = valid_command [ :keys ] . split ( ' ' ) items = @mc . get ( keys ) for item in items connection . puts ( Reply :: GET % [ item . key , item . flags , item . bytes , item . data_block ] ) if item connection . puts ( Reply :: END_ ) end return false when 'gets' keys = valid_command [ :keys ] . split ( ' ' ) items = @mc . get ( keys ) for item in items connection . puts ( Reply :: GETS % [ item . key , item . flags , item . bytes , item . cas_id , item . data_block ] ) if item connection . puts ( Reply :: END_ ) end return false else return true end end
Runs a valid memcache command.
Runs a valid memcache command .
# END command stops run
false if valid_command[:name] != END else true
false if valid_command [ : name ] ! = END else true
Boolean
connection
None
valid_command
It encapsulates all the results of a valid command pattern match
It encapsulates all the results of a valid command pattern match