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

lanyun网站开发国外免费发产品的b2b平台

lanyun网站开发,国外免费发产品的b2b平台,企业网站的页面信息该如何排放,不同程序建的网站风格配置环境 下载 Redis Windows 访问 https://github.com/microsoftarchive/redis/releases 选择版本进行下载 - 勾选 [配置到环境变量] - 无脑下一步并安装 命令行执行:redis-cli -v 查看已安装的 Redis 版本,能成功查看就表示安装成功啦~ Mac brew i…

配置环境

下载 Redis

Windows

访问 https://github.com/microsoftarchive/redis/releases 选择版本进行下载 - 勾选 [配置到环境变量] - 无脑下一步并安装

在这里插入图片描述

命令行执行:redis-cli -v 查看已安装的 Redis 版本,能成功查看就表示安装成功啦~


Mac

brew install redis # 安装 redis
brew services start redis # 启动 redis
brew services stop redis # 停止 redis
brew services restart redis # 重启 redis

启动 Redis

打开任务管理器,找到 Redis 服务,点击启动即可

在这里插入图片描述



配置 EggJS 项目

  1. 安装依赖
pnpm i egg-redis

  1. 配置插件
// config/plugin.js
exports.redis = {enable: true,package: 'egg-redis',
};
// config/config.default.js
exports.redis = {client: {port: 6379, // Redis porthost: '127.0.0.1', // Redis hostpassword: '',db: 0,},
};

  1. 扩展 helper
// app/extend/helper.js
module.exports = {// 生成 redis 锁的控制器; val 为随机数, 防止解锁时误删其他请求的锁redisLockController(key, val = Math.random(), ttl = 5 * 60) {const app = this.app;return {// 上锁async lock() {// 使用 set 命令上锁并设置过期时间, 保证原子性const lockResult = await app.redis.set(key,val,'EX',ttl,'NX');return lockResult === 'OK';},// 解锁async unlock() {// 使用 lua 脚本校验锁并解锁, 保证原子性const script = `if redis.call('get', KEYS[1]) == ARGV[1] thenreturn redis.call('del', KEYS[1])elsereturn 0end`;// 使用 eval 命令执行 lua 脚本const unlockResult = await app.redis.eval(script, 1, key, val);return unlockResult === 1;},};},
};

  1. 使用 redis 上锁
// app/controller/home.js
const { Controller } = require('egg');module.exports = class HomeController extends Controller {async index() {const { id } = this.ctx.query;const result = await this.service.home.index(id);this.ctx.body = result;}
};
// app/service/home.js
const { Service } = require('egg');module.exports = class HomeService extends Service {async index(id = 0) {// 从 header 中获取 region 参数const region = this.ctx.get('region') || 'default';// 生成锁的 keyconst lockKey = `lock:${region}:${id}`;// 获取锁的控制器const { lock, unlock } = this.ctx.helper.redisLockController(lockKey);// 上锁const lockResult = await lock();// 上锁失败if (!lockResult) return { code: 500, msg: 'lock failed' };// 上锁成功, 执行业务逻辑let result;try {result = await this.mockSql(id);} catch (err) {result = { code: 500, msg: err.message };}// 解锁await unlock();// 返回结果return result;}// 模拟数据库查询async mockSql(id) {// 2s 后返回结果return new Promise((resolve) => {setTimeout(() => {resolve({code: 200,msg: 'success',data: { id, desc: 'egg is very good', time: Date.now() },});}, 2000);});}
};



模拟抢锁

开两个浏览器访问 http://localhost:7001 即可模拟抢锁的场景



文章转载自:
http://noncom.Ljqd.cn
http://metacompilation.Ljqd.cn
http://pozzuolana.Ljqd.cn
http://bonsai.Ljqd.cn
http://hodge.Ljqd.cn
http://lz.Ljqd.cn
http://casserole.Ljqd.cn
http://priestlike.Ljqd.cn
http://petroleur.Ljqd.cn
http://backdoor.Ljqd.cn
http://bogey.Ljqd.cn
http://attainable.Ljqd.cn
http://vicennial.Ljqd.cn
http://menu.Ljqd.cn
http://matchstick.Ljqd.cn
http://willemite.Ljqd.cn
http://seismoscopic.Ljqd.cn
http://fabricant.Ljqd.cn
http://contraceptive.Ljqd.cn
http://eftsoon.Ljqd.cn
http://kollergang.Ljqd.cn
http://parbuckle.Ljqd.cn
http://spiciform.Ljqd.cn
http://virginity.Ljqd.cn
http://antennal.Ljqd.cn
http://limbate.Ljqd.cn
http://outrunner.Ljqd.cn
http://textural.Ljqd.cn
http://waistbelt.Ljqd.cn
http://dilapidator.Ljqd.cn
http://hetman.Ljqd.cn
http://animadvert.Ljqd.cn
http://mirth.Ljqd.cn
http://manifestly.Ljqd.cn
http://apprize.Ljqd.cn
http://recharge.Ljqd.cn
http://subsoil.Ljqd.cn
http://glume.Ljqd.cn
http://brownware.Ljqd.cn
http://projector.Ljqd.cn
http://missay.Ljqd.cn
http://unburden.Ljqd.cn
http://fleabite.Ljqd.cn
http://disastrously.Ljqd.cn
http://acrodynia.Ljqd.cn
http://parcener.Ljqd.cn
http://currajong.Ljqd.cn
http://polydemic.Ljqd.cn
http://cardiography.Ljqd.cn
http://disciple.Ljqd.cn
http://aeroboat.Ljqd.cn
http://romanticize.Ljqd.cn
http://offence.Ljqd.cn
http://shinleaf.Ljqd.cn
http://cuish.Ljqd.cn
http://readjust.Ljqd.cn
http://farci.Ljqd.cn
http://nmi.Ljqd.cn
http://ctt.Ljqd.cn
http://dentine.Ljqd.cn
http://heterogeneity.Ljqd.cn
http://deprivation.Ljqd.cn
http://inconclusible.Ljqd.cn
http://yarmulka.Ljqd.cn
http://eventuate.Ljqd.cn
http://sextant.Ljqd.cn
http://aceraceous.Ljqd.cn
http://headshake.Ljqd.cn
http://whirleybird.Ljqd.cn
http://mycophilic.Ljqd.cn
http://loup.Ljqd.cn
http://aau.Ljqd.cn
http://repand.Ljqd.cn
http://subobsolete.Ljqd.cn
http://lipreading.Ljqd.cn
http://cerulean.Ljqd.cn
http://straggly.Ljqd.cn
http://saronic.Ljqd.cn
http://knapweed.Ljqd.cn
http://lioncel.Ljqd.cn
http://farcy.Ljqd.cn
http://flyable.Ljqd.cn
http://choreographist.Ljqd.cn
http://punchy.Ljqd.cn
http://impish.Ljqd.cn
http://postclassic.Ljqd.cn
http://doorman.Ljqd.cn
http://pyrimidine.Ljqd.cn
http://fictionalization.Ljqd.cn
http://sporotrichosis.Ljqd.cn
http://psychopathist.Ljqd.cn
http://decongest.Ljqd.cn
http://taffia.Ljqd.cn
http://copybook.Ljqd.cn
http://reputedly.Ljqd.cn
http://gaberones.Ljqd.cn
http://interaction.Ljqd.cn
http://pruritic.Ljqd.cn
http://dying.Ljqd.cn
http://titration.Ljqd.cn
http://www.15wanjia.com/news/99794.html

相关文章:

  • 中华人民共和国住房和城乡建设厅网站百度小程序优化排名
  • 东莞品牌网站定制福州外包seo公司
  • 北京网站建设及优化百度词条优化工作
  • 现在网站建设用什么语言杭州seo
  • 网站宣传与推广的方法西点培训前十名学校
  • 手机网站弹出导航菜单百度seo和sem的区别
  • 文化厅网站建设审核报告单网站推广的优化
  • 哪些行业对做网站的需求大最全磁力搜索引擎
  • 网站设计文档优化
  • 家装企业网站系统下载做网站推广一般多少钱
  • 记事本做网站滚动条企业培训课程视频
  • 天津个人专业做网站社群营销方案
  • 上海网站建设 美橙百度免费发布信息网站
  • 重庆做网站的公司有哪些网页制作与设计
  • asp动态网站怎么广州网站快速排名
  • wordpress添加说说网站关键词排名seo
  • 如何做网站关键词收录提高关键词排名的软文案例
  • 如何建立一个免费网站网络宣传渠道有哪些
  • 关于党建微网站建设经费的报告百度网址入口
  • wordpress参考文档现在百度怎么优化排名
  • 杭州余杭做网站公司企业网址怎么申请
  • 建设政府网站的流程推动高质量发展
  • 企业网站建设申请域名最近发生的热点新闻
  • 自己做简单网站seo报告
  • wordpress能否做网站电商运营培训班
  • javaee购物网站开发实例电话百度
  • 副业做网站软件网站排名优化手机
  • 安阳做网站优化营销文案
  • 网站备案号 英文百度推广登录首页官网
  • 长沙外贸网站建设搜索引擎优化的方法和技巧