Skip to content

Commit

Permalink
Merge branch 'master' of github.com:eclipse/jnosql-diana-driver
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviojava committed Jan 18, 2018
2 parents 52d1bd5 + 62e1c45 commit 0e90c2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ class RedisSet<T> extends RedisCollection<T> implements Set<T> {
@Override
public boolean add(T e) {
Objects.requireNonNull(e);
jedis.sadd(keyWithNameSpace, JSONB.toJson(e));
return false;
if (isString) {
jedis.sadd(keyWithNameSpace, e.toString());
} else {
jedis.sadd(keyWithNameSpace, JSONB.toJson(e));
}
return true;
}

@Override
Expand Down Expand Up @@ -92,7 +96,7 @@ protected List<T> toArrayList() {
Set<String> redisValues = jedis.smembers(keyWithNameSpace);
List<T> list = new ArrayList<>();
for (String redisValue : redisValues) {
if(isString) {
if (isString) {
list.add((T) redisValue);
} else {
list.add(JSONB.fromJson(redisValue, clazz));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class RedisSetStringTest {
Expand All @@ -44,6 +45,14 @@ public void shouldAddUsers() {
users.add("otaviojava");
assertTrue(users.size() == 1);

String user = users.iterator().next();
assertEquals("otaviojava", user);
}

@Test
public void shouldRemoveSet() {
assertTrue(users.isEmpty());
users.add("otaviojava");
users.remove("otaviojava");
assertTrue(users.isEmpty());
}
Expand Down

0 comments on commit 0e90c2c

Please sign in to comment.