不久前,随着《街头霸王》、《死或生》、《苍翼默示录》等重重街机格斗游戏纷繁登陆家用机、PC,甚至是掌机、手机平台,在笨重的街机平台奄奄一息的格斗游戏就像再一次打开了百花争艳的新时代。但是随着名作续作、独立黑马的总是出现,琳琅满目标格斗游戏在让许多玩家大呼过瘾的还要,也让有些怀古玩家起初回想起这些在时光经过里日益褪色的大笔,首先想到的便是《THE
KING OF FIGHTERS》——《拳皇》。
本文原创,转发请注解:http://www.cnblogs.com/fengzheng/p/5941953.html
小编:HUSH——游民星空热心读者
至于 Redis
集群搭建可以参见我的另一篇小说 Redis集群搭建与简便利用
流浪汉星空热心读者投稿,讲出自己心里的故事。
Redis 是怎么,能做什么样
Redis
是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和信息队列代理。它扶助字符串、哈希表、列表、集合、一如既往聚集,位图,hyperloglogs等数据类型。内置复制、Lua脚本、LRU收回、事务以及不一样级别磁盘持久化效能,同时通过Redis
Sentinel 提供高可用,通过 Redis Cluster
提供自动分区。(摘自 Redis
官网)
(点击图片进入专栏列表)
用作内存数据库,在现世网络 web 系统中,仍旧器重将 Redis
作为缓存使用。大型网络 Web
系统对质量须要很高,而在前端和数据层之间扩展数据缓存已化作不可或缺的手段之一,当前比较流行的三个技巧就是 Redis
和 Memcached,至于两岸有怎么着界别,不是本文要说的内容。本文首要讲 Java
web 怎样操作 Redis 及 Redis 集群。
在经历了《拳皇97》、98的兴旺,99-01的落寞甚至诽谤,再到《拳皇XIII》所拉动的新热潮,拳皇体系实在承载了对打玩家太多的尊崇和期待,而在拳皇连串正统续作近乎销声匿迹的今日,我们到底想要一款怎么样的《拳皇》,成为了比比皆是玩家幻想和YY的话题。
貌似 Java 程序操作Redis
添加的角色和招式
Redis 提供了多样语言的客户端,在 Java 中最流行的是
Jedis 。访问可查阅源码及应用办法。如今Jedis 最新版本是2.9.0。无论是单机依然集群,Jedis
都有很详细的表明和实例代码,那里只做简单表明。如果用 Maven
做包管理,须求引用 jedis 包,本例使用最新的2.9.0本子,如下:
拳皇连串之所以可以在中期就广受好评,最关键的要素就是不可计数的角色和招式,初代拳皇94的登场角色就多达24人,比起CAPCOM同期的《街霸ZERO》(1995年)多出了大体上之上。且不谈游戏系统与素质本身,参战人数上的优势相对是拳皇体系的一大特征。
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
操作 Redis 单机
多达到24名角色的琼楼玉宇阵容(角色大多源自于SNK自己的游艺,理论上《拳皇94》是“SNK大乱斗”)
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* Created by fengdezitai on 2016/10/9.
*/
public class JedisClient {
private static final String host= "192.168.31.121";
private static final JedisClient jedisClient = new JedisClient();
private Jedis jedis = null;
/**
* 私有构造函数
*/
private JedisClient(){}
public static JedisClient getInstance(){
return jedisClient;
}
private JedisPoolConfig getPoolConfig(){
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxIdle(10);
jedisPoolConfig.setMaxTotal(100);
jedisPoolConfig.setMaxWaitMillis(3000);
return jedisPoolConfig;
}
/**
* 添加
* @param key
* @param value
* @return
* @throws Exception
*/
public Boolean add(String key,String value) throws Exception{
JedisPool pool = new JedisPool(getPoolConfig(),host);
Jedis jedis = null;
try {
jedis = pool.getResource();
if(jedis.exists(key)){
throw new Exception(String.format("key (%s) 已存在 ",key));
}
jedis.set(key,value);
}catch (Exception e){
throw e;
}
finally {
if(jedis!=null){
jedis.close();
}
}
pool.destroy();
return true;
}
/**
* 获取值
* @param key
* @return
* @throws Exception
*/
public String get(String key) throws Exception{
JedisPool pool = new JedisPool(getPoolConfig(),host);
Jedis jedis = null;
String result = "";
try {
jedis = pool.getResource();
result = jedis.get(key);
}catch (Exception e){
throw e;
}
finally {
if(jedis!=null){
jedis.close();
}
}
pool.destroy();
return result;
}
public static void main(String[] args) {
JedisClient jedisClient = JedisClient.getInstance();
try {
/*Boolean result = jedisClient.add("hello", "redis1");
if(result){
System.out.println("success");
}*/
System.out.println(jedisClient.get("hello"));
}catch (Exception e){
e.printStackTrace();
}
}
}
除外角色数量上的“大手笔”,开发公司SNK在人物特色上也下足了功夫。首先从人物特色上来讲,与《街霸》比较,《拳皇》的角色设定显得更为天马行空,作为系列主演,拳皇94-98的不可磨灭留级生草薙京,不但人物性格桀骜不驯,自信甚至毒舌,其招式动作也尽显酷炫:从一开端作为简单的波动升龙系角色,到新兴实在的珍重追加输入技(毒咬-罪咏-罚咏)等引发的充实技能为本位的角色,草薙京的属性和实战格局已经暴发了朝不保夕的转移。由此,包罗主演在内,每一作拳皇种类中的角色都可能在形象、战斗作风上冒出大幅度的更改(罗Bert也是个极好的例证,这一个角色在2000中居然变成了一种类少有的全蓄力型角色)。
操作 redis 集群
import redis.clients.jedis.*;
import java.util.HashSet;
import java.util.Set;
/**
* Created by fengdezitai on 2016/10/13.
*/
public class JedisClusterClient {
private static int count = 0;
private static final JedisClusterClient redisClusterClient = new JedisClusterClient();
/**
* 私有构造函数
*/
private JedisClusterClient() {}
public static JedisClusterClient getInstance() {
return redisClusterClient;
}
private JedisPoolConfig getPoolConfig(){
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(1000);
config.setMaxIdle(100);
config.setTestOnBorrow(true);
return config;
}
public void SaveRedisCluster() {
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
jedisClusterNodes.add(new HostAndPort("192.168.31.245", 7000));
jedisClusterNodes.add(new HostAndPort("192.168.31.245", 7001));
jedisClusterNodes.add(new HostAndPort("192.168.31.245", 7002));
jedisClusterNodes.add(new HostAndPort("192.168.31.210", 7003));
jedisClusterNodes.add(new HostAndPort("192.168.31.210", 7004));
jedisClusterNodes.add(new HostAndPort("192.168.31.210", 7005));
JedisCluster jc = new JedisCluster(jedisClusterNodes,getPoolConfig());
jc.set("cluster", "this is a redis cluster");
String result = jc.get("cluster");
System.out.println(result);
}
public static void main(String[] args) {
JedisClusterClient jedisClusterClient = JedisClusterClient.getInstance();
jedisClusterClient.SaveRedisCluster();
}
}
《拳皇》主角形象衍生和变化进程
Spring mvc 操作 Redis
而SNK也绝非停歇新的追究与发现,拳皇99后头引入的新支柱——白发黑衣的墨镜暴力男K’在即时越来越得到了一定的人气,固然99-01的素质普遍不被看好,可是新参预的角色依然为多元赚足了人气;再到03未来的新支柱ASH——白发红衣的白屑风美(niang)男(pao)更是用其离经叛道的角色性格吸引了累累玩家的眼球。
在 Spring mvc 中操作 Redis ,首先当然要搭好 Spring mvc
框架了。以下是在如若 Spring mvc 环境已经架好的情景下。本例中 Spring
版本为 4.3.2 RELEASE。关于 Spring 的 maven 引用如下:
<!-- spring版本号 -->
<spring.version>4.3.2.RELEASE</spring.version>
<!-- spring核心包 -->
<!-- springframe start -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- springframe end -->
《街霸》主演形象的演化进度
操作 Redis 单机
还要,让大家来探望拳皇体系的老对头——《街霸》的栋梁,一贯都是非常苦大仇深、一本正经的功德男“隆”,这几个角色在经验了二十几年的变质之后,必杀技依旧是朝不保夕、升龙、旋风脚等……变化的大致只是特效。当然如此说不用贬低任何角色,事实上街霸体系那种实干的严刻设定正是多如牛毛人物的魅力所在,但是作为一个玩家来说,何人不情愿看看越发丰裕多变的角色吗?拳皇种类涵盖了太多玩法各异甚至颇有试验色彩的征战作风,大家当然也冀望SNK可以将那种作风与特征三番四次下去,在新的《拳皇》小说中,为大家带来越发惊叹的角色和招式,同时,我们也相当盼望能够在新平纽伦堡看看体系人气角色的回归和衍生和变化,比如呼声很高的“大蛇八杰”(至少是“三杰”)。
只用 Jedis 自己已毕注入(不一致于下边的引用spring-data-redis)
把后面的 JedisClient 代码拿过来引用即可,只需兑现一个造访 Redis 的
Service ,就足以合二为一到 Spring mvc 。Service 代码如下:
《拳皇2002》之后就已销声匿迹的“大蛇三杰”(即使不算上XIII中的背景的话)
import org.springframework.stereotype.Service;
import util.JedisClient;
/**
* Created by fengdezitai on 2016/10/9.
*/
@Service
public class RedisService {
public String get(String key) throws Exception{
JedisClient jedisClient = JedisClient.getInstance(); //上面实现的JedisClient
String result = "";
try {
result = jedisClient.get("hello");
}catch (Exception e){
throw e;
}
return result;
}
}
简单上手并值得商讨的连串
Controller 已毕如下:
权衡一款格斗游戏的优劣,游戏系统本来是一项根本的目的。格斗游戏从早期简单的打击、防御、跳跃,发展到如今纷繁复杂的快节奏攻防转换,出色独到的案例太多,值得探究和切磋的话题也不少,在此间,大家只是将目光放在《拳皇》种类本身。
@Controller
@RequestMapping(value = "redisAllInOne")
public class RedisAllInOneController {
@Autowired
private RedisService redisService;
@RequestMapping(value = "get",method = RequestMethod.GET)
@ResponseBody
public Object getByMyService(String key){
try {
String result = redisService.get(key);
return result;
}catch (Exception e){
e.printStackTrace();
}
return null;
}
}
《拳皇》连串在功成名就引入了逃避、解投、三种跳跃形式等等基础要素之余,众所周知的,最令人津津乐道的特性便是令人眼花缭乱的“一连技”,而从“一而再技”这一话题展开开来,拳皇种类一连技的基本便是“废除”。“撤废”本身其实毫不《拳皇》种类的专利,所谓“撤除”是指中断角色当前动作或者收招硬直,通过适时的下令输入强制引入下一动作的体系,在格斗游戏普遍适应了“普通技——特殊技——必杀技”那种使用“裁撤”来促成一而再技的架构之后,拳皇体系其实早已开辟了崭新的“连击技巧”。换而言之,拳皇连串将“打消”那几个体系,至少说曾在一段时间内,发挥到了最为,那便是super
cancel——超级取消。
用 spring-data-redis 包做集成
地方是团结完成的流入,那里用 spring-data-redis
进行集成,只需简单安顿即可,必要引用 maven 包如下,版本为当前风行版
1.7.2.RELEASE:
被不少玩家奉为经典的《拳皇2002》,想当初作者的微机里也存了几十张那种截图
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.7.2.RELEASE</version>
</dependency>
那么些系统最早出现在《拳皇2001》,它可以让超必杀技在特定必杀技动作中撤销使出,延伸了价值观再三再四技格局的尺寸和套路,那的确让一而再技变得尤其豪华而且便于驾驭(相对“目押”来说,“打消”的输入判定要宽松不少),而在此作之后《拳皇2002》中引入的power
max则允许得玩家可以在一段时间内反复使用“一级裁撤”,也正因为这一种类的引入,让《拳皇2002》成为了不以为奇拳皇迷心目中的神作,再到《拳皇XIII》,这一序列持续被发扬光大,成为了“Hyper
Drive
Mode”这些系统让角色能在必杀技中收回其余必杀技或超必杀技,并且扩大了可以撤除超必杀技的NEO
MAX超必杀技。游戏系统仁者见仁智者见智,然而不可不可以认的是,正是因为那种连接技情势的面世,而让《拳皇XIII》成为体系内部最为华丽、观赏度最高的一作。
运用 spring-data-redis
,即省去了温馨完结注入的历程,通过它提供的一对布置,即可兑现连接池配置、RedisTemplate
配置、JedisConnectionFactory 配置;通过 JedisConnectionFactory
可陈设连接池参数、redis
服务器、端口、密码、超时时间、database索引等;RedisTemplate 即注入的bean
,可以利用 RedisTemplate 自动注入的实业举行 redis
的一系列操作,具体看安顿;
redis 服务性质配置文件:
经过“Hyper Drive”和“super cancel”“轻松”落成的高伤连携
redis.maxIdle=300
redis.maxWait=3000
redis.testOnBorrow=true
redis.host=192.168.31.121
redis.port=6379
redis.password=password
redis.timeout=3000
而是小编在此间只好指出的是,《拳皇XIII》中过度施用的“撤消”让玩家之间的胶着,从一招一式的博弈变为了Combo(连击)技巧的对峙,某些角色通过“撤废”可以拔取出一定霸气的Combo,往往一旦摸到对手,就立刻会将对方带入连击地狱,那种对抗纵然很有观赏性,并且不乏高超技术,可是那也使得新玩家出手的技法变得一定之高,如若不可以熟习领会几套“顶尖裁撤”的连击技巧,是很难在高手如林的网络对战中佼佼不群,最终也不得不沦为到世代打电脑的“单机玩家”,比如小编自我……
spring-data-redis xml 配置文件 redis-context.xml:
实则,在此在此以前,《拳皇98》已经做出过一个针锋相对成功的初阶——双系统,同时专职了老玩家和尝鲜者。为了名目繁多发展设想,也为了这几个“不是王牌”的动武玩家也可以取得乐趣,我们如故期待见到一款在保留连串精髓的还要,入手难度又不是“那么高”的《拳皇》作品,让大家能在游玩中逐步成长,或者至少是在菜鸟和一把手之间,创建一个针锋相对宽松的“缓冲区”。
<!-- jedis 连接池 配置 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig" >
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<!-- redis服务器中心 -->
<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" >
<property name="poolConfig" ref="poolConfig" />
<property name="port" value="${redis.port}" />
<property name="hostName" value="${redis.host}" />
<!--<property name="password" value="${redis.password}" />-->
<property name="timeout" value="${redis.timeout}" ></property>
<property name="database" value="1"></property>
</bean>
<bean id="commonRedisTemplate" class="org.springframework.data.redis.core.RedisTemplate" >
<property name="connectionFactory" ref="connectionFactory" />
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="connectionFactory1" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" >
<property name="poolConfig" ref="poolConfig" />
<property name="port" value="${redis.port}" />
<property name="hostName" value="${redis.host}" />
<!--<property name="password" value="${redis.password}" />-->
<property name="timeout" value="${redis.timeout}" ></property>
<property name="database" value="2"></property>
</bean>
<bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="cacheRedisTemplate" class="org.springframework.data.redis.core.RedisTemplate" >
<property name="connectionFactory" ref="connectionFactory1" />
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
历史观而精致的2D绘制
而后在 spring 配置文件中援引以上文件:
由来,各样娱乐的画面显示比起街机盛行的时期已经不知上涨了略微个档次,不过事实上,就算所有《撕裂重罪》、《街霸EX》等,在当下来讲素质不俗的3D建模格斗游戏,直到《街霸4》出现从前,2D制图的格斗游戏依然平昔维系着一定高涨的人气,而《拳皇XIII》、《苍翼默示录》、《夜下跌地》等游艺的产出也照例让我们对精密的2D作图欲罢不可能。
<import resource="redis-context.xml" />
解释一下上面的安顿:
不管是以当时要么后天的见地来看《KOF: MaXIIImum
Impact》的变现效果都遗憾
poolConfig 即配置 redis 连接池,之后安顿了八个 JedisConnectionFactory 和
RedisTemplate ,一个 RedisTemplate 对应一个 JedisConnectionFactory
,那样可以安顿按照气象布局分歧的 Redis
连接,比如超时时间必要不均等、database 0-15
可以储存区其他数量等。那里就布局了database 1 和 2
,调用 commonRedisTemplate 会存到 database1 ,调用 cacheRedisTemplate
会存到 database2。
作为《拳皇》连串来讲,作者觉得最契合该序列的绘图格局,依旧是观念的2D镜头,大家曾经见过了SNK在3D建模方面的实力,不管是《KOF:
MaXIIImum
Impact》依旧《侍魂闪》都令人不敢恭维,反倒是《拳皇XIII》所突显出的通畅、动感十足的手绘2D人选及形貌在霎时可以再次掀起一股拳皇热潮,召回一批忠实粉丝的同时并能从当时画面展现优良老练的《街霸4》手下抢得一矢之地,甚至颇有当年CAPCOM和SNK三个老对手在街机厅里分庭抗礼的气氛。
之后在 Service 层即可注入并援引那四个 RedisTemplate ,如下代码:
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.io.*;
@Repository
public class RedisCache {
@Resource(name = "cacheRedisTemplate")
private RedisTemplate<String, String> cacheRedisTemplate;
public void put(Object key, Object value) {
if(null == value) {
return;
}
if(value instanceof String) {
if(StringUtils.isEmpty(value.toString())) {
return;
}
}
// TODO Auto-generated method stub
final String keyf = key + "";
final Object valuef = value;
final long liveTime = 86400;
cacheRedisTemplate.execute(new RedisCallback<Long>() {
public Long doInRedis(RedisConnection connection)
throws DataAccessException {
byte[] keyb = keyf.getBytes();
byte[] valueb = toByteArray(valuef);
connection.set(keyb, valueb);
if (liveTime > 0) {
connection.expire(keyb, liveTime);
}
return 1L;
}
});
}
public Object get(Object key) {
final String keyf = (String) key;
Object object;
object = cacheRedisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection)
throws DataAccessException {
byte[] key = keyf.getBytes();
byte[] value = connection.get(key);
if (value == null) {
return null;
}
return toObject(value);
}
});
return object;
}
/**
* 描述 : <byte[]转Object>. <br>
* <p>
* <使用方法说明>
* </p>
*
* @param bytes
* @return
*/
private Object toObject(byte[] bytes) {
Object obj = null;
try {
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bis);
obj = ois.readObject();
ois.close();
bis.close();
} catch (IOException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return obj;
}
private byte[] toByteArray(Object obj) {
byte[] bytes = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
oos.flush();
bytes = bos.toByteArray();
oos.close();
bos.close();
} catch (IOException ex) {
ex.printStackTrace();
}
return bytes;
}
}
《拳皇XII》的绘图其实早已令人十分满意
末段在 Controller 中调用即可
2D作图本身工程浩大,尽管是《苍翼默示录》那种新晋游戏也难免会存在锯齿和混淆的景色,但是不得不说,就到底像《月姬格斗》那种角色点阵显明的格斗游戏也能依靠流畅的动作和值得商讨的种类获得玩家的拥护,小编仍旧认为,对于格斗游戏来说,2D制图是完全可以让玩家接受,并且对于《拳皇》连串来讲,也完全是制作商所擅长的花色。
@Autowired
private RedisCache redisCache;
@RequestMapping(value = "get", method = RequestMethod.GET)
@ResponseBody
public Object getByMyService(String key) {
try {
String result = redisService.get(key);
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@RequestMapping(value = "save", method = RequestMethod.GET)
@ResponseBody
public Object save() {
Token token = new Token();
token.setAccess_token("token");
token.setExpires_in(1000);
try {
redisCache.put("token", token);
} catch (Exception e) {
e.printStackTrace();
}
return "ok";
}
操作 Redis 集群
有着非凡2D作画水平的《苍翼默示录》
只用 Jedis 自己已毕注入(分裂于下边的引用spring-data-redis)
把前边的 JedisClusterClient 代码拿过来引用即可,只需兑现一个访问 Redis
的 Service ,就能够合二为一到 Spring mvc 。Service 代码如下:
画面上决不万分超人的《月姬格斗》
import org.springframework.stereotype.Service;
import util.JedisClusterClient;
/**
* Created by fengdezitai on 2016/10/13.
*/
@Service
public class RedisClusterService {
public void save() throws Exception{
//调用 JedisClusterClient 中的方法
JedisClusterClient jedisClusterClient = JedisClusterClient.getInstance();
try {
jedisClusterClient.SaveRedisCluster();
}catch (Exception e){
throw e;
}
}
}
引人入胜的故事剧情
末段在 Controller 中调用完结的 Service 即可
或者对于一款格斗游戏来说,故事剧情在里面的份额并不要求很大,但是当格斗游戏从喧闹的街机平台来到了PC或者家用机领域,玩家在纯粹的迎阵之余也出色愿意静下心来去驾驭一款游戏的文化背景,丰盛的世界观设定和故事编撰也更为成为了玩家商量的话题。
@Controller
@RequestMapping(value = "redisCluster")
public class RedisClusterController {
@Autowired
private RedisClusterService redisClusterService;
@RequestMapping(value = "save",method = RequestMethod.GET)
@ResponseBody
public Object save(){
try{
redisClusterService.save();
}catch (Exception e){
e.printStackTrace();
return String.format("error: %s",e.getMessage());
}
return "ok";
}
}
澳门美高梅手机网站,作为此方面的中标案例,小编初始想到的便是《苍翼默示录》连串,那款由Arc
System
Works开发的格斗游戏从一初始就将支付首要放在了多平台,在街机平台推出后赶忙,家用机,掌机,PC平台的续作和抓实版便连绵不断,最让玩家津津乐道的地点,就是该种类特大、完备的世界观和颇有深度的剧情安顿。
用 spring-data-redis 包做集成
而盛名的《苍翼》连串,恰恰继承了该商家《罪恶装备》系列的卓绝传统。除了将格斗游戏的根底体系完善以外,还出席了大气的剧情内容,也就是故事格局。故事方式中,通过大批量的对话,专业的CV演出,不时穿插的剧情动画,使得人物背景、剧情走向在每一部作品中得以持续和加剧,让玩家对一切《苍翼》世界有了一个周密的的摸底和认得。“让玩家带着心理去选择角色”“让玩家真正感受和饰演他所使用的角色”,那种规划意见让有些非格斗玩家甚至是手残伤者也两肋插刀地改为了粉丝,不得不说,那种设计方式是成功还要值得推广的。
Spring 和 spring-data-redis maven
包引述和前边一致,之所以引用 spring-data-redis 1.7.2.RELEASE,是因为眼下唯有那一个最新版本才支撑集群操作。
redis 集群服务特性配置
被戏称为“格斗AVG”的《苍翼默示录》,对话选用、图鉴收藏等AVG要素一应俱全
redis.maxIdle=300
redis.maxWait=3000
redis.testOnBorrow=false
redis.timeout=3000
足足乐观的是,《拳皇》种类其实完全不乏故事演绎的情节和挖掘潜力。在那里,小编不得不捎带上一些私有心情色彩,我所接触的首先部卡通不是《龙珠》,不是《灌篮高手》,而是由香岛漫歌唱家许景探绘制的《拳皇99》,正是因为接触了那部启蒙之作,在原则有限的情景下,我依然在网上大概了然了拳皇的故事背景,也在一定长的一段时间内沉迷其中。
spring-data-redis xml 集群配置文件 redis-cluster-context.xml
<!-- 连接池 配置 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig" >
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<bean id="redisClusterConfig" class="org.springframework.data.redis.connection.RedisClusterConfiguration">
<property name="maxRedirects" value="3"></property>
<property name="clusterNodes">
<set>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="192.168.31.245"></constructor-arg>
<constructor-arg name="port" value="7000"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="192.168.31.245"></constructor-arg>
<constructor-arg name="port" value="7001"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="192.168.31.245"></constructor-arg>
<constructor-arg name="port" value="7002"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="192.168.31.210"></constructor-arg>
<constructor-arg name="port" value="7003"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="192.168.31.210"></constructor-arg>
<constructor-arg name="port" value="7004"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="192.168.31.210"></constructor-arg>
<constructor-arg name="port" value="7005"></constructor-arg>
</bean>
</set>
</property>
</bean>
<bean id="redis4CacheConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<constructor-arg name="clusterConfig" ref="redisClusterConfig" />
<property name="timeout" value="${redis.timeout}" />
<property name="poolConfig" ref="poolConfig"/>
</bean>
<bean name="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="clusterRedisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redis4CacheConnectionFactory" />
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
港漫味儿十足的《拳皇》漫画,其实画风依然万分可观的
然后在 Spring 配置文件中引用
拳皇的宇宙观很有风味,在《拳皇99》此前,因为系列的主要反面人物如故“大蛇一族”,围绕着草薙、神乐和八神家族的恩恩怨怨情仇为所有游戏打造了一种“现代城池神话”的气氛,而99到01所提供的世界观又是关于高科学技术社团NETS的丑恶阴谋,相关剧情更是关乎了“克隆人”、“改造人”等颇具时代感的概念,这种幽默的距离和融合也让拳皇世界变得越来越多元化。事实上,若是SNK可以认认真真地开掘剧情设定里的细节,拳皇种类完全可以向玩家显示一个特大而且别有天地的好故事。
<import resource="redis-cluster-context.xml" />
俺们可以见到SNK的不竭尝试,从《拳皇03》开始,到《拳皇XIII》甘休的“遥远彼之地”讲述了一个完整而有趣的故事,XIII的后果即使稍有烂尾的疑惑,不过到底是以“就义主演的生命”为代价大玩“祖父悖论”,作为历史上首先个在剧情里死掉的格斗游戏主演,ASH为了振兴拳皇体系也是蛮拼的。于是,在收看《拳皇XIII》“惊人的后果”之后,玩家自然更为希望SNK能在崭新的宗旨篇章里为玩家带来如何的主线剧情,而在新序列里,由于ASH已死,有事烧……啊不是,在ASH篇为止之后,究竟是由草薙重新引起主角宛城如故引入越发离经叛道的新角色,都将是SNK为普遍玩家所能带来的最大惊喜。
解释以上配置:
poolConfig是连接池配置,redisClusterConfig 配置了 Redis
集群的各类节点(节点 host 和 port 最好写在品质配置文件中),集群搭建可见我的 另一篇博客 。然后上边和单机配置一样了,一对
JedisConnectionFactory 和 RedisTemplate 。
而后在 Service 层即可注入并引述那么些 RedisTemplate,代码如下:
拳皇体系开发的新作,已经判定是3D化,为何我望着那张脸就没了玩儿它的私欲呢……(事实上那款新作的制作人员还在招生中,成品与图片毫不相关)
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;
import java.io.*;
/**
* Created by fengdezitai on 2016/9/29.
*/
@Repository
public class RedisClusterCache {
@Autowired
private RedisTemplate clusterRedisTemplate;
public void put(Object key, Object value) {
if(null == value) {
return;
}
if(value instanceof String) {
if(StringUtils.isEmpty(value.toString())) {
return;
}
}
// TODO Auto-generated method stub
final String keyf = key + "";
final Object valuef = value;
final long liveTime = 86400;
clusterRedisTemplate.execute(new RedisCallback<Long>() {
public Long doInRedis(RedisConnection connection)
throws DataAccessException {
byte[] keyb = keyf.getBytes();
byte[] valueb = toByteArray(valuef);
connection.set(keyb, valueb);
if (liveTime > 0) {
connection.expire(keyb, liveTime);
}
return 1L;
}
});
}
public Object get(Object key) {
final String keyf = (String) key;
Object object;
object = clusterRedisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection)
throws DataAccessException {
byte[] key = keyf.getBytes();
byte[] value = connection.get(key);
if (value == null) {
return null;
}
return toObject(value);
}
});
return object;
}
/**
* 描述 : <byte[]转Object>. <br>
* <p>
* <使用方法说明>
* </p>
*
* @param bytes
* @return
*/
private Object toObject(byte[] bytes) {
Object obj = null;
try {
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bis);
obj = ois.readObject();
ois.close();
bis.close();
} catch (IOException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return obj;
}
private byte[] toByteArray(Object obj) {
byte[] bytes = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
oos.flush();
bytes = bos.toByteArray();
oos.close();
bos.close();
} catch (IOException ex) {
ex.printStackTrace();
}
return bytes;
}
}
末段的期许
最后在 Controller 中调用即可
日前一年来,关于拳皇的任何信息都能挑逗起一大批格斗玩家的关心,但是那款老牌名作的现状却令人尤为失望,续作的开发遥遥无期,手游、网游平台种种圈钱和冷饭行为也让为数众多玩家流失严重,瞅着早已的老对手《街霸》体系一个接一个地生产新本子,新本子做完之后很快放出正统续作,SNK就好像早就陷入了“破罐子破摔”的颓败境地,作为一名对拳皇种类深有心绪的老玩家,只能相信SNK圈够了钱,最后还是能给玩家显示出一部不枉期待的正规续作。大家并不期待SNK可以过来从前的昌盛光景,不愿意《拳皇》可以重新重回历史舞台继续和《街霸》一较高下,大家只是梦想那样一部从小陪伴着大家,承载着太多青葱回忆的玩乐可以迈着大家耳熟能详的步子给持有玩家一份似曾相识的触动。
@Controller
@RequestMapping(value = "redisCluster")
public class RedisClusterController {
@Autowired
private RedisClusterCache redisClusterCache;
@RequestMapping(value = "clusterSave",method = {RequestMethod.GET,RequestMethod.POST})
@ResponseBody
public Object clusterSave(){
//redisClusterCache.put("cluster","save cluster");
Token token = new Token();
token.setExpires_in(1000);
token.setAccess_token("hello world");
redisClusterCache.put("token",token);
return "ok";
}
@RequestMapping(value = "getKey",method = RequestMethod.GET)
@ResponseBody
public Object getCluster(String key){
Object val = redisClusterCache.get(key);
return val;
}
}
注意事项:
- 本子难题,假若用 spring-data-redis 做集成操作 Reids
集群,唯有 spring-data-redis
方今风靡版本1.7才含有对集群的操作,而风靡的 spring-data-redis
中的某些职能对 Spring mvc
的本子也有些限制,所以尽可能拔取高版本的 Spring mvc 对应。 - 假诺存储的value值是一个实体对象,那么早晚要兑现 Serializable 接口