Skip to content

Commit

Permalink
Java: Replace instances of Redis with Valkey (valkey-io#2268)
Browse files Browse the repository at this point in the history
* Replace instances of Redis with Valkey

Signed-off-by: Jonathan Louie <[email protected]>

* Update changelog

Signed-off-by: Jonathan Louie <[email protected]>

* Change GLIDE for Valkey to Valkey-GLIDE

Co-authored-by: Andrew Carbonetto <[email protected]>
Signed-off-by: jonathanl-bq <[email protected]>

* rename valkey_value to resp_value

Signed-off-by: Jonathan Louie <[email protected]>

---------

Signed-off-by: Jonathan Louie <[email protected]>
Signed-off-by: jonathanl-bq <[email protected]>
Co-authored-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
jonathanl-bq and acarbonetto authored Sep 11, 2024
1 parent 9afe97e commit 87b5848
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 49 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#### Changes
* Java: Replace instances of Redis with Valkey ([#2268](https://github.com/valkey-io/valkey-glide/pull/2268))
* Node: Replace instances of Redis with Valkey ([#2260](https://github.com/valkey-io/valkey-glide/pull/2260))
* Java: Fetch server version using info command ([#2258](https://github.com/valkey-io/valkey-glide/pull/2258))
* Node: Added binary variant for commands which have `Record` as input or output ([#2207](https://github.com/valkey-io/valkey-glide/pull/2207))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

/** Benchmarking app for reporting performance of various Redis Java-clients */
/** Benchmarking app for reporting performance of various Valkey Java-clients */
public class BenchmarkingApp {

// main application entrypoint
Expand Down Expand Up @@ -55,7 +55,7 @@ public static void main(String[] args) {
testClientSetGet(LettuceAsyncClient::new, runConfiguration, true);
break;
case GLIDE:
System.out.println("GLIDE for Redis async client");
System.out.println("Valkey-GLIDE async client");
testClientSetGet(GlideAsyncClient::new, runConfiguration, true);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/** A Redis client with async capabilities */
/** A Valkey client with async capabilities */
public interface AsyncClient<T> extends Client {

long DEFAULT_TIMEOUT_MILLISECOND = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import glide.benchmarks.utils.ConnectionSettings;

/** A Redis client interface */
/** A Valkey client interface */
public interface Client {
void connectToValkey(ConnectionSettings connectionSettings);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.benchmarks.clients;

/** A Redis client with sync capabilities */
/** A Valkey client with sync capabilities */
public interface SyncClient extends Client {
void set(String key, String value);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.benchmarks.utils;

/** Redis-client settings */
/** Valkey-client settings */
public class ConnectionSettings {
public final String host;
public final int port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ZScanOptionsBinary extends BaseScanOptionsBinary {

/**
* When set to true, the command will not include scores in the results. This option is available
* from Redis version 8.0.0 and above.
* from Valkey version 8.0.0 and above.
*/
@Builder.Default protected boolean noScores = false;

Expand Down
22 changes: 11 additions & 11 deletions java/client/src/test/java/glide/ffi/FfiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,30 @@ public static native void throwException(
boolean throwTwice, boolean isRuntimeException, String message);

@Test
public void redisValueToJavaValue_Nil() {
public void respValueToJavaValue_Nil() {
long ptr = FfiTest.createLeakedNil();
Object nilValue = GlideValueResolver.valueFromPointer(ptr);
assertNull(nilValue);
}

@ParameterizedTest
@ValueSource(strings = {"hello", "cat", "dog"})
public void redisValueToJavaValue_SimpleString(String input) {
public void respValueToJavaValue_SimpleString(String input) {
long ptr = FfiTest.createLeakedSimpleString(input);
Object simpleStringValue = GlideValueResolver.valueFromPointer(ptr);
assertEquals(input, simpleStringValue);
}

@Test
public void redisValueToJavaValue_Okay() {
public void respValueToJavaValue_Okay() {
long ptr = FfiTest.createLeakedOkay();
Object okayValue = GlideValueResolver.valueFromPointer(ptr);
assertEquals("OK", okayValue);
}

@ParameterizedTest
@ValueSource(longs = {0L, 100L, 774L, Integer.MAX_VALUE + 1L, Integer.MIN_VALUE - 1L})
public void redisValueToJavaValue_Int(Long input) {
public void respValueToJavaValue_Int(Long input) {
long ptr = FfiTest.createLeakedInt(input);
Object longValue = GlideValueResolver.valueFromPointer(ptr);
assertTrue(longValue instanceof Long);
Expand All @@ -90,7 +90,7 @@ public void redisValueToJavaValue_Int(Long input) {

@Test
@SneakyThrows
public void redisValueToJavaValue_BulkString() {
public void respValueToJavaValue_BulkString() {
// This is explicitly for testing non-ASCII UTF-8 byte sequences.
// Note that these can't be encoded as String literals without introducing compiler
// warnings and errors.
Expand All @@ -105,7 +105,7 @@ public void redisValueToJavaValue_BulkString() {
}

@Test
public void redisValueToJavaValue_Array() {
public void respValueToJavaValue_Array() {
long[] array = {1L, 2L, 3L};
long ptr = FfiTest.createLeakedLongArray(array);
Object longArrayValue = GlideValueResolver.valueFromPointer(ptr);
Expand All @@ -115,7 +115,7 @@ public void redisValueToJavaValue_Array() {
}

@Test
public void redisValueToJavaValue_Map() {
public void respValueToJavaValue_Map() {
long[] keys = {12L, 14L, 23L};
long[] values = {1L, 2L, 3L};
long ptr = FfiTest.createLeakedMap(keys, values);
Expand All @@ -130,29 +130,29 @@ public void redisValueToJavaValue_Map() {

@ParameterizedTest
@ValueSource(doubles = {1.0d, 25.2d, 103.5d})
public void redisValueToJavaValue_Double(Double input) {
public void respValueToJavaValue_Double(Double input) {
long ptr = FfiTest.createLeakedDouble(input);
Object doubleValue = GlideValueResolver.valueFromPointer(ptr);
assertEquals(input, doubleValue);
}

@Test
public void redisValueToJavaValue_Boolean() {
public void respValueToJavaValue_Boolean() {
long ptr = FfiTest.createLeakedBoolean(true);
Object booleanValue = GlideValueResolver.valueFromPointer(ptr);
assertTrue((Boolean) booleanValue);
}

@ParameterizedTest
@ValueSource(strings = {"hello", "cat", "dog"})
public void redisValueToJavaValue_VerbatimString(String input) {
public void respValueToJavaValue_VerbatimString(String input) {
long ptr = FfiTest.createLeakedVerbatimString(input);
Object verbatimStringValue = GlideValueResolver.valueFromPointer(ptr);
assertEquals(input, verbatimStringValue);
}

@Test
public void redisValueToJavaValue_Set() {
public void respValueToJavaValue_Set() {
long[] array = {1L, 2L, 2L};
long ptr = FfiTest.createLeakedLongSet(array);
Object longSetValue = GlideValueResolver.valueFromPointer(ptr);
Expand Down
44 changes: 22 additions & 22 deletions java/src/ffi_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub extern "system" fn Java_glide_ffi_FfiTest_createLeakedNil<'local>(
_env: JNIEnv<'local>,
_class: JClass<'local>,
) -> jlong {
let redis_value = Value::Nil;
Box::leak(Box::new(redis_value)) as *mut Value as jlong
let resp_value = Value::Nil;
Box::leak(Box::new(resp_value)) as *mut Value as jlong
}

#[no_mangle]
Expand All @@ -25,17 +25,17 @@ pub extern "system" fn Java_glide_ffi_FfiTest_createLeakedSimpleString<'local>(
value: JString<'local>,
) -> jlong {
let value: String = env.get_string(&value).unwrap().into();
let redis_value = Value::SimpleString(value);
Box::leak(Box::new(redis_value)) as *mut Value as jlong
let resp_value = Value::SimpleString(value);
Box::leak(Box::new(resp_value)) as *mut Value as jlong
}

#[no_mangle]
pub extern "system" fn Java_glide_ffi_FfiTest_createLeakedOkay<'local>(
_env: JNIEnv<'local>,
_class: JClass<'local>,
) -> jlong {
let redis_value = Value::Okay;
Box::leak(Box::new(redis_value)) as *mut Value as jlong
let resp_value = Value::Okay;
Box::leak(Box::new(resp_value)) as *mut Value as jlong
}

#[no_mangle]
Expand All @@ -44,8 +44,8 @@ pub extern "system" fn Java_glide_ffi_FfiTest_createLeakedInt<'local>(
_class: JClass<'local>,
value: jlong,
) -> jlong {
let redis_value = Value::Int(value);
Box::leak(Box::new(redis_value)) as *mut Value as jlong
let resp_value = Value::Int(value);
Box::leak(Box::new(resp_value)) as *mut Value as jlong
}

#[no_mangle]
Expand All @@ -56,8 +56,8 @@ pub extern "system" fn Java_glide_ffi_FfiTest_createLeakedBulkString<'local>(
) -> jlong {
let value = env.convert_byte_array(&value).unwrap();
let value = value.into_iter().collect::<Vec<u8>>();
let redis_value = Value::BulkString(value);
Box::leak(Box::new(redis_value)) as *mut Value as jlong
let resp_value = Value::BulkString(value);
Box::leak(Box::new(resp_value)) as *mut Value as jlong
}

#[no_mangle]
Expand All @@ -67,8 +67,8 @@ pub extern "system" fn Java_glide_ffi_FfiTest_createLeakedLongArray<'local>(
value: JLongArray<'local>,
) -> jlong {
let array = java_long_array_to_value(&mut env, &value);
let redis_value = Value::Array(array);
Box::leak(Box::new(redis_value)) as *mut Value as jlong
let resp_value = Value::Array(array);
Box::leak(Box::new(resp_value)) as *mut Value as jlong
}

#[no_mangle]
Expand All @@ -81,8 +81,8 @@ pub extern "system" fn Java_glide_ffi_FfiTest_createLeakedMap<'local>(
let keys_vec = java_long_array_to_value(&mut env, &keys);
let values_vec = java_long_array_to_value(&mut env, &values);
let map: Vec<(Value, Value)> = keys_vec.into_iter().zip(values_vec).collect();
let redis_value = Value::Map(map);
Box::leak(Box::new(redis_value)) as *mut Value as jlong
let resp_value = Value::Map(map);
Box::leak(Box::new(resp_value)) as *mut Value as jlong
}

#[no_mangle]
Expand All @@ -91,8 +91,8 @@ pub extern "system" fn Java_glide_ffi_FfiTest_createLeakedDouble<'local>(
_class: JClass<'local>,
value: jdouble,
) -> jlong {
let redis_value = Value::Double(value.into());
Box::leak(Box::new(redis_value)) as *mut Value as jlong
let resp_value = Value::Double(value.into());
Box::leak(Box::new(resp_value)) as *mut Value as jlong
}

#[no_mangle]
Expand All @@ -101,8 +101,8 @@ pub extern "system" fn Java_glide_ffi_FfiTest_createLeakedBoolean<'local>(
_class: JClass<'local>,
value: jboolean,
) -> jlong {
let redis_value = Value::Boolean(value != 0);
Box::leak(Box::new(redis_value)) as *mut Value as jlong
let resp_value = Value::Boolean(value != 0);
Box::leak(Box::new(resp_value)) as *mut Value as jlong
}

#[no_mangle]
Expand All @@ -113,11 +113,11 @@ pub extern "system" fn Java_glide_ffi_FfiTest_createLeakedVerbatimString<'local>
) -> jlong {
use redis::VerbatimFormat;
let value: String = env.get_string(&value).unwrap().into();
let redis_value = Value::VerbatimString {
let resp_value = Value::VerbatimString {
format: VerbatimFormat::Text,
text: value,
};
Box::leak(Box::new(redis_value)) as *mut Value as jlong
Box::leak(Box::new(resp_value)) as *mut Value as jlong
}

#[no_mangle]
Expand All @@ -127,8 +127,8 @@ pub extern "system" fn Java_glide_ffi_FfiTest_createLeakedLongSet<'local>(
value: JLongArray<'local>,
) -> jlong {
let set = java_long_array_to_value(&mut env, &value);
let redis_value = Value::Set(set);
Box::leak(Box::new(redis_value)) as *mut Value as jlong
let resp_value = Value::Set(set);
Box::leak(Box::new(resp_value)) as *mut Value as jlong
}

fn java_long_array_to_value<'local>(
Expand Down
18 changes: 9 additions & 9 deletions java/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub use ffi_test::*;
struct Level(i32);

// TODO: Consider caching method IDs here in a static variable (might need RwLock to mutate)
fn redis_value_to_java<'local>(
fn resp_value_to_java<'local>(
env: &mut JNIEnv<'local>,
val: Value,
encoding_utf8: bool,
Expand Down Expand Up @@ -62,8 +62,8 @@ fn redis_value_to_java<'local>(
let linked_hash_map = env.new_object("java/util/LinkedHashMap", "()V", &[])?;

for (key, value) in map {
let java_key = redis_value_to_java(env, key, encoding_utf8)?;
let java_value = redis_value_to_java(env, value, encoding_utf8)?;
let java_key = resp_value_to_java(env, key, encoding_utf8)?;
let java_value = resp_value_to_java(env, value, encoding_utf8)?;
env.call_method(
&linked_hash_map,
"put",
Expand All @@ -88,7 +88,7 @@ fn redis_value_to_java<'local>(
let set = env.new_object("java/util/HashSet", "()V", &[])?;

for elem in array {
let java_value = redis_value_to_java(env, elem, encoding_utf8)?;
let java_value = resp_value_to_java(env, elem, encoding_utf8)?;
env.call_method(
&set,
"add",
Expand All @@ -106,7 +106,7 @@ fn redis_value_to_java<'local>(
// Create a java `Map<String, Object>` with two keys:
// - "kind" which corresponds to the push type, stored as a `String`
// - "values" which corresponds to the array of values received, stored as `Object[]`
// Only string messages are supported now by Redis and `redis-rs`.
// Only string messages are supported now by Valkey and `redis-rs`.
Value::Push { kind, data } => {
let hash_map = env.new_object("java/util/HashMap", "()V", &[])?;

Expand Down Expand Up @@ -137,7 +137,7 @@ fn redis_value_to_java<'local>(

/// Convert an array of values into java array of corresponding values.
///
/// Recursively calls to [`redis_value_to_java`] for every element.
/// Recursively calls to [`resp_value_to_java`] for every element.
///
/// Returns an arbitrary java `Object[]`.
fn array_to_java_array<'local>(
Expand All @@ -149,7 +149,7 @@ fn array_to_java_array<'local>(
env.new_object_array(values.len() as i32, "java/lang/Object", JObject::null())?;

for (i, item) in values.into_iter().enumerate() {
let java_value = redis_value_to_java(env, item, encoding_utf8)?;
let java_value = resp_value_to_java(env, item, encoding_utf8)?;
env.set_object_array_element(&items, i as i32, java_value)?;
}

Expand All @@ -169,7 +169,7 @@ pub extern "system" fn Java_glide_ffi_resolvers_GlideValueResolver_valueFromPoin
pointer: jlong,
) -> Result<JObject<'a>, FFIError> {
let value = unsafe { Box::from_raw(pointer as *mut Value) };
redis_value_to_java(env, *value, true)
resp_value_to_java(env, *value, true)
}
let result = value_from_pointer(&mut env, pointer);
handle_errors(&mut env, result)
Expand All @@ -194,7 +194,7 @@ pub extern "system" fn Java_glide_ffi_resolvers_GlideValueResolver_valueFromPoin
pointer: jlong,
) -> Result<JObject<'a>, FFIError> {
let value = unsafe { Box::from_raw(pointer as *mut Value) };
redis_value_to_java(env, *value, false)
resp_value_to_java(env, *value, false)
}
let result = value_from_pointer_binary(&mut env, pointer);
handle_errors(&mut env, result)
Expand Down

0 comments on commit 87b5848

Please sign in to comment.