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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

函数集成redis与Spring集成

發布時間:2025/3/20 javascript 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 函数集成redis与Spring集成 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

新手發帖,很多方面都是剛入門,有錯誤的地方請大家見諒,歡迎批評指正

????redis與Spring集成比較簡單,本文不觸及Spring的一些基本概念,讀都需先具有Spring的相干知識。

????先在maven中添加依賴

????pom.xml

<!-- redis --><dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>2.0.0</version></dependency><!-- redis -->

????applicationContext-redis.xml加入你的Spring context

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:mongo="http://www.springframework.org/schema/data/mongo"xsi:schemaLocation="http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/data/mongohttp://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"><property name="maxActive" value="50" /><property name="maxIdle" value="10" /><property name="maxWait" value="1000" /><property name="testOnBorrow" value="true" /></bean><bean id="jedis.shardInfo" class="redis.clients.jedis.JedisShardInfo"><constructor-arg index="0" value="172.21.1.121" /><constructor-arg index="1" value="6379" /></bean><bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool"><constructor-arg index="0" ref="jedisPoolConfig" /><constructor-arg index="1"><list><ref bean="jedis.shardInfo" /></list></constructor-arg></bean> </beans> 每日一道理
因為自信,在呀呀學語時,我靠著纖嫩的雙腿,邁出人生的第一步;因為自信,我一次次將第一名的獎狀高高舉起;因為自信,我毫不吝惜地剪掉飄逸的長發,在運動場上展現風采……感謝自信,它給了我一雙翅膀,讓我在電閃雷鳴中去飛翔,在風雨中去搏擊人生!

????RedisDao.java操縱redis的類

/*** */ package com.zolcorp.mahout.dao;import org.springframework.beans.factory.annotation.Autowired;import redis.clients.jedis.ShardedJedis; import redis.clients.jedis.ShardedJedisPool;/*** @author hadoop**/ public class RedisDao {@Autowiredprivate ShardedJedisPool shardedJedisPool;public void set(String key, String value){ShardedJedis jedis = shardedJedisPool.getResource();jedis.set(key, value);}public String get(String key){ShardedJedis jedis = shardedJedisPool.getResource();return jedis.get(key);} }

????其它一些方法,請讀者自己完成。

<bean id="redisDao" class="com.zolcorp.mahout.dao.RedisDao"></bean>

????注冊bean

????main函數如下:

/*** */ package com.zolcorp.mahout.main;import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext;import com.zolcorp.mahout.dao.RedisDao;/*** @author hadoop**/ public class RedisMain {/*** @param args*/public static void main(String[] args) {ApplicationContext context = new FileSystemXmlApplicationContext(new String[] { "classpath:applicationContext-bean.xml","classpath:applicationContext-datasource.xml", "classpath:applicationContext-redis.xml"});RedisDao redisDao = context.getBean("redisDao", RedisDao.class);redisDao.set("test", "test-----ming...");System.out.println(redisDao.get("test"));}}

????結果很簡單:

test-----ming...

????

????

文章結束給大家分享下程序員的一些笑話語錄: 手機終究會變成PC,所以ip會比wm更加暢銷,但是有一天手機強大到一定程度了就會發現只有wm的支持才能完美享受。就好比樹和草,草長得再高也是草,時間到了條件成熟了樹就會竄天高了。www.ishuo.cn

總結

以上是生活随笔為你收集整理的函数集成redis与Spring集成的全部內容,希望文章能夠幫你解決所遇到的問題。

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