redis 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/CHANGELOG.md +34 -0
- data/README.md +190 -0
- data/Rakefile +194 -79
- data/benchmarking/logging.rb +62 -0
- data/benchmarking/pipeline.rb +51 -0
- data/benchmarking/speed.rb +21 -0
- data/benchmarking/suite.rb +24 -0
- data/benchmarking/thread_safety.rb +38 -0
- data/benchmarking/worker.rb +71 -0
- data/examples/basic.rb +15 -0
- data/examples/dist_redis.rb +43 -0
- data/examples/incr-decr.rb +17 -0
- data/examples/list.rb +26 -0
- data/examples/pubsub.rb +31 -0
- data/examples/sets.rb +36 -0
- data/examples/unicorn/config.ru +3 -0
- data/examples/unicorn/unicorn.rb +20 -0
- data/lib/redis.rb +612 -156
- data/lib/redis/client.rb +98 -57
- data/lib/redis/connection.rb +9 -134
- data/lib/redis/connection/command_helper.rb +45 -0
- data/lib/redis/connection/hiredis.rb +49 -0
- data/lib/redis/connection/registry.rb +12 -0
- data/lib/redis/connection/ruby.rb +131 -0
- data/lib/redis/connection/synchrony.rb +125 -0
- data/lib/redis/distributed.rb +161 -5
- data/lib/redis/pipeline.rb +6 -0
- data/lib/redis/version.rb +3 -0
- data/redis.gemspec +24 -0
- data/test/commands_on_hashes_test.rb +32 -0
- data/test/commands_on_lists_test.rb +60 -0
- data/test/commands_on_sets_test.rb +78 -0
- data/test/commands_on_sorted_sets_test.rb +109 -0
- data/test/commands_on_strings_test.rb +80 -0
- data/test/commands_on_value_types_test.rb +88 -0
- data/test/connection_handling_test.rb +87 -0
- data/test/db/.gitignore +1 -0
- data/test/distributed_blocking_commands_test.rb +53 -0
- data/test/distributed_commands_on_hashes_test.rb +12 -0
- data/test/distributed_commands_on_lists_test.rb +24 -0
- data/test/distributed_commands_on_sets_test.rb +85 -0
- data/test/distributed_commands_on_strings_test.rb +50 -0
- data/test/distributed_commands_on_value_types_test.rb +73 -0
- data/test/distributed_commands_requiring_clustering_test.rb +148 -0
- data/test/distributed_connection_handling_test.rb +25 -0
- data/test/distributed_internals_test.rb +18 -0
- data/test/distributed_key_tags_test.rb +53 -0
- data/test/distributed_persistence_control_commands_test.rb +24 -0
- data/test/distributed_publish_subscribe_test.rb +101 -0
- data/test/distributed_remote_server_control_commands_test.rb +31 -0
- data/test/distributed_sorting_test.rb +21 -0
- data/test/distributed_test.rb +60 -0
- data/test/distributed_transactions_test.rb +34 -0
- data/test/encoding_test.rb +16 -0
- data/test/error_replies_test.rb +53 -0
- data/test/helper.rb +145 -0
- data/test/internals_test.rb +157 -0
- data/test/lint/hashes.rb +114 -0
- data/test/lint/internals.rb +41 -0
- data/test/lint/lists.rb +93 -0
- data/test/lint/sets.rb +66 -0
- data/test/lint/sorted_sets.rb +167 -0
- data/test/lint/strings.rb +137 -0
- data/test/lint/value_types.rb +84 -0
- data/test/persistence_control_commands_test.rb +22 -0
- data/test/pipelining_commands_test.rb +123 -0
- data/test/publish_subscribe_test.rb +158 -0
- data/test/redis_mock.rb +80 -0
- data/test/remote_server_control_commands_test.rb +63 -0
- data/test/sorting_test.rb +44 -0
- data/test/synchrony_driver.rb +57 -0
- data/test/test.conf +8 -0
- data/test/thread_safety_test.rb +30 -0
- data/test/transactions_test.rb +100 -0
- data/test/unknown_commands_test.rb +14 -0
- data/test/url_param_test.rb +60 -0
- metadata +128 -19
- data/README.markdown +0 -129
data/README.markdown
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
# redis-rb
|
2
|
-
|
3
|
-
A Ruby client library for the [Redis](http://code.google.com/p/redis) key-value store.
|
4
|
-
|
5
|
-
## A note about versions
|
6
|
-
|
7
|
-
Versions *1.0.x* target all versions of Redis. You have to use this one if you are using Redis < 1.2.
|
8
|
-
|
9
|
-
Version *2.0* is a big refactoring of the previous version and makes little effort to be
|
10
|
-
backwards-compatible when it shouldn't. It does not support Redis' original protocol, favoring the
|
11
|
-
new, binary-safe one. You should be using this version if you're running Redis 1.2+.
|
12
|
-
|
13
|
-
## Information about Redis
|
14
|
-
|
15
|
-
Redis is a key-value store with some interesting features:
|
16
|
-
|
17
|
-
1. It's fast.
|
18
|
-
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.
|
19
|
-
|
20
|
-
See [the Redis homepage](http://code.google.com/p/redis/wiki/README) for more information.
|
21
|
-
|
22
|
-
## Getting started
|
23
|
-
|
24
|
-
You can connect to Redis by instantiating the `Redis` class:
|
25
|
-
|
26
|
-
require "redis"
|
27
|
-
|
28
|
-
redis = Redis.new
|
29
|
-
|
30
|
-
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:
|
31
|
-
|
32
|
-
redis = Redis.new(:host => "10.0.1.1", :port => 6380)
|
33
|
-
|
34
|
-
Once connected, you can start running commands against Redis:
|
35
|
-
|
36
|
-
>> redis.set "foo", "bar"
|
37
|
-
=> "OK"
|
38
|
-
|
39
|
-
>> redis.get "foo"
|
40
|
-
=> "bar"
|
41
|
-
|
42
|
-
>> redis.sadd "users", "albert"
|
43
|
-
=> true
|
44
|
-
|
45
|
-
>> redis.sadd "users", "bernard"
|
46
|
-
=> true
|
47
|
-
|
48
|
-
>> redis.sadd "users", "charles"
|
49
|
-
=> true
|
50
|
-
|
51
|
-
How many users?
|
52
|
-
|
53
|
-
>> redis.scard "users"
|
54
|
-
=> 3
|
55
|
-
|
56
|
-
Is `albert` a user?
|
57
|
-
|
58
|
-
>> redis.sismember "users", "albert"
|
59
|
-
=> true
|
60
|
-
|
61
|
-
Is `isabel` a user?
|
62
|
-
|
63
|
-
>> redis.sismember "users", "isabel"
|
64
|
-
=> false
|
65
|
-
|
66
|
-
Handle groups:
|
67
|
-
|
68
|
-
>> redis.sadd "admins", "albert"
|
69
|
-
=> true
|
70
|
-
|
71
|
-
>> redis.sadd "admins", "isabel"
|
72
|
-
=> true
|
73
|
-
|
74
|
-
Users who are also admins:
|
75
|
-
|
76
|
-
>> redis.sinter "users", "admins"
|
77
|
-
=> ["albert"]
|
78
|
-
|
79
|
-
Users who are not admins:
|
80
|
-
|
81
|
-
>> redis.sdiff "users", "admins"
|
82
|
-
=> ["bernard", "charles"]
|
83
|
-
|
84
|
-
Admins who are not users:
|
85
|
-
|
86
|
-
>> redis.sdiff "admins", "users"
|
87
|
-
=> ["isabel"]
|
88
|
-
|
89
|
-
All users and admins:
|
90
|
-
|
91
|
-
>> redis.sunion "admins", "users"
|
92
|
-
=> ["albert", "bernard", "charles", "isabel"]
|
93
|
-
|
94
|
-
|
95
|
-
## Storing objects
|
96
|
-
|
97
|
-
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:
|
98
|
-
|
99
|
-
>> redis.set "foo", [1, 2, 3].to_json
|
100
|
-
=> OK
|
101
|
-
|
102
|
-
>> JSON.parse(redis.get("foo"))
|
103
|
-
=> [1, 2, 3]
|
104
|
-
|
105
|
-
## Executing multiple commands atomically
|
106
|
-
|
107
|
-
You can use `MULTI/EXEC` to run arbitrary commands in an atomic fashion:
|
108
|
-
|
109
|
-
redis.multi do
|
110
|
-
redis.set "foo", "bar"
|
111
|
-
redis.incr "baz"
|
112
|
-
end
|
113
|
-
|
114
|
-
## Multithreaded Operation
|
115
|
-
|
116
|
-
To use redis safely in a multithreaded environment, be sure to initialize the client with :thread_safe=>true
|
117
|
-
|
118
|
-
Redis.new(:thread_safe=>true)
|
119
|
-
|
120
|
-
See the tests and benchmarks for examples.
|
121
|
-
|
122
|
-
|
123
|
-
## More info
|
124
|
-
|
125
|
-
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.
|
126
|
-
|
127
|
-
## Contributing
|
128
|
-
|
129
|
-
[Fork the project](http://github.com/ezmobius/redis-rb) and send pull requests. You can also ask for help at `#redis-rb` on Freenode.
|