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

com.jn.agileway.redis.core.RedisTemplate Maven / Gradle / Ivy

Go to download

Provides a large number of convenient redis tools: distributed locks, distributed count, distributed cache, distributed id generator, jdk collection implements, the enhanced RedisTemplate based on a specified key prefix and the agileway-codec module

There is a newer version: 5.0.4
Show newest version
package com.jn.agileway.redis.core;

import com.jn.agileway.redis.core.script.RedisLuaScript;
import com.jn.agileway.redis.core.script.RedisLuaScriptRepository;
import org.springframework.data.redis.serializer.RedisSerializer;

import java.util.List;

public class RedisTemplate extends org.springframework.data.redis.core.RedisTemplate {
    private RedisLuaScriptRepository luaScriptRepository;

    public RedisLuaScript findRedisScript(String scriptId) {
        if (luaScriptRepository != null) {
            return luaScriptRepository.getById(scriptId);
        }
        return null;
    }

    /*
     * (non-Javadoc)
     * @see org.springframework.data.redis.core.RedisOperations#execute(org.springframework.data.redis.core.script.RedisScript, java.util.List, java.lang.Object[])
     */
    public  T executeScript(String scriptId, List keys, Object... args) {
        RedisLuaScript redisLuaScript = findRedisScript(scriptId);
        if (redisLuaScript != null) {
            return execute(redisLuaScript, keys, args);
        }
        return null;
    }


    /*
     * (non-Javadoc)
     * @see org.springframework.data.redis.core.RedisOperations#execute(org.springframework.data.redis.core.script.RedisScript, org.springframework.data.redis.serializer.RedisSerializer, org.springframework.data.redis.serializer.RedisSerializer, java.util.List, java.lang.Object[])
     */
    public  T executeScript(String scriptId, RedisSerializer argsSerializer, RedisSerializer resultSerializer, List keys, Object... args) {
        RedisLuaScript redisLuaScript = findRedisScript(scriptId);
        if (redisLuaScript != null) {
            return execute(redisLuaScript, argsSerializer, resultSerializer, keys, args);
        }
        return null;
    }


    public RedisLuaScriptRepository getLuaScriptRepository() {
        return luaScriptRepository;
    }

    public void setLuaScriptRepository(RedisLuaScriptRepository luaScriptRepository) {
        this.luaScriptRepository = luaScriptRepository;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy