All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lordofthejars.nosqlunit.demo.redis.BookManager Maven / Gradle / Ivy

There is a newer version: 1.0.0-rc.5
Show newest version
package com.lordofthejars.nosqlunit.demo.redis;

import java.util.HashMap;
import java.util.Map;

import redis.clients.jedis.Jedis;

import com.lordofthejars.nosqlunit.demo.model.Book;


public class BookManager {
	
	private static final String TITLE_FIELD_NAME = "title";
	private static final String NUMBER_OF_PAGES = "numberOfPages";
	
	private Jedis jedis;
	
	public BookManager(Jedis jedis) {
		this.jedis = jedis;
	}
	
	public void insertBook(Book book) {
		
		Map fields = new HashMap();
		
		fields.put(TITLE_FIELD_NAME, book.getTitle());
		fields.put(NUMBER_OF_PAGES, Integer.toString(book.getNumberOfPages()));
		
		jedis.hmset(book.getTitle(), fields);
	}

	public Book findBookByTitle(String title) {
		
		Map fields = jedis.hgetAll(title);
		return new Book(fields.get(TITLE_FIELD_NAME), Integer.parseInt(fields.get(NUMBER_OF_PAGES)));
		
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy