package com.neusoft.smart.pos.framework.utils;


import com.neusoft.smart.pos.framework.service.RedisManagerService;

import java.util.Map;

/**
 * Redis工具类
 * @author zhangchuanfu
 */
public class RedisUtils {
	
	protected static RedisManagerService instanceRedis(){
		RedisManagerService redisManagerService = (RedisManagerService)SpringUtils.getBean("redisManagerService");
		return redisManagerService;
	}
	
	/**
	 * 获取缓存信息内容使用方法
	 * @return Object
	 */
	public static Object getRedisValue(String key){
		RedisManagerService redisManagerService = instanceRedis();
		Object resultObj = redisManagerService.get(key);
		return resultObj;
	}
	
	/**
	 * 删除缓存信息内容使用方法
	 */
	public static void removeRedisValue(String key){
		RedisManagerService redisManagerService = instanceRedis();
		redisManagerService.del(key);
	}
	
	/**
	 * 添加缓存信息内容使用方法
	 * @return boolean
	 */
	public static boolean saveRedisValue(String key,Object value){
		RedisManagerService redisManagerService = instanceRedis();
		return redisManagerService.set(key, value);
	}
	
	/**
	 * 添加缓存信息内容使用方法,可设置缓存时间
	 * @return boolean
	 */
	public static boolean saveRedisValue(String key,Object value,Long expireTime){
		RedisManagerService redisManagerService = instanceRedis();
		return redisManagerService.set(key, value, expireTime);
	}
	
	public static Map<Object,Object> getForHash(String key){
		RedisManagerService redisManagerService = instanceRedis();
		return redisManagerService.hmget(key);
	}
	
	public static Object getForHash(String key,String hashKey){
		RedisManagerService redisManagerService = instanceRedis();
		return redisManagerService.hHasKey(key, hashKey);
	}
	
	public static boolean setForHash(String key,String hashKey,Object value){
		RedisManagerService redisManagerService = instanceRedis();
		return redisManagerService.hset(key, hashKey, value);
	}

	public static Long setIncr(String key){
		return instanceRedis().incr(key,1);
	}

	public static Long setIncr(String key,Long expire){
		expire(key,expire);
		return instanceRedis().incr(key,1);
	}

	public static Boolean expire(String key,Long expire){
		return instanceRedis().expire(key,expire);
	}
	
}
