5.3 KiB
Migration guide
Libkv can replace both libraries hiredis and hiredis-cluster.
This guide highlights which APIs that have changed and what you need to do when migrating to libkv.
The general actions needed are:
- Replace the prefix
rediswithkvin API usages. - Replace the term
SSLwithTLSin API usages for secure communication. - Update include paths depending on your previous installation.
All
libkvheaders are now found underinclude/kv/. - Update used build options, e.g.
USE_TLSreplacesUSE_SSL.
Migrating from hiredis v1.2.0
The type sds is removed from the public API.
Renamed API functions
redisAsyncSetConnectCallbackNCis renamed tokvAsyncSetConnectCallback.
Removed API functions
redisFormatSdsCommandArgvremoved from API. Can be replaced withkvFormatCommandArgv.redisFreeSdsCommandremoved since thesdstype is for internal use only.redisAsyncSetConnectCallbackis removed, but can be replaced withkvAsyncSetConnectCallbackwhich accepts the non-const callback function prototype.
Renamed API defines
HIREDIS_MAJORis renamed toLIBKV_VERSION_MAJOR.HIREDIS_MINORis renamed toLIBKV_VERSION_MINOR.HIREDIS_PATCHis renamed toLIBKV_VERSION_PATCH.
Removed API defines
HIREDIS_SONAMEremoved.
Migrating from hiredis-cluster 0.14.0
- The cluster client initiation procedure is changed and
kvClusterOptionsshould be used to specify options when creating a context. See documentation for configuration examples when using the Synchronous API or the Asynchronous API. The examples directory also contains some common client initiation examples that might be helpful. - The default command to update the internal slot map is changed to
CLUSTER SLOTS.CLUSTER NODEScan be re-enabled through options usingKV_OPT_USE_CLUSTER_NODES. - A
kvClusterAsyncContextnow embeds akvClusterContextinstead of holding a pointer to it. Replace any use ofacc->ccwith&acc->ccor similar.
Renamed API functions
ctx_get_by_nodeis renamed tokvClusterGetKVContext.actx_get_by_nodeis renamed tokvClusterGetKVAsyncContext.
Renamed API defines
REDIS_ROLE_NULLis renamed toKV_ROLE_UNKNOWN.REDIS_ROLE_MASTERis renamed toKV_ROLE_PRIMARY.REDIS_ROLE_SLAVEis renamed toKV_ROLE_REPLICA.
Removed API functions
redisClusterConnect2removed, usekvClusterConnectWithOptions.redisClusterContextInitremoved, usekvClusterConnectWithOptions.redisClusterSetConnectCallbackremoved, usekvClusterOptions.connect_callback.redisClusterSetEventCallbackremoved, usekvClusterOptions.event_callback.redisClusterSetMaxRedirectremoved, usekvClusterOptions.max_retry.redisClusterSetOptionAddNoderemoved, usekvClusterOptions.initial_nodes.redisClusterSetOptionAddNodesremoved, usekvClusterOptions.initial_nodes.redisClusterSetOptionConnectBlockremoved since it was deprecated.redisClusterSetOptionConnectNonBlockremoved since it was deprecated.redisClusterSetOptionConnectTimeoutremoved, usekvClusterOptions.connect_timeout.redisClusterSetOptionMaxRetryremoved, usekvClusterOptions.max_retry.redisClusterSetOptionParseSlavesremoved, usekvClusterOptions.optionsandKV_OPT_USE_REPLICAS.redisClusterSetOptionPasswordremoved, usekvClusterOptions.password.redisClusterSetOptionRouteUseSlotsremoved,CLUSTER SLOTSis used by default.redisClusterSetOptionUsernameremoved, usekvClusterOptions.username.redisClusterAsyncConnectremoved, usekvClusterAsyncConnectWithOptionswith options flagKV_OPT_BLOCKING_INITIAL_UPDATE.redisClusterAsyncConnect2removed, usekvClusterAsyncConnectWithOptions.redisClusterAsyncContextInitremoved,kvClusterAsyncConnectWithOptionswill initiate the context.redisClusterAsyncSetConnectCallbackremoved, butkvClusterOptions.async_connect_callbackcan be used which accepts a non-const callback function prototype.redisClusterAsyncSetConnectCallbackNCremoved, usekvClusterOptions.async_connect_callback.redisClusterAsyncSetDisconnectCallbackremoved, usekvClusterOptions.async_disconnect_callback.parse_cluster_nodesremoved from API, for internal use only.parse_cluster_slotsremoved from API, for internal use only.
Removed API defines
HIRCLUSTER_FLAG_NULLremoved.HIRCLUSTER_FLAG_ADD_SLAVEremoved, flag can be replaced with an option, seeKV_OPT_USE_REPLICAS.HIRCLUSTER_FLAG_ROUTE_USE_SLOTSremoved, the use ofCLUSTER SLOTSis enabled by default.
Removed support for splitting multi-key commands per slot
Since old days (from hiredis-vip) there has been support for sending some commands with multiple keys that covers multiple slots.
The client would split the command into multiple commands and send to each node handling each slot.
This was unnecessary complex and broke any expectations of atomicity.
Commands affected are DEL, EXISTS, MGET and MSET.
Proposed action:
Partition the keys by slot using kvClusterGetSlotByKey before sending affected commands.
Construct new commands when needed and send them using multiple calls to kvClusterCommand or equivalent.