Background information
OBKV-Redis is a Redis-compatible persistent cache database developed based on OceanBase Database. It is supported in OceanBase Database V4.2.5 and later. OBKV-Redis aims to address the pain points of the conventional solution that combines Redis and relational database service (RDS), such as high costs, poor scalability, complex O&M and management, and difficulties in ensuring data consistency and security. OBKV-Redis achieves a P99 latency of less than 10 ms, which can meet the requirements of 80% of scenarios.
OceanBase Database Proxy (ODP) V4.3.0 and later provide a remote procedure call (RPC) service port (2885 by default) to provide proxy services for NoSQL requests. ODP V4.3.2 BP1 and later reuse the RPC service port to provide Redis Serialization Protocol (RESP) services of OBKV-Redis. ODP is fully compatible with RESP and allows you to access OBKV-Redis based on the native RESP without replacing the SDK for your business.
Characteristics
ODP supports OBKV-Redis with the following characteristics:
RPC service port: ODP supports OBKV requests and RESP connections for access.
Protocol commands: ODP supports most protocol commands of OBKV-Redis.
Native compatibility: ODP allows you to access OBKV-Redis by using native RESP clients or drivers.
Scenarios
ODP supports OBKV-Redis in the following scenarios:
Future persistent Redis service scenarios for public cloud users
RESP-based business scenarios for private cloud and open source users
Examples
This section provides examples to demonstrate how to use ODP to connect to OBKV-Redis. In the examples, the OBKV-Redis user is the root user of the test tenant in the obcluster cluster, the IP address of ODP is 10.10.10.1, and the RPC port number is 2885.
Notice
redis-cli of a version earlier than V6.0.0 supports only a connection string for connecting the default user. redis-cli V6.0.0 and later support any one of the following connection strings.
Use the default user
redis-cli -h <ODP_IP> -p <RPC_PORT> -a <user_password> # example redis-cli -h 10.10.10.1 -p 2885 -a ********-aspecifies the password of the user. The default user is specified by the rpc_redis_default_user_name parameter of ODP.Use the
--useroption to specify a userredis-cli -h <ODP_IP> -p <RPC_PORT> --user <user_name>@<tenant_name>#<cluster_name> -a <user_password> # example redis-cli -h 10.10.10.1 -p 2885 --user root@test#obcluster -a ********--userspecifies the user, and-aspecifies the password of the user. You need to configure--userand-abased on your actual situation.Use the
-aoption to specify a userODP V4.3.3 and later allow you to use the
-aoption to specify the tenant name and cluster name in the format oftenant_name#cluster_name#user_password. Ifuser_passwordis empty, specify the-aoption in the format oftenant_name#cluster_name.redis-cli -h <ODP_IP> -p <RPC_PORT> --user <user_name> -a <tenant_name>#<cluster_name>#<user_password> # example redis-cli -h 10.10.10.1 -p 2885 --user root -a test#obcluster#<user_password>Notice
When you use the
-aoption to specify the tenant name and cluster name, make sure that the--useroption does not contain the tenant name or cluster name. You can use only one of the options to specify the tenant name and cluster name.You can use the
--useroption to specify the user for connection. If the--useroption is not specified, the value of the rpc_redis_default_user_name parameter is used.If the
-aoption does not contain the#character, ODP attempts to parse the--useroption or therpc_redis_default_user_nameparameter to obtain the the tenant name and cluster name. If the parsing fails, the login fails.
Supported commands
This section describes the Redis commands supported by ODP.
String-related commands
| Command | Purpose | Syntax |
|---|---|---|
| APPEND | Appends a string to the end of the value of the specified key. | APPEND key value |
| BITCOUNT | Counts the number of bits set to 1 in the binary string. | BITCOUNT key [start end] |
| DECR | Decrements the value of the key by 1. | DECR key |
| DECRBY | Decrements the value of the key by the specified integer. | DECRBY key decrement |
| GET | Gets the value of the specified key. | GET key |
| GETBIT | Gets the bit value at the specified offset in the value of the specified key. | GETBIT key offset |
| GETRANGE | Gets the substring of the value of the specified key. | GETRANGE key start end |
| GETSET | Sets a new value for the specified key and returns the old value. | GETSET key value |
| INCR | Increments the value of the key by 1. | INCR key |
| INCRBY | Increments the value of the key by the specified integer. | INCRBY key increment |
| INCRBYFLOAT | Increments the value of the key by the specified floating-point number. | INCRBYFLOAT key increment |
| MGET | Gets the values of one or more specified keys. | MGET key [key ...] |
| MSET | Sets multiple key-value pairs. | MSET key value [key value ...] |
| PSETEX | Sets the value and validity period (in milliseconds) of the specified key. | PSETEX key milliseconds value |
| SET | Sets the value of the specified key. | SET key value (EX, PX, NX, and XX options not supported) |
| SETBIT | Sets the bit value at the specified offset in the value of the specified key. | SETBIT key offset value |
| SETEX | Sets the value and validity period (in seconds) of the specified key. | SETEX key seconds value |
| SETNX | Sets the value of the specified key if the key does not exist. | SETNX key value |
| SETRANGE | Updates the value of the specified key, starting at the specified offset. | SETRANGE key offset value |
| STRLEN | Gets the length of the value of the specified key. | STRLEN key |
Hash-related commands
| Command | Purpose | Syntax |
|---|---|---|
| HDEL | Removes one or more fields from the hash table. | HDEL key field [field ...] |
| HEXISTS | Checks whether the specified field exists in the hash table. | HEXISTS key field |
| HGET | Gets the value of the specified field in the hash table. | HGET key field |
| HGETALL | Gets all fields in the hash table and their values. | HGETALL key |
| HINCRBY | Increments the value of the specified field in the hash table by the specified integer. | HINCRBY key field increment |
| HINCRBYFLOAT | Increments the value of the specified field in the hash table by the specified floating-point number. | HINCRBYFLOAT key field increment |
| HKEYS | Gets the names of all fields in the hash table. | HKEYS key |
| HLEN | Gets the number of fields in the hash table. | HLEN key |
| HMGET | Gets the values of one or more specified fields in the hash table. | HMGET key field [field ...] |
| HMSET | Sets the values of multiple fields in the hash table. | HMSET key field value [field value ...] |
| HSET | Sets the value of the specified field in the hash table. | HSET key field value |
| HSETNX | Sets the value of the specified field in the hash table if the field does not exist. | HSETNX key field value |
| HVALS | Gets the values of all fields in the hash table. | HVALS key |
Set-related commands
| Command | Purpose | Syntax |
|---|---|---|
| SADD | Adds one or more members to the set. | SADD key member [member ...] |
| SCARD | Gets the number of members in the set. | SCARD key |
| SDIFF | Returns the difference between the given sets. | SDIFF key [key ...] |
| SDIFFSTORE | Stores the difference between the given sets in a new set. | SDIFFSTORE destination key [key ...] |
| SINTER | Returns the intersection between the given sets. | SINTER key [key ...] |
| SINTERSTORE | Stores the intersection between the given sets in a new set. | SINTERSTORE destination key [key ...] |
| SISMEMBER | Checks whether the specified member exists in the set. | SISMEMBER key member |
| SMEMBERS | Gets all members in the set. | SMEMBERS key |
| SMOVE | Moves the specified member from one set to another. | SMOVE source destination member |
| SPOP | Randomly removes and returns one or more members in the set. | SPOP key |
| SRANDMEMBER | Randomly gets one or more members from the set. | SRANDMEMBER key [count] |
| SREM | Removes one or more members from the set. | SREM key member [member ...] |
| SUNION | Returns the union of the given sets. | SUNION key [key ...] |
| SUNIONSTORE | Stores the union of the given sets in a new set. | SUNIONSTORE destination key [key ...] |
Sorted set-related commands
| Command | Purpose | Syntax |
|---|---|---|
| ZADD | Adds one or more members with the specified scores to the sorted set. | ZADD key score member [score] [member] |
| ZCARD | Gets the number of members in the sorted set. | ZCARD key |
| ZCOUNT | Gets the number of members within the specified score range in the sorted set. | ZCOUNT key min max |
| ZINCRBY | Increments the score of the specified member in the sorted set by the specified floating-point number. | ZINCRBY key increment member |
| ZINTERSTORE | Calculates the intersection between multiple sorted sets, and stores the result in a new sorted set. | ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM,MIN,MAX] |
| ZRANGE | Gets the members within the specified index range in the sorted set. | ZRANGE key start stop [WITHSCORES] |
| ZRANGEBYSCORE | Gets the members within the specified score range in the sorted set. | ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] |
| ZRANK | Gets the rank of the specified member in the sorted set. | ZRANK key member |
| ZREM | Removes one or more members from the sorted set. | ZREM key member [member ...] |
| ZREMRANGEBYRANK | Removes the members within the specified rank range from the sorted set. | ZREMRANGEBYRANK key start stop |
| ZREMRANGEBYSCORE | Removes the members within the specified score range from the sorted set. | ZREMRANGEBYSCORE key min max |
| ZREVRANGE | Returns the members within the specified index range in the sorted set, ordered by scores in descending order. | ZREVRANGE key start stop [WITHSCORES] |
| ZREVRANGEBYSCORE | Returns the members within the specified score range in the sorted set, ordered by scores in descending order. | ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] |
| ZREVRANK | Gets the reverse rank of the specified member in the sorted set. | ZREVRANK key member |
| ZSCORE | Gets the score of the specified member in the sorted set. | ZSCORE key member |
| ZUNIONSTORE | Calculates the union of multiple sorted sets, and stores the result in a new sorted set. | ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM,MIN,MAX] |
List-related commands
| Command | Purpose | Syntax |
|---|---|---|
| LINDEX | Gets the element at the specified index position in the list. | LINDEX key index |
| LSET | Modifies the element at the specified index position in the list. | LSET key index value |
| LRANGE | Gets the elements within the specified range in the list. | LRANGE key start stop |
| LTRIM | Retains the elements within the specified range in the list, and removes other elements. | LTRIM key start stop |
| LPUSH | Inserts one or more elements at the head of the list. If the list does not exist, this command creates one. | LPUSH key value [value ...] |
| LPUSHX | Inserts an element at the head of the list if the list exists. | LPUSHX key value |
| RPUSH | Inserts one or more elements at the tail of the list. If the list does not exist, this command creates one. | RPUSH key value [value ...] |
| RPUSHX | Inserts an element at the tail of the list if the list exists. | RPUSHX key value |
| LPOP | Removes and returns the first element in the list. | LPOP key |
| RPOP | Removes and returns the last element in the list. | RPOP key |
| LREM | Removes the specified number of specified elements from the list. | LREM key count value |
| LINSERT | Inserts an element before or after the specified element in the list. | LINSERT key BEFORE AFTER pivot value |
| LLEN | Gets the length of the list. | LLEN key |
Key management commands
| Command | Purpose | Syntax |
|---|---|---|
| TYPE | Gets the data type of the specified key. | TYPE key [value |member] |
| DEL | Removes one or more keys from the database. A key is ignored if it does not exist. | DEL key [key …] |
| EXISTS | Checks whether the specified one or more keys exist. | EXISTS key [key …] |
| TTL | Sets the remaining time to live of one or more keys. | TTL key [key ...] |
Server commands
| Command | Purpose | Syntax |
|---|---|---|
| ECHO | Returns the input parameters. | ECHO message |
| PING | Checks whether the server is active. | PING |
| QUIT | Closes the connection with the server. | QUIT |
| SELECT | Switches to the specified database. | SELECT db |
| AUTH | Authenticates the login. | AUTH [password] |
Client commands
ODP V4.3.3 and later support the following OBKV-Redis client commands.
| Command | Purpose | Syntax |
|---|---|---|
| CLIENT LIST | Returns all the connected clients. | CLIENT LIST |
| CLIENT SETINFO | Returns the database version and name used to establish the connection. | CLIENT SETINFO LIB-NAME jedis /CLIENT SETINFO LIB-VER 5.3.2 |
| CLIENT ID | Returns the ID of the current client connection. | CLIENT ID |
| CLIENT INFO | Returns the information about the current client connection. | CLIENT INFO |
| CLIENT SETNAME/GETNAME | Sets the name of the current client connection. | CLIENT SETNAME/GETNAME |
| INFO | Returns the information about the current ODP. | INFO |
| MONITOR | Returns the Redis commands received by the current ODP. | MONITOR |
Note
The output of the
INFOcommand in OBKV-Redis is a subset of that in Redis.The
MONITORandCLIENT LISTcommands in OBKV-Redis monitor only the commands and client connections received by the current ODP.