README.md in redis-client-0.2.1 vs README.md in redis-client-0.3.0
- old
+ new
@@ -143,23 +143,72 @@
```
Hashes are flatenned as well:
```ruby
-redis.call("HMSET", "hash", foo: 1, bar: 2)
-redis.call("SET", "key", "value", ex: 5)
+redis.call("HMSET", "hash", { "foo" => "1", "bar" => "2" })
```
is equivalent to:
```ruby
redis.call("HMSET", "hash", "foo", "1", "bar", "2")
-redis.call("SET", "key", "value", "ex", "5")
```
Any other type requires the caller to explictly cast the argument as a string.
+Keywords arguments are treated as Redis command flags:
+
+```ruby
+redis.call("SET", "mykey", "value", nx: true, ex: 60)
+redis.call("SET", "mykey", "value", nx: false, ex: nil)
+```
+
+is equivalent to:
+
+```ruby
+redis.call("SET", "mykey", "value", "nx", "ex", "60")
+redis.call("SET", "mykey", "value")
+```
+
+If flags are built dynamically, you'll have to explictly pass them as keyword arguments with `**`:
+
+```ruby
+flags = {}
+flags[:nx] = true if something?
+redis.call("SET", "mykey", "value", **flags)
+```
+
+**Important Note**: because of the keyword argument semantic change between Ruby 2 and Ruby 3,
+unclosed hash literals with string keys may be interpreted differently:
+
+```ruby
+redis.call("HMSET", "hash", "foo" => "bar")
+```
+
+On Ruby 2 `"foo" => "bar"` will be passed as a postional argument, but on Ruby 3 it will be interpreted as keyword
+arguments. To avoid such problem, make sure to enclose hash literals:
+
+```ruby
+redis.call("HMSET", "hash", { "foo" => "bar" })
+```
+
+### Commands return values
+
+Contrary to the `redis` gem, `redis-client` doesn't do any type casting on the return value of commands.
+
+If you wish to cast the return value, you can pass a block to the `#call` familly of methods:
+
+```ruby
+redis.call("INCR", "counter") # => 1
+redis.call("GET", "counter") # => "1"
+redis.call("GET", "counter", &:to_i) # => 1
+
+redis.call("EXISTS", "counter") # => 1
+redis.call("EXISTS", "counter") { |c| c > 0 } # => true
+```
+
### Blocking commands
For blocking commands such as `BRPOP`, a custom timeout duration can be passed as first argument of the `#blocking_call` method:
```
@@ -334,9 +383,27 @@
```ruby
redis_config = RedisClient.config(reconnect_attempts: [0, 0.05, 0.1])
redis = redis_config.new_client
redis.call("GET", "counter") # Will be retried up to 3 times.
redis.call_once("INCR", "counter") # Won't be retried.
+```
+
+### Drivers
+
+`redis-client` ships with two connection implementations, a `hiredis` binding and a pure Ruby implementation.
+
+The hiredis binding is only available on Linux, macOS and other POSIX platforms. When available it is the default.
+
+The default driver can be set through `RedisClient.default_driver=`:
+
+```ruby
+RedisClient.default_driver = :ruby
+```
+
+You can also select the driver on a per connection basis:
+
+```ruby
+redis_config = RedisClient.config(driver: :ruby, ...)
```
## Notable differences with the `redis` gem
### Thread Safety