redis 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  # redis-rb
2
2
 
3
- A Ruby client library for the [Redis](http://code.google.com/p/redis) key-value storage system.
3
+ A Ruby client library for the [Redis](http://code.google.com/p/redis) key-value store.
4
4
 
5
5
  ## Information about Redis
6
6
 
@@ -11,64 +11,102 @@ Redis is a key-value store with some interesting features:
11
11
 
12
12
  See [the Redis homepage](http://code.google.com/p/redis/wiki/README) for more information.
13
13
 
14
- ## Usage
15
-
16
- For all types redis-rb needs redis-server running to connect to.
17
-
18
- ### Simple Key Value Strings can be used like a large Ruby Hash (Similar to Memcached, Tokyo Cabinet)
19
-
20
- require 'redis'
21
- r = Redis.new
22
- r['key_one'] = "value_one"
23
- r['key_two'] = "value_two"
24
-
25
- r['key_one] # => "value_one"
26
-
27
- ### Redis only stores strings. To store Objects, Array or Hashes, you must [Marshal](http://ruby-doc.org/core/classes/Marshal.html)
28
-
29
- require 'redis'
30
- r = Redis.new
31
-
32
- example_hash_to_store = {:name => "Alex", :age => 21, :password => "letmein", :cool => false}
33
-
34
- r['key_one'] = Marshal.dump(example_hash_to_store)
35
-
36
- hash_returned_from_redis = Marshal.load(r['key_one'])
37
-
38
- ### Alternatively you can use the [Redis Commands](http://code.google.com/p/redis/wiki/CommandReference)
39
-
40
- require 'redis'
41
- r = Redis.new
42
- r.set 'key_one', 'value_one'
43
- r.get 'key_one' # => 'value_one'
44
-
45
- # Using Redis list objects
46
- # Push an object to the head of the list. Creates the list if it doesn't allready exsist.
47
-
48
- blog_hash = {:title => "Redis Rules!", :body => "Ok so, like why, well like, RDBMS is like....", :created_at => Time.now.to_i}
49
- r.lpush 'all_blogs', Marshal.dump(blog_hash)
50
-
51
- # Get a range of strings from the all_blogs list. Similar to offset and limit in SQL (-1, means the last one)
52
-
53
- r.lrange 'all_blogs', 0, -1
54
-
55
- ### Multiple commands at once!
56
-
57
- require 'redis'
58
- r = Redis.new
59
- r.multi do
60
- r.set 'foo', 'bar'
61
- r.incr 'baz'
62
- end
14
+ ## Getting started
63
15
 
64
- ## Contributing
16
+ You can connect to Redis by instantiating the `Redis` class:
17
+
18
+ require "redis"
19
+
20
+ redis = Redis.new
21
+
22
+ This assumes Redis was started with default values listening on `localhost`, port 6379. If you need to connect to a remote server or a different port, try:
23
+
24
+ redis = Redis.new(:host => "10.0.1.1", :port => 6380)
25
+
26
+ Once connected, you can start running commands against Redis:
27
+
28
+ >> redis.set "foo", "bar"
29
+ => "OK"
30
+
31
+ >> redis.get "foo"
32
+ => "bar"
33
+
34
+ >> redis.sadd "users", "albert"
35
+ => true
36
+
37
+ >> redis.sadd "users", "bernard"
38
+ => true
39
+
40
+ >> redis.sadd "users", "charles"
41
+ => true
42
+
43
+ How many users?
44
+
45
+ >> redis.scard "users"
46
+ => 3
47
+
48
+ Is `albert` a user?
49
+
50
+ >> redis.sismember "users", "albert"
51
+ => true
52
+
53
+ Is `isabel` a user?
54
+
55
+ >> redis.sismember "users", "isabel"
56
+ => false
57
+
58
+ Handle groups:
65
59
 
66
- See the build on [RunCodeRun](http://runcoderun.com/rsanheim/redis-rb).
60
+ >> redis.sadd "admins", "albert"
61
+ => true
67
62
 
68
- If you would like to submit patches, you'll need Redis in your development environment:
63
+ >> redis.sadd "admins", "isabel"
64
+ => true
69
65
 
70
- rake redis:install
66
+ Users who are also admins:
71
67
 
72
- ## Examples
68
+ >> redis.sinter "users", "admins"
69
+ => ["albert"]
70
+
71
+ Users who are not admins:
72
+
73
+ >> redis.sdiff "users", "admins"
74
+ => ["bernard", "charles"]
75
+
76
+ Admins who are not users:
77
+
78
+ >> redis.sdiff "admins", "users"
79
+ => ["isabel"]
80
+
81
+ All users and admins:
82
+
83
+ >> redis.sunion "admins", "users"
84
+ => ["albert", "bernard", "charles", "isabel"]
85
+
86
+
87
+ ## Storing objects
88
+
89
+ Redis only stores strings as values. If you want to store an object inside a key, you can use a serialization/deseralization mechanism like JSON:
90
+
91
+ >> redis.set "foo", [1, 2, 3].to_json
92
+ => OK
93
+
94
+ >> JSON.parse(redis.get("foo"))
95
+ => [1, 2, 3]
96
+
97
+ ## Executing multiple commands atomically
98
+
99
+ You can use `MULTI/EXEC` to run arbitrary commands in an atomic fashion:
100
+
101
+ redis.multi do
102
+ redis.set "foo", "bar"
103
+ redis.incr "baz"
104
+ end
105
+
106
+ ## More info
107
+
108
+ Check the [Redis Command Reference](http://code.google.com/p/redis/wiki/CommandReference) or check the tests to find out how to use this client.
109
+
110
+ ## Contributing
73
111
 
74
- Check the `examples/` directory. You'll need to have an instance of `redis-server` running before running the examples.
112
+ [Fork the project](http://github.com/ezmobius/redis-rb) and send pull requests. You can also ask for help at `#redis` on Freenode.
@@ -1,7 +1,7 @@
1
1
  require 'socket'
2
2
 
3
3
  class Redis
4
- VERSION = "1.0.4"
4
+ VERSION = "1.0.5"
5
5
 
6
6
  def self.new(*attrs)
7
7
  Client.new(*attrs)
@@ -41,7 +41,8 @@ class Redis
41
41
  MULTI_BULK_COMMANDS = {
42
42
  "mset" => true,
43
43
  "msetnx" => true,
44
- "hset" => true
44
+ "hset" => true,
45
+ "hmset" => true
45
46
  }
46
47
 
47
48
  BOOLEAN_PROCESSOR = lambda{|r| r == 1 }
@@ -167,6 +168,10 @@ class Redis
167
168
  set(key, value)
168
169
  end
169
170
 
171
+ def get(key)
172
+ call_command([:get, key])
173
+ end
174
+
170
175
  def set(key, value, ttl = nil)
171
176
  if ttl
172
177
  deprecated("set with an expire", :set_with_expire, caller[0])
@@ -475,8 +480,14 @@ class Redis
475
480
  end
476
481
 
477
482
 
478
- def get_size(string)
479
- string.respond_to?(:bytesize) ? string.bytesize : string.size
483
+ if "".respond_to?(:bytesize)
484
+ def get_size(string)
485
+ string.bytesize
486
+ end
487
+ else
488
+ def get_size(string)
489
+ string.size
490
+ end
480
491
  end
481
492
 
482
493
  private
@@ -72,7 +72,7 @@ class Redis
72
72
  def delete_cloud!
73
73
  @ring.nodes.each do |red|
74
74
  red.keys("*").each do |key|
75
- red.delete key
75
+ red.del key
76
76
  end
77
77
  end
78
78
  end
@@ -107,6 +107,10 @@ class Redis
107
107
  kbn
108
108
  end
109
109
  end
110
+
111
+ def type(key)
112
+ method_missing(:type, key)
113
+ end
110
114
  end
111
115
  end
112
116
 
@@ -14,7 +14,6 @@ class Redis
14
14
  def execute
15
15
  return if @commands.empty?
16
16
  @redis.call_command(@commands)
17
- @commands.clear
18
17
  end
19
18
  end
20
19
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 4
9
- version: 1.0.4
8
+ - 5
9
+ version: 1.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ezra Zygmuntowicz
@@ -19,7 +19,7 @@ autorequire: redis
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2010-04-05 00:00:00 -07:00
22
+ date: 2010-04-21 00:00:00 -03:00
23
23
  default_executable:
24
24
  dependencies: []
25
25