Libvalkey 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 libvalkey.
The general actions needed are:
- Replace the prefix
redis
withvalkey
in API usages. - Replace the term
SSL
withTLS
in API usages for secure communication. - Update include paths depending on your previous installation.
All
libvalkey
headers are now found underinclude/valkey/
. - Update used build options, e.g.
USE_TLS
replacesUSE_SSL
.
The type sds
is removed from the public API.
redisAsyncSetConnectCallbackNC
is renamed tovalkeyAsyncSetConnectCallback
.
redisFormatSdsCommandArgv
removed from API. Can be replaced withvalkeyFormatCommandArgv
.redisFreeSdsCommand
removed since thesds
type is for internal use only.redisAsyncSetConnectCallback
is removed, but can be replaced withvalkeyAsyncSetConnectCallback
which accepts the non-const callback function prototype.
- The cluster client initiation procedure is changed and
valkeyClusterOptions
should 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 NODES
can be re-enabled through options usingVALKEY_OPT_USE_CLUSTER_NODES
. - A
valkeyClusterAsyncContext
now embeds avalkeyClusterContext
instead of holding a pointer to it. Replace any use ofacc->cc
with&acc->cc
or similar.
ctx_get_by_node
is renamed tovalkeyClusterGetValkeyContext
.actx_get_by_node
is renamed tovalkeyClusterGetValkeyAsyncContext
.
REDIS_ROLE_NULL
is renamed toVALKEY_ROLE_UNKNOWN
.REDIS_ROLE_MASTER
is renamed toVALKEY_ROLE_PRIMARY
.REDIS_ROLE_SLAVE
is renamed toVALKEY_ROLE_REPLICA
.
redisClusterConnect2
removed, usevalkeyClusterConnectWithOptions
.redisClusterContextInit
removed, usevalkeyClusterConnectWithOptions
.redisClusterSetConnectCallback
removed, usevalkeyClusterOptions.connect_callback
.redisClusterSetEventCallback
removed, usevalkeyClusterOptions.event_callback
.redisClusterSetMaxRedirect
removed, usevalkeyClusterOptions.max_retry
.redisClusterSetOptionAddNode
removed, usevalkeyClusterOptions.initial_nodes
.redisClusterSetOptionAddNodes
removed, usevalkeyClusterOptions.initial_nodes
.redisClusterSetOptionConnectBlock
removed since it was deprecated.redisClusterSetOptionConnectNonBlock
removed since it was deprecated.redisClusterSetOptionConnectTimeout
removed, usevalkeyClusterOptions.connect_timeout
.redisClusterSetOptionMaxRetry
removed, usevalkeyClusterOptions.max_retry
.redisClusterSetOptionParseSlaves
removed, usevalkeyClusterOptions.options
andVALKEY_OPT_USE_REPLICAS
.redisClusterSetOptionPassword
removed, usevalkeyClusterOptions.password
.redisClusterSetOptionRouteUseSlots
removed,CLUSTER SLOTS
is used by default.redisClusterSetOptionUsername
removed, usevalkeyClusterOptions.username
.redisClusterAsyncConnect
removed, usevalkeyClusterAsyncConnectWithOptions
with options flagVALKEY_OPT_BLOCKING_INITIAL_UPDATE
.redisClusterAsyncConnect2
removed, usevalkeyClusterAsyncConnectWithOptions
.redisClusterAsyncContextInit
removed,valkeyClusterAsyncConnectWithOptions
will initiate the context.redisClusterAsyncSetConnectCallback
removed, butvalkeyClusterOptions.async_connect_callback
can be used which accepts a non-const callback function prototype.redisClusterAsyncSetConnectCallbackNC
removed, usevalkeyClusterOptions.async_connect_callback
.redisClusterAsyncSetDisconnectCallback
removed, usevalkeyClusterOptions.async_disconnect_callback
.parse_cluster_nodes
removed from API, for internal use only.parse_cluster_slots
removed from API, for internal use only.
HIRCLUSTER_FLAG_NULL
removed.HIRCLUSTER_FLAG_ADD_SLAVE
removed, flag can be replaced with an option, seeVALKEY_OPT_USE_REPLICAS
.HIRCLUSTER_FLAG_ROUTE_USE_SLOTS
removed, the use ofCLUSTER SLOTS
is enabled by default.
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 valkeyClusterGetSlotByKey
before sending affected commands.
Construct new commands when needed and send them using multiple calls to valkeyClusterCommand
or equivalent.