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

com.infusers.auth.cache.redis.UserRedisUtility Maven / Gradle / Ivy

There is a newer version: 2025.01.0002
Show newest version
package com.infusers.auth.cache.redis;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.google.gson.Gson;
import com.infusers.core.user.APIUser;

@Service
public class UserRedisUtility {
	
	@Qualifier("redisTemplate")
	@Autowired(required = true)
	private RedisTemplate redisTemplate;
	
	@Autowired
	Gson gson;
	
	public void setValue(final String key, APIUser user) {
		redisTemplate.opsForValue().set(key, gson.toJson(user));
		redisTemplate.expire(key, 10, TimeUnit.MINUTES);
	}
	
	public APIUser getValue(final String key) {
		if(key!=null && key.trim().length()>0) {
			return gson.fromJson(redisTemplate.opsForValue().get(key), APIUser.class);
		}
		return null;
	}
	
	public void deleteKeyfromRedis(String key) {
		redisTemplate.delete(key);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy