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

com.tmsps.ne4springboot.token.TokenService Maven / Gradle / Ivy

There is a newer version: 3.2.4.2
Show newest version
package com.tmsps.ne4springboot.token;

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

/**
 * Token 相关工具类
 *
 * @author 冯晓东 [email protected]
 */
@Service
public class TokenService {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 同步获取token值并移除
     *
     * @param key
     * @return
     */
    public String getAsyncToken(String key) {
        // 压测代码
		/*
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		*/
        // 无需上锁, 获取的时候直接移除.
        String token = redisTemplate.opsForValue().getAndSet(key, "");
        redisTemplate.delete(key);
        return token;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy