CacheKeyEnum.java 1.78 KB
/**
 * 
 */
package com.yohoufo.user.cache;

import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import org.apache.commons.lang3.StringUtils;

import java.util.concurrent.TimeUnit;

/**
 * 描述:
 * 
 * @author craig.qin 2018年9月17日
 */
public enum CacheKeyEnum {

	// user - passport -authorize
	AUTHORIZE_INFO_KEY("ufo:user:authorizeInfo:","实名认证信息", 2, TimeUnit.HOURS),

	ZHI_MA_CERT_KEY("ufo:user:zhiMaCert:","芝麻认证信息", 2, TimeUnit.HOURS),

	STORED_SELLER_KEY("ufo:user:storedSeller:","商家入驻信息", 2, TimeUnit.HOURS),

	USER_PRODUCT_FAVORITE_ZSET_KEY("ufo:user:product:favorite:","用户商品收藏集合", 180, TimeUnit.DAYS),

	SUPER_ENTRY_SELLER_LIST("ufo:user:superEntrySeller:list","超级入驻商家集合", 1, TimeUnit.HOURS)
	;

	// 缓存的key
	private String cacheKey;

	private String desc;

	// 默认的过期时间
	private int defaultExpireTime;

	// 缓存时间单位
	private TimeUnit timeUnit;


	CacheKeyEnum(String cacheKey,  String desc, int defaultExpireTime, TimeUnit timeUnit) {
		this.cacheKey = cacheKey;
		this.desc = desc;
		this.defaultExpireTime = defaultExpireTime;
		this.timeUnit = timeUnit;
	}

	/**
	 * 获取该枚举的信息
	 * 
	 * @param key
	 * @return
	 */
	public static CacheKeyEnum getEnumByKey(String key) {
		if (StringUtils.isEmpty(key)) {
			return null;
		}
		for (CacheKeyEnum e : values()) {
			if (key.equalsIgnoreCase(e.name())) {
				return e;
			}
		}
		return null;
	}

	public String getCacheKey() {
		return cacheKey;
	}

	public int getDefaultExpireTime() {
		return defaultExpireTime;
	}

	public TimeUnit getTimeUnit() {
		return timeUnit;
	}

	public String getDesc() {
		return desc;
	}

	public RedisKeyBuilder getKey(){
		return RedisKeyBuilder.newInstance().appendFixed(cacheKey);
	}
}