2. What is Redis
Is an advanced key-value store.
A redis serve can contain the following data structures:
● strings
● hashes
● lists
● sets
● sorted sets
7. Even more...
Creating a simple hashmap
Hashes
Redis Hashes are maps between string fields and string values, so they are the perfect data type to represent objects (eg: A User with a
number of fields like name, surname, age, and so forth):
redis 127.0.0.1:6379> HMSET user:1 username antirez password Mirko age 33
OK
redis 127.0.0.1:6379> HGETALL user:1
1) "username"
2) "antirez"
3) "password"
4) "Mirko"
5) "age"
6) "33"
Want to check is a user exists? (Login)
HMGET user:1000 password password
8. Ok, perfect. But what in
Java?
Very nice and easy project is
https://github.com/xetorthio/jedis
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Jedis jedis = new Jedis("localhost");
jedis.set("foo", "bar");
String value = jedis.get("foo");