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

com.redis.spring.batch.util.CodecUtils Maven / Gradle / Ivy

There is a newer version: 4.0.7
Show newest version
package com.redis.spring.batch.util;

import java.util.function.Function;

import io.lettuce.core.codec.ByteArrayCodec;
import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.codec.StringCodec;

public abstract class CodecUtils {

    private CodecUtils() {
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static  Function stringKeyFunction(RedisCodec codec) {
        if (codec instanceof StringCodec) {
            return (Function) Function.identity();
        }
        return key -> codec.decodeKey(StringCodec.UTF8.encodeKey(key));
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static  Function toStringKeyFunction(RedisCodec codec) {
        if (codec instanceof StringCodec) {
            return (Function) Function.identity();
        }
        return key -> StringCodec.UTF8.decodeKey(codec.encodeKey(key));
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static  Function stringValueFunction(RedisCodec codec) {
        if (codec instanceof StringCodec) {
            return (Function) Function.identity();
        }
        return value -> codec.decodeValue(StringCodec.UTF8.encodeValue(value));
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static  Function toStringValueFunction(RedisCodec codec) {
        if (codec instanceof StringCodec) {
            return (Function) Function.identity();
        }
        return value -> StringCodec.UTF8.decodeValue(codec.encodeValue(value));
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static  Function byteArrayKeyFunction(RedisCodec codec) {
        if (codec instanceof ByteArrayCodec) {
            return (Function) Function.identity();
        }
        return key -> codec.decodeKey(ByteArrayCodec.INSTANCE.encodeKey(key));
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static  Function toByteArrayKeyFunction(RedisCodec codec) {
        if (codec instanceof ByteArrayCodec) {
            return (Function) Function.identity();
        }
        return key -> ByteArrayCodec.INSTANCE.decodeKey(codec.encodeKey(key));
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static  Function byteArrayValueFunction(RedisCodec codec) {
        if (codec instanceof ByteArrayCodec) {
            return (Function) Function.identity();
        }
        return value -> codec.decodeValue(ByteArrayCodec.INSTANCE.encodeValue(value));
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static  Function toByteArrayValueFunction(RedisCodec codec) {
        if (codec instanceof ByteArrayCodec) {
            return (Function) Function.identity();
        }
        return value -> ByteArrayCodec.INSTANCE.decodeValue(codec.encodeValue(value));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy