Redis
Posted by Bruce Tsai
04/01/2016
Redis 是 NoSQL 的一種,屬性鍵值型式(key-value)的資料庫,資料存在記憶體中。依其特性來說,很適合用於高擴充性的雲端資料、快取服務等。另外 Redis 也支援 PUB/SUB 的發佈模式(Pub/Sub – Redis),若是需要簡易的訊息佇列也可以考慮使用 Redis 來實做(使用Redis做简单的消息队列)。
import redis.clients.jedis.Jedis;
public class RedisListJava {
public static void main(String[] args) {
//Connecting to Redis server on localhost
Jedis jedis = new Jedis("localhost");
System.out.println("Connection to server sucessfully");
//store data in redis list
jedis.lpush("tutorial-list", "Redis");
jedis.lpush("tutorial-list", "Mongodb");
jedis.lpush("tutorial-list", "Mysql");
// Get the stored data and print it
List<String> list = jedis.lrange("tutorial-list", 0, 5);
for (int i = 0; i < list.size(); i++) {
System.out.println("Stored string in redis:: " + list.get(i));
}
}
}