README.markdown in redis-0.2.0 vs README.markdown in redis-1.0.0

- old
+ new

@@ -1,36 +1,74 @@ # redis-rb -A ruby client library for the redis key value storage system. +A Ruby client library for the [Redis](http://code.google.com/p/redis) key-value storage system. -## Information about redis +## Information about Redis -Redis is a key value store with some interesting features: +Redis is a key-value store with some interesting features: + 1. It's fast. -2. Keys are strings but values can have types of "NONE", "STRING", "LIST", or "SET". List's can be atomically push'd, pop'd, lpush'd, lpop'd and indexed. This allows you to store things like lists of comments under one key while retaining the ability to append comments without reading and putting back the whole list. +2. Keys are strings but values are typed. Currently Redis supports strings, lists, sets, sorted sets and hashes. [Atomic operations](http://code.google.com/p/redis/wiki/CommandReference) can be done on all of these types. -See [redis on code.google.com](http://code.google.com/p/redis/wiki/README) for more information. +See [the Redis homepage](http://code.google.com/p/redis/wiki/README) for more information. -See the build on [RunCodeRun](http://runcoderun.com/rsanheim/redis-rb) +## Usage -## Dependencies +For all types redis-rb needs redis-server running to connect to. -1. rspec - - sudo gem install rspec +### Simple Key Value Strings can be used like a large Ruby Hash (Similar to Memcached, Tokyo Cabinet) + + require 'redis' + r = Redis.new + r['key_one'] = "value_one" + r['key_two'] = "value_two" + + r['key_one] # => "value_one" -2. redis - +### Redis only stores strings. To store Objects, Array or Hashes, you must [Marshal](http://ruby-doc.org/core/classes/Marshal.html) + + require 'redis' + r = Redis.new + + example_hash_to_store = {:name => "Alex", :age => 21, :password => "letmein", :cool => false} + + r['key_one'] = Marshal.dump(example_hash_to_store) + + hash_returned_from_redis = Marshal.load(r['key_one']) + +### Alternatively you can use the [Redis Commands](http://code.google.com/p/redis/wiki/CommandReference) + + require 'redis' + r = Redis.new + r.set 'key_one', 'value_one' + r.get 'key_one' # => 'value_one' + + # Using Redis list objects + # Push an object to the head of the list. Creates the list if it doesn't allready exsist. + + blog_hash = {:title => "Redis Rules!", :body => "Ok so, like why, well like, RDBMS is like....", :created_at => Time.now.to_i} + r.lpush 'all_blogs', Marshal.dump(blog_hash) + + # Get a range of strings from the all_blogs list. Similar to offset and limit in SQL (-1, means the last one) + + r.lrange 'all_blogs', 0, -1 - rake redis:install +### Multiple commands at once! -2. dtach - + require 'redis' + r = Redis.new + r.multi do + r.set 'foo', 'bar' + r.incr 'baz' + end - rake dtach:install +## Contributing -3. git - git is the new black. +See the build on [RunCodeRun](http://runcoderun.com/rsanheim/redis-rb). -## Setup +If you would like to submit patches, you'll need Redis in your development environment: -Use the tasks mentioned above (in Dependencies) to get your machine setup. + rake redis:install ## Examples -Check the examples/ directory. *Note* you need to have redis-server running first. +Check the `examples/` directory. You'll need to have an instance of `redis-server` running before running the examples. \ No newline at end of file