转载: https://blog.csdn.net/eff 666/article/details/52998688? 单击locationNum=3fps=1打开链接
1、Redis简介
redis 3354 remotedictionaryserver可以直接理解为基于远程字典服务,即Key-Value模式Memcached Database Persistence。 Redis以开源ANSI C语言编写,是一种符合BSD协议、支持网络、基于内存的可持续日志型Key-Value数据库,可提供多种语言的API。
通常称为数据结构服务。 因为“值”可以是字符串(String )、散列(Map )、列表(list )、集合(sets )、有序集合(sorted sets )等类型。 简单地说,Redis是一个nosql数据库,在开发过程中经常用作高速缓存。 Jedis是Redis在Java中的redis- client。
2、Redis和其他密钥值缓存的特征
)1) Redis支持数据持久性,可以将内存中的数据保存到磁盘上,并在重新启动时重新加载使用。
)2) Redis不仅支持简单的密钥值类型的数据,还提供数据结构的存储,如list、set、zset和hash。
)3) Redis支持数据备份,即主模式数据备份。
3、Java如何使用redis
目前,Redis大约有三个基于Java语言的客户端。 分别是JREdis、Jedis和Redis4J。 这里只说Jedis。 因为这是唯一正式提供的Redis Client For Java Provider!
4、简单使用redis
4.1 Maven Pom.xml配置
ependencygroupidredis.clients/groupidartifactidjedis/artifactidversion2.8.1/versiontypejar/typescopecompile/ssssion
#properties部署#最大分配对象数redis.pool.maxTotal=1024#可以保持最大idel状态的对象数redis.pool.maxIdle=200#池中返回对象调用最大等待时间redis.pool.maxwaitmillis=1000 # borrow object方法时,redis.pool.testOnBorrow=true#将调用return Object方法是否进行有效性检查redis.pool.testonreturn=true # IP redis.IP=xxxx # port redis.port=63791234567891012131415164.3初始化及其
import redis.clients.jedis.jedis; import redis.clients.jedis.Jedi spool; import redis.clients.jedis.jedis poolconfig; import java.util.ResourceBundle; 公共类redis { privatestaticjedispoolpool; 静态{//要读取配置文件的resourcebundlebundle=resource bundle.get bundle (' redis ' ); if(bundle==null ) thrownewillegalargumentexception ([ redis.properties ] is not found! ' ); } jedispoolconfigconfig=newjedispoolconfig (; config.setmaxtotal (integer.value of ) bundle.getstring (' redis.pool.max total ' ); config.set maxidle (integer.value of ) bundle.getstring (' redis.pool.maxidle ' ); config.setmaxwaitmillis (long.value of (bundle.getstring (redis.pool.maxwaitmillis ) ); config.settestonborrow (boolean.value of ) bundle.getstring (redis.pool.testonborrow ) ); config.settestonreturn (boolean.value of ) bundle.getstring (redis.pool.testonreturn ) ); pool=newJedispool(config,bundle.getstring )、integer.valueof ) bundle.getstring )、redis.port } publicstaticticvotic //system.out.println (jedis.get (redis.pool.max total ) ); system.out.println(Jedis; //释放目标池//上次使用后,请不要忘记释放Jedis对象//pool.returnresource(Jedis )。 虽然高版本已正式取消了此方法,但请使用以下方法创建try { jedis=pool.getResource (; (Finally(if ) Jedis!=null(Jedis.close ); } } }}