Command Comparison: Redisson → Glide
String Operations
Section titled “String Operations”SET & GET
Section titled “SET & GET”The SET command stores a key-value pair in Valkey, while GET retrieves the value associated with a key.
- Redisson uses
RBucketobjects to represent string values. - Glide provides direct
set()andget()methods on the client.
Redisson
// Set a key-value pairRBucket<String> bucket = redisson.getBucket("key");bucket.set("value");
// Retrieve the valueString value = bucket.get(); // value = "value"
// Alternative approachredisson.getBucket("key").set("value");String value = redisson.getBucket("key").get(); // value = "value"Glide
// Set a key-value pairclient.set("key", "value");
// Retrieve the valueString value = client.get("key").get(); // value = "value"Note: The .get() is required in Glide because get() returns a CompletableFuture<String>.
SETEX (Set with Expiry)
Section titled “SETEX (Set with Expiry)”The SETEX command sets a key with an expiration time in seconds.
- In Redisson, expiration is handled using
expire()method orsetAsync()with duration. - In Glide, expiration is handled using an additional parameter in the
set()command.
Redisson
RBucket<String> bucket = redisson.getBucket("key");bucket.set("value", Duration.ofSeconds(5)); // Set with 5 second expiryGlide
client.set("key", "value", SetOptions.builder().expiry(Seconds(5L)).build()).get();SETNX (Set if Not Exists)
Section titled “SETNX (Set if Not Exists)”The SETNX command sets a key only if it does not already exist.
- In Redisson, this is handled using
trySet()method which returns true if the key was set. - In Glide, this is handled using conditional set options within the
set()command.
Redisson
RBucket<String> bucket = redisson.getBucket("key");boolean result = bucket.trySet("value"); // Returns true if key was set, false if key existsGlide
import glide.api.models.commands.SetOptions;import glide.api.models.commands.ConditionalChange;
String result = client.set("key", "value", SetOptions.builder() .conditionalSet(ConditionalChange.ONLY_IF_DOES_NOT_EXIST) .build()).get(); // Returns "OK" if key was set, null if key existsMSET & MGET (Multiple Set/Get)
Section titled “MSET & MGET (Multiple Set/Get)”The MSET command sets multiple key-value pairs in a single operation, while MGET retrieves values for multiple keys.
- In Redisson,
RBucketsis used for bulk operations with Maps. - In Glide,
mset()accepts a Map andmget()requires an array of keys.
Redisson
// Multiple setRBuckets buckets = redisson.getBuckets();Map<String, String> map = new HashMap<>();map.put("key1", "value1");map.put("key2", "value2");buckets.set(map);
// Multiple getMap<String, String> values = buckets.get("key1", "key2"); // {key1=value1, key2=value2}Glide
// Multiple setMap<String, String> map = new HashMap<>();map.put("key1", "value1");map.put("key2", "value2");client.mset(map);
// Multiple getString[] values = client.mget(new String[]{"key1", "key2"}).get(); // ["value1", "value2"]INCR & DECR
Section titled “INCR & DECR”The INCR command increments the value of a key by 1, while DECR decrements it by 1.
- Redisson uses
RAtomicLongfor atomic increment/decrement operations. - Glide provides direct
incr()anddecr()methods.
Redisson
redisson.getBucket("counter").set("1");RAtomicLong counter = redisson.getAtomicLong("counter");counter.incrementAndGet(); // counter = 2counter.decrementAndGet(); // counter = 1Glide
client.set("counter", "1");client.incr("counter").get(); // counter = 2client.decr("counter").get(); // counter = 1INCRBY & DECRBY
Section titled “INCRBY & DECRBY”The INCRBY command increases the value of a key by a specified amount, while DECRBY decreases it by a specified amount.
- Redisson uses
RAtomicLongwithaddAndGet()method. - Glide provides direct
incrBy()anddecrBy()methods.
Redisson
RAtomicLong counter = redisson.getAtomicLong("counter");long result = counter.addAndGet(5); // counter: 5result = counter.addAndGet(-2); // counter: 3Glide
long counter = client.incrBy("counter", 5).get(); // counter: 5counter = client.decrBy("counter", 2).get(); // counter: 3APPEND
Section titled “APPEND”The APPEND command appends a value to the end of an existing string stored at a key.
- Redisson doesn’t have a direct append method; you need to get, concatenate, and set.
- Glide provides a direct
append()method.
Redisson
RBucket<String> bucket = redisson.getBucket("greeting");bucket.set("Hello");String current = bucket.get();bucket.set(current + " World"); // Manual appendString result = bucket.get(); // "Hello World"Glide
client.set("greeting", "Hello");Long length = client.append("greeting", " World").get(); // Returns length: 11String result = client.get("greeting").get(); // "Hello World"GETRANGE & SETRANGE
Section titled “GETRANGE & SETRANGE”The GETRANGE command retrieves a substring from a string value stored at a key, while SETRANGE overwrites part of a string at a key starting at a specified offset.
- Redisson doesn’t have direct getrange/setrange methods.
- Glide provides direct
getRange()andsetRange()methods.
Redisson
// Redisson doesn't have direct getrange/setrange support// You would need to implement this manually using get/set operationsRBucket<String> bucket = redisson.getBucket("key");bucket.set("Hello World");String value = bucket.get();String substring = value.substring(0, 5); // "Hello" (manual implementation)Glide
client.set("key", "Hello World");String result = client.getRange("key", 0, 4).get(); // "Hello"
client.setRange("key", 6, "Redis").get(); // Returns length: 11String updated = client.get("key").get(); // "Hello Redis"Key Operations
Section titled “Key Operations”DEL (Delete)
Section titled “DEL (Delete)”The DEL command removes one or more keys from Valkey.
- In Redisson, individual objects have
delete()methods, or useRKeysfor bulk operations. - In Glide,
del()requires an array of keys.
Redisson
// Delete single keyredisson.getBucket("key1").delete();
// Delete multiple keysRKeys keys = redisson.getKeys();long deleted = keys.delete("key1", "key2"); // 2 (number of keys deleted)Glide
Long deleted = client.del(new String[]{"key1", "key2"}).get(); // 2 (number of keys deleted)EXISTS
Section titled “EXISTS”The EXISTS command checks if one or more keys exist in Valkey.
- In Redisson, individual objects have
isExists()methods, or useRKeysfor bulk operations. - In Glide,
exists()takes a list of keys and returns a Long indicating how many exist.
Redisson
// Check single keyboolean exists = redisson.getBucket("key").isExists(); // true or false
// Check multiple keysRKeys keys = redisson.getKeys();long count = keys.countExists("key1", "key2"); // number of keys that existGlide
Long count = client.exists(new String[]{"key1", "key2"}).get(); // number of keys that existEXPIRE & TTL
Section titled “EXPIRE & TTL”The EXPIRE command sets a time-to-live (TTL) for a key, after which it will be automatically deleted. The TTL command returns the remaining time-to-live for a key.
- In Redisson, objects implement
RExpirableinterface withexpire()andremainTimeToLive()methods. - In Glide,
expire()andttl()are direct client methods.
Redisson
RBucket<String> bucket = redisson.getBucket("key");bucket.set("value");boolean success = bucket.expire(Duration.ofSeconds(10)); // true (success)long ttl = bucket.remainTimeToLive(); // milliseconds remainingGlide
Long success = client.expire("key", 10).get(); // 1 (success)Long ttl = client.ttl("key").get(); // 10 (seconds remaining)KEYS & SCAN
Section titled “KEYS & SCAN”The KEYS command returns all keys matching a pattern, while SCAN iterates through keys in a more efficient way for production use.
- Redisson provides
RKeysinterface withgetKeys()andgetKeysStream()methods. - Glide provides direct
keys()andscan()methods.
Redisson
RKeys keys = redisson.getKeys();
// KEYS (not recommended for production)Iterable<String> allKeys = keys.getKeysByPattern("*");
// SCAN (recommended for production)Iterable<String> keysIterable = keys.getKeysStream().toIterable();for (String key : keysIterable) { System.out.println("Key: " + key);}Glide
// KEYS (not recommended for production)String[] allKeys = client.keys("*").get();
// SCAN (recommended for production)String cursor = "0";Object[] result;
do { result = client.scan(cursor).get(); cursor = result[0].toString();
Object[] keys = (Object[]) result[1]; if (keys.length > 0) { String keyList = Arrays.stream(keys) .map(obj -> (String) obj) .collect(Collectors.joining(", ")); System.out.println("SCAN iteration: " + keyList); }} while (!cursor.equals("0"));RENAME & RENAMENX
Section titled “RENAME & RENAMENX”The RENAME command renames a key, while RENAMENX renames a key only if the new key does not already exist.
- In Redisson, objects have
rename()andrenamenx()methods. - In Glide,
rename()andrenameNx()are direct client methods.
Redisson
RBucket<String> bucket = redisson.getBucket("oldkey");bucket.set("value");bucket.rename("newkey"); // void
RBucket<String> bucket1 = redisson.getBucket("key1");bucket1.set("value1");boolean success = bucket1.renamenx("key2"); // true (success)Glide
client.set("oldkey", "value");String result = client.rename("oldkey", "newkey").get(); // "OK"
client.set("key1", "value1");Long success = client.renameNx("key1", "key2").get(); // 1 (success)Hash Operations
Section titled “Hash Operations”HSET & HGET
Section titled “HSET & HGET”The HSET command sets field-value pairs in a hash stored at a key, while HGET retrieves the value of a specific field.
- In Redisson,
RMapis used for hash operations withput()andget()methods. - In Glide,
hset()accepts a Map andhget()retrieves individual fields.
Redisson
RMap<String, String> map = redisson.getMap("hash");
// Set a single fieldmap.put("key1", "1"); // returns previous value or null
// Set multiple fieldsMap<String, String> fields = new HashMap<>();fields.put("key1", "1");fields.put("key2", "2");map.putAll(fields);
// Get a single fieldString value = map.get("key1"); // "1"Glide
// Set a single fieldMap<String, String> singleField = new HashMap<>();singleField.put("key1", "1");client.hset("hash", singleField).get(); // 1 (field added)
// Set multiple fieldsMap<String, String> map = new HashMap<>();map.put("key1", "1");map.put("key2", "2");client.hset("hash", map).get(); // 2 (fields added)
// Get a single fieldString value = client.hget("hash", "key1").get(); // "1"HMSET & HMGET
Section titled “HMSET & HMGET”The HMSET command sets multiple field-value pairs in a hash, while HMGET retrieves values for multiple fields.
- In Redisson,
RMap.putAll()is used for setting multiple fields, andgetAll()for getting multiple fields. - In Glide,
hset()is used for setting multiple fields, andhmget()requires an array of fields.
Redisson
RMap<String, String> map = redisson.getMap("hash");
// Set multiple fieldsMap<String, String> fields = new HashMap<>();fields.put("key1", "1");fields.put("key2", "2");map.putAll(fields);
// Get multiple fieldsMap<String, String> values = map.getAll(Set.of("key1", "key2")); // {key1=1, key2=2}Glide
// Set multiple fields (same as hset in Glide)Map<String, String> map = new HashMap<>();map.put("key1", "1");map.put("key2", "2");client.hset("hash", map).get(); // 2 (fields added)
// Get multiple fieldsString[] values = client.hmget("hash", new String[]{"key1", "key2"}).get(); // ["1", "2"]HGETALL
Section titled “HGETALL”The HGETALL command retrieves all field-value pairs from a hash.
- Redisson uses
RMap.readAllMap()to get all entries. - Glide provides direct
hgetall()method.
Redisson
RMap<String, String> map = redisson.getMap("user");Map<String, String> fields = new HashMap<>();fields.put("name", "John");fields.put("age", "30");map.putAll(fields);
Map<String, String> user = map.readAllMap(); // {name=John, age=30}Glide
Map<String, String> map = new HashMap<>();map.put("name", "John");map.put("age", "30");client.hset("user", map);
Map<String, String> user = client.hgetall("user").get(); // {name=John, age=30}HDEL & HEXISTS
Section titled “HDEL & HEXISTS”The HDEL command removes one or more fields from a hash, while HEXISTS checks if a field exists in a hash.
- In Redisson,
RMapprovidesremove()andcontainsKey()methods. - In Glide,
hdel()requires an array of fields, andhexists()returns 1 or 0.
Redisson
RMap<String, String> map = redisson.getMap("hash");Map<String, String> fields = new HashMap<>();fields.put("key1", "1");fields.put("key2", "2");fields.put("key3", "3");map.putAll(fields);
// Remove fieldsmap.remove("key1");map.remove("key2");
// Check existenceboolean exists = map.containsKey("key3"); // true (exists)boolean notExists = map.containsKey("key1"); // false (doesn't exist)Glide
Map<String, String> map = new HashMap<>();map.put("key1", "1");map.put("key2", "2");map.put("key3", "3");client.hset("hash", map);
Long deleted = client.hdel("hash", new String[]{"key1", "key2"}).get(); // 2 (fields deleted)
Long exists = client.hexists("hash", "key3").get(); // 1 (exists)Long notExists = client.hexists("hash", "key1").get(); // 0 (doesn't exist)List Operations
Section titled “List Operations”LPUSH & RPUSH
Section titled “LPUSH & RPUSH”The LPUSH command adds elements to the beginning of a list, while RPUSH adds elements to the end of a list.
- In Redisson,
RListprovidesaddFirst()andadd()methods. - In Glide,
lpush()andrpush()require arrays of elements.
Redisson
RList<String> list = redisson.getList("list");list.addFirst("c");list.addFirst("b");list.addFirst("a"); // List: [a, b, c]
list.add("d");list.add("e"); // List: [a, b, c, d, e]Glide
Long lengthOfList = client.lpush("list", new String[]{"a", "b", "c"}).get(); // lengthOfList = 3lengthOfList = client.rpush("list", new String[]{"d", "e"}).get(); // lengthOfList = 5LPOP & RPOP
Section titled “LPOP & RPOP”The LPOP command removes and returns the first element of a list, while RPOP removes and returns the last element.
- In Redisson,
RListprovidesremoveFirst()andremoveLast()methods. - Glide provides direct
lpop()andrpop()methods.
Redisson
RList<String> list = redisson.getList("list");list.add("a");list.add("b");list.add("c");
String first = list.removeFirst(); // "a"String last = list.removeLast(); // "c"Glide
client.rpush("list", new String[]{"a", "b", "c"});String first = client.lpop("list").get(); // "a"String last = client.rpop("list").get(); // "c"LRANGE
Section titled “LRANGE”The LRANGE command retrieves a range of elements from a list.
- In Redisson,
RListprovidesrange()method. - Glide provides direct
lrange()method.
Redisson
RList<String> list = redisson.getList("list");list.add("a");list.add("b");list.add("c");list.add("d");list.add("e");
List<String> elements = list.range(0, 2); // [a, b, c]Glide
client.rpush("list", new String[]{"a", "b", "c", "d", "e"});String[] elements = client.lrange("list", 0, 2).get(); // ["a", "b", "c"]Set Operations
Section titled “Set Operations”SADD & SMEMBERS
Section titled “SADD & SMEMBERS”The SADD command adds one or more members to a set, while SMEMBERS returns all members of a set.
- In Redisson,
RSetprovidesadd()andreadAll()methods. - In Glide,
sadd()requires an array of members.
Redisson
RSet<String> set = redisson.getSet("set");boolean added1 = set.add("a"); // trueboolean added2 = set.add("b"); // trueboolean added3 = set.add("c"); // true
Set<String> members = set.readAll(); // [a, b, c]Glide
Long added = client.sadd("set", new String[]{"a", "b", "c"}).get(); // 3 (members added)String[] members = client.smembers("set").get(); // ["a", "b", "c"]SREM & SISMEMBER
Section titled “SREM & SISMEMBER”The SREM command removes one or more members from a set, while SISMEMBER checks if a value is a member of a set.
- In Redisson,
RSetprovidesremove()andcontains()methods. - In Glide,
srem()requires an array of members, andsismember()returns 1 or 0.
Redisson
RSet<String> set = redisson.getSet("set");set.add("a");set.add("b");set.add("c");
boolean removed1 = set.remove("a"); // trueboolean removed2 = set.remove("b"); // true
boolean isMember = set.contains("c"); // true (is member)boolean notMember = set.contains("a"); // false (not member)Glide
client.sadd("set", new String[]{"a", "b", "c"});Long removed = client.srem("set", new String[]{"a", "b"}).get(); // 2 (members removed)
Long isMember = client.sismember("set", "c").get(); // 1 (is member)Long notMember = client.sismember("set", "a").get(); // 0 (not member)Sorted Set Operations
Section titled “Sorted Set Operations”ZADD & ZRANGE
Section titled “ZADD & ZRANGE”The ZADD command adds one or more members with scores to a sorted set, while ZRANGE retrieves members from a sorted set by index range.
- In Redisson,
RScoredSortedSetprovidesadd()andvalueRange()methods. - In Glide,
zadd()requires an array of score-member pairs.
Redisson
RScoredSortedSet<String> sortedSet = redisson.getScoredSortedSet("sortedSet");
// Add members with scoressortedSet.add(1.0, "one");sortedSet.add(2.0, "two");sortedSet.add(3.0, "three");
// Get range of membersCollection<String> members = sortedSet.valueRange(0, -1); // [one, two, three]
// With scoresCollection<ScoredEntry<String>> withScores = sortedSet.entryRange(0, -1);// [{one=1.0}, {two=2.0}, {three=3.0}]Glide
// Add members with scoresObject[] scoreMembers = new Object[] { new Object[] { 1.0, "one" }, new Object[] { 2.0, "two" }, new Object[] { 3.0, "three" }};Long added = client.zadd("sortedSet", scoreMembers).get(); // 3 (members added)
// Get range of membersString[] members = client.zrange("sortedSet", 0, -1).get(); // ["one", "two", "three"]
// With scoresObject[] withScores = client.zrange("sortedSet", 0, -1, "WITHSCORES").get();// ["one", "1", "two", "2", "three", "3"]ZREM & ZSCORE
Section titled “ZREM & ZSCORE”The ZREM command removes one or more members from a sorted set, while ZSCORE returns the score of a member in a sorted set.
- In Redisson,
RScoredSortedSetprovidesremove()andgetScore()methods. - In Glide,
zrem()requires an array of members.
Redisson
RScoredSortedSet<String> sortedSet = redisson.getScoredSortedSet("sortedSet");sortedSet.add(1.0, "one");sortedSet.add(2.0, "two");sortedSet.add(3.0, "three");
boolean removed1 = sortedSet.remove("one"); // trueboolean removed2 = sortedSet.remove("two"); // true
Double score = sortedSet.getScore("three"); // 3.0Glide
Object[] scoreMembers = new Object[] { new Object[] { 1.0, "one" }, new Object[] { 2.0, "two" }, new Object[] { 3.0, "three" }};client.zadd("sortedSet", scoreMembers);
Long removed = client.zrem("sortedSet", new String[]{"one", "two"}).get(); // 2 (members removed)
String score = client.zscore("sortedSet", "three").get(); // "3"ZRANK & ZREVRANK
Section titled “ZRANK & ZREVRANK”The ZRANK command returns the rank (position) of a member in a sorted set, while ZREVRANK returns the rank in reverse order.
- In Redisson,
RScoredSortedSetprovidesrank()andrevRank()methods. - Glide provides direct
zrank()andzrevrank()methods.
Redisson
RScoredSortedSet<String> sortedSet = redisson.getScoredSortedSet("sortedSet");sortedSet.add(1.0, "one");sortedSet.add(2.0, "two");sortedSet.add(3.0, "three");
Integer rank = sortedSet.rank("two"); // 1 (0-based index)Integer revRank = sortedSet.revRank("two"); // 1 (0-based index from end)Glide
Object[] scoreMembers = new Object[] { new Object[] { 1.0, "one" }, new Object[] { 2.0, "two" }, new Object[] { 3.0, "three" }};client.zadd("sortedSet", scoreMembers);
Long rank = client.zrank("sortedSet", "two").get(); // 1 (0-based index)Long revRank = client.zrevrank("sortedSet", "two").get(); // 1 (0-based index from end)Transactions
Section titled “Transactions”Transactions (MULTI / EXEC)
Section titled “Transactions (MULTI / EXEC)”The MULTI command starts a transaction block, while EXEC executes all commands issued after MULTI.
- In Redisson, transactions are handled using
RBatchfor batching operations. - In Glide, transactions are represented as a
Transactionobject.
Redisson
// Create a batch (similar to transaction)RBatch batch = redisson.createBatch();
// Add commands to the batchbatch.getBucket("key").setAsync("value");batch.getAtomicLong("counter").incrementAndGetAsync();batch.getBucket("key").getAsync();
// Execute the batchBatchResult<?> result = batch.execute();List<?> responses = result.getResponses();System.out.println(responses); // [void, 1, value]Glide
import glide.api.models.Transaction;
// Initialize a transaction objectTransaction transaction = new Transaction();
// Add commands to the transactiontransaction.set("key", "value");transaction.incr("counter");transaction.get("key");
// Execute the transactionObject[] result = client.exec(transaction).get();System.out.println(Arrays.toString(result)); // [OK, 1, value]Lua Scripts
Section titled “Lua Scripts”EVAL / EVALSHA
Section titled “EVAL / EVALSHA”The EVAL command executes a Lua script on the server, while EVALSHA executes a script cached on the server using its SHA1 hash.
- In Redisson, scripts are executed using
RScriptinterface. - In Glide, scripts are created using the
Scriptclass and executed withinvokeScript().
Redisson
RScript script = redisson.getScript();
// EVALString luaScript = "return 'Hello, Lua!'";Object result = script.eval(RScript.Mode.READ_ONLY, luaScript, RScript.ReturnType.VALUE);System.out.println(result); // Hello, Lua!
// With keys and argumentsString scriptWithArgs = "return {KEYS[1], ARGV[1]}";List<Object> resultWithArgs = script.eval(RScript.Mode.READ_ONLY, scriptWithArgs, RScript.ReturnType.MULTI, Arrays.asList("key"), "value");System.out.println(resultWithArgs); // [key, value]
// EVALSHAString sha1 = script.scriptLoad(scriptWithArgs);List<Object> shaResult = script.evalSha(RScript.Mode.READ_ONLY, sha1, RScript.ReturnType.MULTI, Arrays.asList("key"), "value");System.out.println(shaResult); // [key, value]Glide
import glide.api.models.Script;import glide.api.models.ScriptOptions;
// EVALString script = "return 'Hello, Lua!'";Script luaScript = new Script(script, false);String result = (String) client.invokeScript(luaScript).get();System.out.println(result); // Hello, Lua!
// With keys and argumentsString scriptWithArgs = "return {KEYS[1], ARGV[1]}";Script luaScriptWithArgs = new Script(scriptWithArgs, false);ScriptOptions options = ScriptOptions.builder() .key("key") .arg("value") .build();Object[] resultWithArgs = (Object[]) client.invokeScript(luaScriptWithArgs, options).get();System.out.println(Arrays.toString(resultWithArgs)); // [key, value]Authentication
Section titled “Authentication”The AUTH command authenticates a client connection to the Valkey server.
- In Redisson, authentication is handled in the configuration during client creation.
- In Glide, authentication can be updated using
updateConnectionPassword().
Redisson
// Authentication is handled during configurationConfig config = new Config();config.useSingleServer() .setAddress("redis://localhost:6379") .setPassword("mypass");RedissonClient redisson = Redisson.create(config);Glide
String result = client.updateConnectionPassword("mypass", true).get(); // OKCustom Commands
Section titled “Custom Commands”Custom Commands
Section titled “Custom Commands”Both Redisson and Glide provide ways to execute custom commands.
- In Redisson, you can execute raw commands using the low-level command executor.
- In Glide, you can execute raw commands using
customCommand().
Redisson
// Redisson doesn't have a direct way to execute arbitrary commands// You would typically use the appropriate high-level API methods// For truly custom commands, you'd need to access the underlying connectionGlide
// Execute a raw commandString rawResult = client.customCommand(new String[]{"SET", "key", "value"}).get();System.out.println(rawResult); // OKConnection Management
Section titled “Connection Management”Close / Disconnect
Section titled “Close / Disconnect”Properly closing connections is important to free up resources and avoid connection leaks.
- In Redisson, you need to call
shutdown()to properly close all connections and resources. - In Glide, you only need to call
close()on the client.
Redisson
// Shutdown Redisson client (closes all connections and resources)redisson.shutdown();
// For graceful shutdown with timeoutredisson.shutdown(10, 30, TimeUnit.SECONDS);Glide
// Close client (works for both standalone and cluster)client.close();