题记
在工作和学习中啊,比如说JAVA开发,要使用Redis,首先要引入一个RedisTemplate类.
在此,将所有的方法都已经注释出来了.
//// Source code recreated from a .class file by IntelliJ IDEA// (powered by Fernflower decompiler)//package org.springframework.data.redis.core;import java.io.Closeable;import java.lang.reflect.Proxy;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.Date;import java.util.Iterator;import java.util.LinkedHashSet;import java.util.List;import java.util.Map;import java.util.Set;import java.util.concurrent.TimeUnit;import org.springframework.beans.factory.BeanClassLoaderAware;import org.springframework.dao.DataAccessException;import org.springframework.dao.InvalidDataAccessApiUsageException;import org.springframework.data.redis.connection.DataType;import org.springframework.data.redis.connection.RedisConnection;import org.springframework.data.redis.connection.RedisConnectionFactory;import org.springframework.data.redis.connection.SortParameters;import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;import org.springframework.data.redis.core.ZSetOperations.TypedTuple;import org.springframework.data.redis.core.query.QueryUtils;import org.springframework.data.redis.core.query.SortQuery;import org.springframework.data.redis.core.script.DefaultScriptExecutor;import org.springframework.data.redis.core.script.RedisScript;import org.springframework.data.redis.core.script.ScriptExecutor;import org.springframework.data.redis.core.types.RedisClientInfo;import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;import org.springframework.data.redis.serializer.RedisSerializer;import org.springframework.data.redis.serializer.SerializationUtils;import org.springframework.data.redis.serializer.StringRedisSerializer;import org.springframework.transaction.support.TransactionSynchronizationManager;import org.springframework.util.Assert;import org.springframework.util.ClassUtils;import org.springframework.util.CollectionUtils;public class RedisTemplate extends RedisAccessor implements RedisOperations , BeanClassLoaderAware { private boolean enableTransactionSupport = false; private boolean exposeConnection = false; private boolean initialized = false; private boolean enableDefaultSerializer = true; private RedisSerializer defaultSerializer; private ClassLoader classLoader; private RedisSerializer keySerializer = null; private RedisSerializer valueSerializer = null; private RedisSerializer hashKeySerializer = null; private RedisSerializer hashValueSerializer = null; private RedisSerializer stringSerializer = new StringRedisSerializer(); private ScriptExecutor scriptExecutor; private ValueOperations valueOps; private ListOperations listOps; private SetOperations setOps; private ZSetOperations zSetOps; private GeoOperations geoOps; private HyperLogLogOperations hllOps; public RedisTemplate() { } //afterPropertiesSet (初始化操作)加载配置后执行 public void afterPropertiesSet() { super.afterPropertiesSet(); boolean defaultUsed = false; //serializer 序列化 if (this.defaultSerializer == null) { this.defaultSerializer = new JdkSerializationRedisSerializer(this.classLoader != null ? this.classLoader : this.getClass().getClassLoader()); } //enable 使能够,提供做…的权利[措施]; 使可能; 授予权利或方法; if (this.enableDefaultSerializer) { if (this.keySerializer == null) { this.keySerializer = this.defaultSerializer; defaultUsed = true; } if (this.valueSerializer == null) { this.valueSerializer = this.defaultSerializer; defaultUsed = true; } if (this.hashKeySerializer == null) { this.hashKeySerializer = this.defaultSerializer; defaultUsed = true; } if (this.hashValueSerializer == null) { this.hashValueSerializer = this.defaultSerializer; defaultUsed = true; } } if (this.enableDefaultSerializer && defaultUsed) { Assert.notNull(this.defaultSerializer, "default serializer null and not all serializers initialized"); } //script脚本 //Executor 遗嘱执行人; 执行者; 实行者; if (this.scriptExecutor == null) { this.scriptExecutor = new DefaultScriptExecutor(this); } //初始化完成 this.initialized = true; } //execute 执行 exposeConnection暴露连接 public T execute(RedisCallback action) { return this.execute(action, this.isExposeConnection()); } public T execute(RedisCallback action, boolean exposeConnection) { return this.execute(action, exposeConnection, false); } //pipeline 管道 public T execute(RedisCallback action, boolean exposeConnection, boolean pipeline) { Assert.isTrue(this.initialized, "template not initialized; call afterPropertiesSet() before using it"); Assert.notNull(action, "Callback object must not be null"); RedisConnectionFactory factory = this.getConnectionFactory(); RedisConnection conn = null; Object var11; try { //enableTransactionSupport 是否支持事务 if (this.enableTransactionSupport) { conn = RedisConnectionUtils.bindConnection(factory, this.enableTransactionSupport); } else { conn = RedisConnectionUtils.getConnection(factory); } //现存的; 目前的; boolean existingConnection = TransactionSynchronizationManager.hasResource(factory); RedisConnection connToUse = this.preProcessConnection(conn, existingConnection); boolean pipelineStatus = connToUse.isPipelined(); if (pipeline && !pipelineStatus) { connToUse.openPipeline(); } RedisConnection connToExpose = exposeConnection ? connToUse : this.createRedisConnectionProxy(connToUse); T result = action.doInRedis(connToExpose); if (pipeline && !pipelineStatus) { connToUse.closePipeline(); } var11 = this.postProcessResult(result, connToUse, existingConnection); } finally { RedisConnectionUtils.releaseConnection(conn, factory); } return var11; } public T execute(SessionCallback session) { Assert.isTrue(this.initialized, "template not initialized; call afterPropertiesSet() before using it"); Assert.notNull(session, "Callback object must not be null"); RedisConnectionFactory factory = this.getConnectionFactory(); RedisConnectionUtils.bindConnection(factory, this.enableTransactionSupport); Object var3; try { var3 = session.execute(this); } finally { RedisConnectionUtils.unbindConnection(factory); } return var3; } //executePipelined 执行管道 public List
这个类基本上就是所有的RedisTemplate.方法就可以用了哟。
例如:
/**保存成功后同步到缓存中**/ redisTemplate.opsForList().rightPush(CachePrefix.CERT_BUNDLE_LIST + "_" + iosBundle.getCertId(), iosBundle.getId());