Skip to content

Commit

Permalink
Node: update commands which return a Record with GlideString. (#2207
Browse files Browse the repository at this point in the history
)

* returning a record replacement with glide strings.
* Node: Add binary variant to `PUBSUB NUMSUB` and `PUBSUB SHARDNUMSUB` (#419)
* Updated PubSub shardnumsub and numsub commands
* Fix tests.
* Add binary variant to PUBSUB subscribe commands
* Fix processing cluster response.

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yi-Pin Chen <[email protected]>
Co-authored-by: Andrew Carbonetto <[email protected]>
Co-authored-by: Yi-Pin Chen <[email protected]>
  • Loading branch information
3 people authored Sep 10, 2024
1 parent 6e32c83 commit 71d8558
Show file tree
Hide file tree
Showing 14 changed files with 1,807 additions and 1,065 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#### Changes
* Node: Added binary variant for commands which have `Record` as input or output ([#2207](https:/valkey-io/valkey-glide/pull/2207))
* Node: Renamed `ReturnType` to `GlideReturnType` ([#2241](https:/valkey-io/valkey-glide/pull/2241))
* Node, Python: Rename `stop` to `end` in sorted set queries ([#2214](https:/valkey-io/valkey-glide/pull/2214))
* Node: Added binary variant to sorted set commands - part 1 ([#2190](https:/valkey-io/valkey-glide/pull/2190))
Expand Down
8 changes: 8 additions & 0 deletions node/npm/glide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ function initialize() {
GlideClient,
GlideClusterClient,
GlideClientConfiguration,
GlideRecord,
GlideString,
SortedSetDataType,
StreamEntryDataType,
HashDataType,
FunctionListOptions,
FunctionListResponse,
FunctionStatsSingleResponse,
Expand Down Expand Up @@ -213,7 +217,11 @@ function initialize() {
Decoder,
DecoderOption,
GeoAddOptions,
GlideRecord,
GlideString,
SortedSetDataType,
StreamEntryDataType,
HashDataType,
CoordOrigin,
MemberOrigin,
SearchOrigin,
Expand Down
18 changes: 11 additions & 7 deletions node/rust-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use napi::bindgen_prelude::Uint8Array;
use napi::{Env, Error, JsObject, JsUnknown, Result, Status};
use napi_derive::napi;
use num_traits::sign::Signed;
use redis::{aio::MultiplexedConnection, AsyncCommands, FromRedisValue, Value};
use redis::{aio::MultiplexedConnection, AsyncCommands, Value};
#[cfg(feature = "testing_utilities")]
use std::collections::HashMap;
use std::str;
Expand Down Expand Up @@ -195,13 +195,17 @@ fn redis_value_to_js(val: Value, js_env: Env, string_decoder: bool) -> Result<Js
Ok(js_array_view.into_unknown())
}
Value::Map(map) => {
let mut obj = js_env.create_object()?;
for (key, value) in map {
let field_name = String::from_owned_redis_value(key).map_err(to_js_error)?;
let value = redis_value_to_js(value, js_env, string_decoder)?;
obj.set_named_property(&field_name, value)?;
// Convert map to array of key-value pairs instead of a `Record` (object),
// because `Record` does not support `GlideString` as a key.
// The result is in format `GlideRecord<T>`.
let mut js_array = js_env.create_array_with_length(map.len())?;
for (idx, (key, value)) in (0_u32..).zip(map.into_iter()) {
let mut obj = js_env.create_object()?;
obj.set_named_property("key", redis_value_to_js(key, js_env, string_decoder)?)?;
obj.set_named_property("value", redis_value_to_js(value, js_env, string_decoder)?)?;
js_array.set_element(idx, obj)?;
}
Ok(obj.into_unknown())
Ok(js_array.into_unknown())
}
Value::Double(float) => js_env.create_double(float).map(|val| val.into_unknown()),
Value::Boolean(bool) => js_env.get_boolean(bool).map(|val| val.into_unknown()),
Expand Down
Loading

0 comments on commit 71d8558

Please sign in to comment.