You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-2Lines changed: 15 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -919,6 +919,8 @@ auto pipe = redis.pipeline();
919
919
920
920
When creating a `Pipeline` object, `Redis::pipeline` method creates a new connection to Redis server. This connection is NOT picked from the connection pool, but a newly created connection. This connection has the same `ConnectionOptions` with other connections in the connection pool. `Pipeline` object maintains the new connection, and all piped commands are sent through this connection.
921
921
922
+
**NOTE**: Creating a `Pipeline` object is NOT cheap, since it creates a new connection. So you'd better reuse the `Pipeline` as much as possible.
923
+
922
924
#### Send Commands
923
925
924
926
You can send Redis commands through the `Pipeline` object. Just like the `Redis` class, `Pipeline` has one or more (overloaded) methods for each Redis command. However, you CANNOT get the replies until you call `Pipeline::exec`. So these methods do NOT return the reply, instead they return the `Pipeline` object itself. And you can chain these methods calls.
@@ -1003,6 +1005,8 @@ auto tx = redis.transaction();
1003
1005
1004
1006
As the `Pipeline` class, `Transaction` maintains a newly created connection to Redis. This connection has the same `ConnectionOptions` with the `Redis` object.
1005
1007
1008
+
**NOTE**: Creating a `Transaction` object is NOT cheap, since it creates a new connection. So you'd better reuse the `Transaction` as much as possible.
1009
+
1006
1010
Also you don't need to send [MULTI](https://redis.io/commands/multi) command to Redis. `Transaction` will do that for you automatically.
1007
1011
1008
1012
#### Send Commands
@@ -1077,7 +1081,7 @@ auto redis = Redis("tcp://127.0.0.1");
1077
1081
// Create a transaction.
1078
1082
auto tx = redis.transaction();
1079
1083
1080
-
// Create a Redis object from the Transaction object, which share a single connection.
1084
+
// Create a Redis object from the Transaction object. Both objects share the same connection.
1081
1085
auto r = tx.redis();
1082
1086
1083
1087
// If the watched key has been modified by other clients, the transaction might fail.
@@ -1166,7 +1170,10 @@ As we mentioned, `RedisCluster`'s interfaces are similar to `Redis`. It supports
1166
1170
- Not support commands without key as argument, e.g. [PING](https://redis.io/commands/ping), [INFO](https://redis.io/commands/info).
1167
1171
- Not support Lua script without key parameters.
1168
1172
1169
-
`RedisCluster` does NOT support these interfaces, because it has no idea to which node these commands should be sent.
1173
+
`RedisCluster` does NOT have built-in methods to send these commands or Lua scripts. Since there's no key parameter, `RedisCluster` has no idea to which node these commands should be sent. However there're 2 workarounds for this problem:
1174
+
1175
+
- If you want to send these commands to a specific node, you can create a `Redis` object with that node's host and port, and use the `Redis` object to do the work.
1176
+
- Instead of host and port, you can also call `Redis RedisCluster::redis(const StringView &hash_tag)` to create a `Redis` object with a hash-tag specifying the node. In this case, the returned `Redis` object creates a new connection to Redis server.
1170
1177
1171
1178
Also you can use the [hash tags](https://redis.io/topics/cluster-spec#keys-hash-tags) to send multiple-key commands.
1172
1179
@@ -1218,6 +1225,12 @@ auto replies = pipe.incr("{counter}:1").incr("{counter}:2").exec();
1218
1225
// Transaction.
1219
1226
auto tx = redis_cluster.transaction("key");
1220
1227
replies = tx.incr("key").get("key").exec();
1228
+
1229
+
// Create a Redis object with hash-tag.
1230
+
auto r = redis_cluster.redis("hash-tag");
1231
+
1232
+
// And send command without key parameter to the server.
0 commit comments