CacheKeyBuilder.java
1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.yohoufo.msg.cache;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import org.slf4j.helpers.MessageFormatter;
/**
* Created by chenchao on 2018/10/16.
*/
public class CacheKeyBuilder {
public enum KeyTemp{
BASE_NOTICE_CASE("ufo:msg:notice:case:","metaKey:{}"),
LOWER_PRICE_NOTICE_SELLER("ufo:msg:lowerPrice:seller:","uid:{}:storageId:{}case:{}:method:{}:dtp{}:num");
private String fix;
private String placeHolder;
KeyTemp(String fix, String placeHolder) {
this.fix = fix;
this.placeHolder = placeHolder;
}
public String fillPlaceHolder(Object[] args){
if (placeHolder == null){
return null;
}
return MessageFormatter.arrayFormat(placeHolder, args).getMessage();
}
public RedisKeyBuilder builderKey(Object[] args){
String appendPart = fillPlaceHolder(args);
return new RedisKeyBuilder().appendFixed(fix).appendVar(appendPart);
}
}
public static RedisKeyBuilder lowerPriceNoticeSellerKey(int uid, int storageId, Integer caseId, Short method, String dtp){
return KeyTemp.LOWER_PRICE_NOTICE_SELLER.builderKey(new Object[]{uid, storageId, caseId, method, dtp});
}
public static RedisKeyBuilder baseNoticeCaseKey(String metaKey){
return KeyTemp.BASE_NOTICE_CASE.builderKey(new Object[]{metaKey});
}
}