日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php+redis+设置前缀,spring使用Redis自定义前缀后缀名(去掉SimpleKey []+自定义)

發布時間:2024/7/5 php 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php+redis+设置前缀,spring使用Redis自定义前缀后缀名(去掉SimpleKey []+自定义) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

標簽:

spring中自動加上?SimpleKey [] 解決方案

一、自定義后綴名

1、定義類實現KeyGenerator接口

MyKeyGenerator

package com.wbg.springRedis.service.impl;

import org.springframework.cache.interceptor.KeyGenerator;

import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Component("myKeyGenerator")

public class MyKeyGenerator implements KeyGenerator {

@Override

public Object generate(Object target, Method method, Object... params) {

//返回后綴名

//return method.getName();

//注意,這里不能返回null,否則會報錯

//java.lang.IllegalArgumentException:

// Null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder[public java.util.List com.wbg.springRedis.service.impl.RoleServiceImpl.listAll()] caches=[listAll] | key='' | keyGenerator='myKeyGenerator' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'

return "";

}

}

2、注解使用:

@Cacheable(value = "listAll", keyGenerator = "myKeyGenerator")

已經解決

二、自定義前綴:

@Bean

RedisCacheManager cacheManager() {

RedisCacheConfiguration configuration = RedisCacheConfiguration

.defaultCacheConfig()

.computePrefixWith(cacheName -> "redis" + cacheName)

.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.string()))

.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.java()));

return RedisCacheManager.builder(redisConnectionFactory()).cacheDefaults(configuration).build();

}

標簽:

來源: https://www.cnblogs.com/weibanggang/p/10191028.html

總結

以上是生活随笔為你收集整理的php+redis+设置前缀,spring使用Redis自定义前缀后缀名(去掉SimpleKey []+自定义)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。