当前位置: 首页 > news >正文

站长工具永久国家中小企业公共服务平台

站长工具永久,国家中小企业公共服务平台,公众号运营外包价格,百度推广多少钱一天文章目录 第1关#xff1a;Redis 事务与锁机制第2关#xff1a;流水线第3关#xff1a;发布订阅第4关#xff1a;超时命令第5关#xff1a;使用Lua语言 第1关#xff1a;Redis 事务与锁机制 编程要求 根据提示#xff0c;在右侧编辑器Begin-End补充代码#xff0c;根据… 文章目录 第1关Redis 事务与锁机制第2关流水线第3关发布订阅第4关超时命令第5关使用Lua语言 第1关Redis 事务与锁机制 编程要求 根据提示在右侧编辑器Begin-End补充代码根据以下要求完成一个模拟一次银行卡支付扣款的流程 1、当余额不足时放弃所有被监控的键返回false。 2、在余额扣除消费的金额在支付金额里加上消费的金额。 测试说明 我会对你编写的代码进行测试 测试输入无 预期输出 支付成功 本次扣款10元余额为90元 开始你的任务吧祝你成功 示例代码如下 package com.test; import redis.clients.jedis.Jedis; import redis.clients.jedis.Transaction; import java.util.List; public class TestRedis {private static String host 127.0.0.1;private static int port 6379;private static Jedis jedis new Jedis(host, port);public static boolean payMent(int deduction) throws InterruptedException {int balance; // 余额//设置余额金额jedis.set(balance, 100);jedis.set(deduction, 0);//监控扣款和余额jedis.watch(balance, deduction);/***********Begin***********/balance Integer.parseInt(jedis.get(balance));// 余额不足if (balance deduction) {jedis.unwatch(); // 放弃所有被监控的键System.out.println(对不起你的余额不足);return false;}Transaction transaction jedis.multi();// 扣钱transaction.decrBy(balance, deduction);Thread.sleep(5000); // 在外部修改 balance 或者 debttransaction.incrBy(deduction, deduction);// list为空说明事务执行失败ListObject list transaction.exec();return !list.isEmpty();/***********End***********/}public static void main(String[] args) throws InterruptedException {boolean resultValue payMent(10);if (resultValuetrue){System.out.println(支付成功);int balance Integer.parseInt(jedis.get(balance));int deduction Integer.parseInt(jedis.get(deduction));System.out.printf(本次扣款deduction元余额为balance元);}else{System.out.println(支付失败);}jedis.close();} }第2关流水线 编程要求 根据提示在右侧编辑器Begin-End补充代码按照以下要求开启一次流水线技术 开启流水线。 测试十万条读写操作,设置 key 值为 key0 、 key1 、 key2 …key99998、key99999对应 value 值为 value0 、value1、value2…value99998、value99999。 结束流水线。 测试说明 我会对你编写的代码进行测试 测试输入无 预期输出 开启流水线 消耗时间XXX毫秒 关闭流水线 流水线成功完成 开始你的任务吧祝你成功 示例代码如下 package com.test; import redis.clients.jedis.*; import java.util.List; public class RedisPipeline {public boolean pipeline() {String redisHost 127.0.0.1;int redisPort 6379;Jedis jedis new Jedis(redisHost, redisPort);jedis.flushDB();/**********Begin**********/long start System.currentTimeMillis();// 开启流水线Pipeline pipeline jedis.pipelined();System.out.println(开启流水线);// 测试十万条读写操作for (int i 0; i 100000; i) {pipeline.set(keyi,valuei);pipeline.get(keyi);}long end System.currentTimeMillis();//关闭流水线pipeline.close();System.out.println(消耗时间(end-start)毫秒);System.out.println(关闭流水线);/**********End**********/return true;} }第3关发布订阅 编程要求 根据提示在右侧编辑器Begin-End补充代码按照以下要求 在SubThread类中订阅指定频道redis。 测试说明 我会对你编写的代码进行测试 测试输入quit 预期输出 订阅redis, 订阅频道为 redis, 线程将被阻塞 订阅redis频道成功, 频道为 redis, 订阅频道为 1 请输入传输的信息 关闭程序 开始你的任务吧祝你成功 示例代码如下 package com.test; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; public class SubThread extends Thread {private final JedisPool jedisPool;private final Subscriber subscriber new Subscriber();private final String channel redis;public SubThread(JedisPool jedisPool) {super(SubThread);this.jedisPool jedisPool;}Overridepublic void run() {System.out.println(String.format(订阅redis, 订阅频道为 %s, 线程将被阻塞, channel));Jedis jedis null;try {/************* Begin ***************/jedis jedisPool.getResource();jedis.subscribe(subscriber, channel);/************* End ***************/} catch (Exception e) {System.out.println(String.format(订阅频道错误, %s, e));} finally {if (jedis ! null) {jedis.close();}}} }第4关超时命令 编程要求 根据提示在右侧编辑器Begin-End补充代码按照以下要求使用 Spring 操作 Redis 超时命令过程 创建键值对key 值为“今天你吃了吗” 获取 key 值 设置 key 的过期时间为 5 秒 测试说明 我会对你编写的代码进行测试 测试输入无 预期输出 今天你吃了吗 null 开始你的任务吧祝你成功 示例代码如下 package com.redis; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.RedisTemplate; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; import java.util.concurrent.TimeUnit; public class OverTimeRedisTest {SuppressWarnings({ unchecked, rawtypes, resource })public static void main(String[] args) {ApplicationContext applicationContextnew ClassPathXmlApplicationContext(applicationContext.xml);RedisTemplate redisTemplateapplicationContext.getBean(RedisTemplate.class);redisTemplate.execute((RedisOperations ops) - {/************Begin************/ops.boundValueOps(key).set(今天你吃了吗);System.out.println(ops.boundValueOps(key).get());ops.expire(key,5L, TimeUnit.SECONDS);/************End************///睡眠6秒使得key值过期try {Thread.sleep(6000);}catch (InterruptedException e){e.printStackTrace();}//获取key值System.out.println(ops.boundValueOps(key).get());//结束所有线程退出系统System.exit(0);return null;});} }第5关使用Lua语言 编程要求 根据提示在右侧编辑器 Begin - End 处补充代码根据以下要求完成一次手机销售库存的操作 编写 ItemRedisTest.lua 文件判断销售量是否比库存数量多如果库存数量大于这次销售量将新的库存数量更新到原来的 key 值上。 编写 ItemRedisTest.java 文件使用 BufferedReader 读取ItemRedisTest.lua 文件使用 eval 命令执行文件里的字符串设置手机销售量为10。 ItemRedisTest.lua 地址为/data/workspace/myshixun/step5/ItemRedisTest.lua 测试说明 我会对你编写的代码进行测试 测试输入无 预期输出 手机库存剩余90 开始你的任务吧祝你成功 代码示例如下 package com.redis; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.data.redis.core.RedisTemplate; import redis.clients.jedis.Jedis; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class ItemRedisTest {public static void main(String[] args) throws IOException {ApplicationContext applicationContextnew ClassPathXmlApplicationContext(applicationContext.xml);RedisTemplate redisTemplateapplicationContext.getBean(RedisTemplate.class);Jedis jedis(Jedis)redisTemplate.getConnectionFactory().getConnection().getNativeConnection();jedis.set(phone_item_stock, 100);/************Begin************/BufferedReader in new BufferedReader(new FileReader(/data/workspace/myshixun/step5/ItemRedisTest.lua));String context null;String script;while (null ! (context in.readLine())){scriptcontext\n;}Object obj jedis.eval(script, 1,phone_item_stock,10);/************End************/System.out.println(手机库存剩余obj);//关闭连接jedis.close();System.exit(0);} }之后在命令行中输入下列代码 vim /data/workspace/myshixun/step5/ItemRedisTest.lua编辑该文件内容 local count redis.call(get, KEYS[1]) local atonumber(count) local btonumber(ARGV[1]) ---Begin if ab thenredis.call(set,KEYS[1],count-b)return redis.call(get, KEYS[1]) end ---End
http://www.sadfv.cn/news/93932/

相关文章:

  • 搭建网站 在线浏览功能网站改版什么意思
  • 推荐成都网站建设中国建设银行官方网站纪念钞预约
  • 肥东建设网站兰州网络公司有哪些
  • google网站搜索深圳十大设计事务所
  • 网站seo外链建设营销案例网站
  • 专业制作网站 地摊做钢材的做什么网站效果好
  • 河源市网站建设公司安康创宇网站建设
  • 什么是网站建设从哪些方面建设网站大连网站网站建设
  • 凡科网做网站视频wordpress 微博时间
  • 在线音乐网站开发教程西安网站建设制作 熊掌号
  • 最新的高端网站建设上海小程序定制开发公司
  • 小公司要不要建设网站怀仁建设局网站
  • 东莞网站排名自己做网站并让别人访问
  • 学生网站建设实训总结九州建网站
  • 北京制作网站多少钱鸽WordPress主题
  • 湛江建站费用电商设计和ui设计哪个前景比较好
  • 如何通过html做网站建筑网页
  • 伦教网站开发竞价推广代运营服务
  • 郑州优化网站关键词wordpress输入html代码
  • 汽车网站有哪些上海网站建设官方网站
  • 网站后台管理系统php滴滴出行的网站是哪家公司做的
  • 在线支付 网站模板大连flash网站
  • 怎么样做好网站运营肥城网站建设哪家好
  • 在线制作网站的平台嘉兴网站建设公司就找嘉乐网络
  • 微擎做网站费用首页关键词排名
  • 网站开发好要租服务器吗优秀产品vi设计手册
  • 上海建设网站服务微信小程序是什么意思?有什么用
  • 建设网站需要云服务器吗中国建设银行网站-个人客
  • 大型的网站开发域名解析站长工具
  • 网站上做的vi设计是怎么做的制作网站在哪里