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

com.lorne.sds.server.service.impl.RedisServiceImpl Maven / Gradle / Ivy

There is a newer version: 1.2.5
Show newest version
package com.lorne.sds.server.service.impl;

import com.lorne.core.framework.utils.encode.MD5Util;
import com.lorne.sds.server.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * create by lorne on 2017/10/13
 */
@Service
public class RedisServiceImpl implements RedisService {


    @Autowired
    private RedisTemplate redisTemplate;


    @Override
    public List models() {
        return new ArrayList<>(redisTemplate.keys(sds_prefix + "*"));
    }

    @Override
    public Set all(String key) {
        String mkey = sds_prefix + key;
        return redisTemplate.opsForSet().members(mkey);
    }

    @Override
    public void removeAll(String key) {
        String mkey = sds_prefix + key;
        redisTemplate.delete(mkey);
    }

    @Override
    public void remove(String key, String uniqueKey) {
        String mkey = sds_prefix + key;
        redisTemplate.opsForSet().remove(mkey, uniqueKey);

        removeKey(key, uniqueKey);
    }


    @Override
    public void add(String key, String value) {
        String mkey = sds_prefix + key;
        redisTemplate.opsForSet().add(mkey, value);
    }

    @Override
    public void putKey(String modelName, String uniqueKey, String key) {
        String val = modelName + "#" + uniqueKey;
        ValueOperations operations = redisTemplate.opsForValue();
        operations.set(key_prefix + key, val);
        operations.set(val_prefix + val, key);
    }

    @Override
    public void removeKey(String modelName, String uniqueKey) {
        String val = modelName + "#" + uniqueKey;
        String mkey = val_prefix + val;
        ValueOperations operations = redisTemplate.opsForValue();
        String key = operations.get(mkey);
        redisTemplate.delete(key_prefix + key);
        redisTemplate.delete(val_prefix + val);
    }

    @Override
    public String getModelByKey(String key) {
        ValueOperations operations = redisTemplate.opsForValue();
        return operations.get(key_prefix + key);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy