当前位置: 首页 > 编程日记 > 正文

kotlin + springboot 整合redis,Redis工具类编写及单元测试

参考自:  https://www.cnblogs.com/zeng1994/p/03303c805731afc9aa9c60dbbd32a323.html

1、maven依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.7.RELEASE</version><relativePath/></parent><groupId>com.example</groupId><artifactId>test-redis</artifactId><version>0.0.1-SNAPSHOT</version><name>test-redis</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><kotlin.version>1.2.71</kotlin.version></properties><dependencies><!--<dependency>--><!--<groupId>org.springframework.boot</groupId>--><!--<artifactId>spring-boot-starter</artifactId>--><!--</dependency>--><dependency><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-reflect</artifactId></dependency><dependency><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-stdlib-jdk8</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-test-junit5 --><dependency><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-test-junit5</artifactId><version>1.2.70</version><scope>test</scope></dependency></dependencies><build><sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory><testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-maven-plugin</artifactId><configuration><args><arg>-Xjsr305=strict</arg></args><compilerPlugins><plugin>spring</plugin></compilerPlugins></configuration><dependencies><dependency><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-maven-allopen</artifactId><version>${kotlin.version}</version></dependency></dependencies></plugin></plugins></build></project>

2、RedisTemplate配置,新建RedisContig.kt

package com.example.demo.configimport com.fasterxml.jackson.annotation.JsonAutoDetect
import com.fasterxml.jackson.annotation.PropertyAccessor
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.redis.connection.RedisConnectionFactory
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
import org.springframework.data.redis.serializer.StringRedisSerializer@Configuration
class RedisConfig {@Beanfun redisTemplate(factory : RedisConnectionFactory) : RedisTemplate<String, Any> {val om = ObjectMapper()//om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY)om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL)
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.PUBLIC_ONLY);//om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
val jackson2JsonRedisSerializer = Jackson2JsonRedisSerializer(Any::class.java)jackson2JsonRedisSerializer.setObjectMapper(om)val stringRedisSerializer = StringRedisSerializer()val template = RedisTemplate<String, Any>()template.setConnectionFactory(factory)template.keySerializer = stringRedisSerializertemplate.hashKeySerializer = stringRedisSerializertemplate.valueSerializer = jackson2JsonRedisSerializertemplate.hashValueSerializer = jackson2JsonRedisSerializertemplate.afterPropertiesSet()return template}
}

创建类RedisUtil.kt,作为redis操作类

package com.example.demo.utilimport org.springframework.data.redis.core.RedisTemplate
import org.springframework.stereotype.Component
import org.springframework.util.CollectionUtils
import java.util.concurrent.TimeUnit
import javax.annotation.Resource@Component
class RedisUtil {@Resourceprivate lateinit var redisTemplate: RedisTemplate<String, Any>// =============================common============================/*** 指定缓存失效时间* @param key 键* @param time 时间(秒)* @return*/fun expire(key: String, time: Long): Boolean {try {if (time > 0) {redisTemplate.expire(key, time, TimeUnit.SECONDS)}return true} catch (e: Exception) {e.printStackTrace()return false}}/*** 根据key 获取过期时间* @param key 键 不能为null* @return 时间(秒) 返回0代表为永久有效*/fun getExpire(key: String): Long {return redisTemplate.getExpire(key, TimeUnit.SECONDS)}/*** 判断key是否存在* @param key 键* @return true 存在 false不存在*/fun hasKey(key: String): Boolean {try {return redisTemplate.hasKey(key)} catch (e: Exception) {e.printStackTrace()return false}}/*** 删除缓存* @param key 可以传一个值 或多个*/fun del(vararg key: String) {if (key.isNotEmpty()) {if (key.size == 1) {redisTemplate.delete(key[0])} else {redisTemplate.delete(key.toList())}}}// ============================String=============================/*** 普通缓存获取* @param key 键* @return*/operator fun get(key: String?): Any? {return if (key == null) null else redisTemplate.opsForValue().get(key)}/*** 普通缓存放入* @param key 键* @param value 值* @return true成功 false失败*/operator fun set(key: String, value: Any): Boolean {try {redisTemplate.opsForValue().set(key, value)return true} catch (e: Exception) {e.printStackTrace()return false}}/*** 普通缓存放入并设置时间* @param key 键* @param value 值* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期* @return true成功 false 失败*/operator fun set(key: String, value: Any, time: Long): Boolean {try {if (time > 0) {redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS)} else {set(key, value)}return true} catch (e: Exception) {e.printStackTrace()return false}}/*** 递增* @param key 键* @param delta 要增加几(大于0)* @return*/fun incr(key: String, delta: Long): Long {if (delta < 0) {throw RuntimeException("递增因子必须大于0")}return redisTemplate.opsForValue().increment(key, delta)!!}/*** 递减* @param key 键* @param delta 要减少几(小于0)* @return*/fun decr(key: String, delta: Long): Long {if (delta < 0) {throw RuntimeException("递减因子必须大于0")}return redisTemplate.opsForValue().increment(key, -delta)!!}// ================================Map=================================/*** HashGet* @param key 键 不能为null* @param item 项 不能为null* @return*/fun hget(key: String, item: String): Any? {return redisTemplate.opsForHash<Any, Any>().get(key, item)}/*** 获取hashKey对应的所有键值* @param key 键* @return 对应的多个键值*/fun hmget(key: String): Map<Any, Any> {return redisTemplate.opsForHash<Any, Any>().entries(key)}/*** HashSet* @param key 键* @param map 对应多个键值* @return true 成功 false 失败*/fun hmset(key: String, map: Map<String, Any>): Boolean {try {redisTemplate.opsForHash<Any, Any>().putAll(key, map)return true} catch (e: Exception) {e.printStackTrace()return false}}/*** HashSet 并设置时间* @param key 键* @param map 对应多个键值* @param time 时间(秒)* @return true成功 false失败*/fun hmset(key: String, map: Map<String, Any>, time: Long): Boolean {try {redisTemplate.opsForHash<Any, Any>().putAll(key, map)if (time > 0) {expire(key, time)}return true} catch (e: Exception) {e.printStackTrace()return false}}/*** 向一张hash表中放入数据,如果不存在将创建* @param key 键* @param item 项* @param value 值* @return true 成功 false失败*/fun hset(key: String, item: String, value: Any): Boolean {try {redisTemplate.opsForHash<Any, Any>().put(key, item, value)return true} catch (e: Exception) {e.printStackTrace()return false}}/*** 向一张hash表中放入数据,如果不存在将创建* @param key 键* @param item 项* @param value 值* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间* @return true 成功 false失败*/fun hset(key: String, item: String, value: Any, time: Long): Boolean {try {redisTemplate.opsForHash<Any, Any>().put(key, item, value)if (time > 0) {expire(key, time)}return true} catch (e: Exception) {e.printStackTrace()return false}}/*** 删除hash表中的值* @param key 键 不能为null* @param item 项 可以使多个 不能为null*/fun hdel(key: String, vararg item: Any) {redisTemplate.opsForHash<Any, Any>().delete(key, *item)}/*** 判断hash表中是否有该项的值* @param key 键 不能为null* @param item 项 不能为null* @return true 存在 false不存在*/fun hHasKey(key: String, item: String): Boolean {return redisTemplate.opsForHash<Any, Any>().hasKey(key, item)}/*** hash递增 如果不存在,就会创建一个 并把新增后的值返回* @param key 键* @param item 项* @param by 要增加几(大于0)* @return*/fun hincr(key: String, item: String, by: Double): Double {return redisTemplate.opsForHash<Any, Any>().increment(key, item, by)}/*** hash递减* @param key 键* @param item 项* @param by 要减少记(小于0)* @return*/fun hdecr(key: String, item: String, by: Double): Double {return redisTemplate.opsForHash<Any, Any>().increment(key, item, -by)}// ============================set=============================/*** 根据key获取Set中的所有值* @param key 键* @return*/fun sGet(key: String): Set<Any>? {try {return redisTemplate.opsForSet().members(key)} catch (e: Exception) {e.printStackTrace()return null}}/*** 根据value从一个set中查询,是否存在* @param key 键* @param value 值* @return true 存在 false不存在*/fun sHasKey(key: String, value: Any): Boolean {try {return redisTemplate.opsForSet().isMember(key, value)!!} catch (e: Exception) {e.printStackTrace()return false}}/*** 将数据放入set缓存* @param key 键* @param values 值 可以是多个* @return 成功个数*/fun sSet(key: String, vararg values: Any): Long {try {return redisTemplate.opsForSet().add(key, *values)!!} catch (e: Exception) {e.printStackTrace()return 0}}/*** 将set数据放入缓存* @param key 键* @param time 时间(秒)* @param values 值 可以是多个* @return 成功个数*/fun sSetAndTime(key: String, time: Long, vararg values: Any): Long {try {val count = redisTemplate.opsForSet().add(key, *values)if (time > 0)expire(key, time)return count!!} catch (e: Exception) {e.printStackTrace()return 0}}/*** 获取set缓存的长度* @param key 键* @return*/fun sGetSetSize(key: String): Long {try {return redisTemplate.opsForSet().size(key)!!} catch (e: Exception) {e.printStackTrace()return 0}}/*** 移除值为value的* @param key 键* @param values 值 可以是多个* @return 移除的个数*/fun setRemove(key: String, vararg values: Any): Long {try {val count = redisTemplate.opsForSet().remove(key, *values)return count!!} catch (e: Exception) {e.printStackTrace()return 0}}// ===============================list=================================/*** 获取list缓存的内容* @param key 键* @param start 开始* @param end 结束 0 到 -1代表所有值* @return*/fun lGet(key: String, start: Long, end: Long): List<Any>? {try {return redisTemplate.opsForList().range(key, start, end)} catch (e: Exception) {e.printStackTrace()return null}}/*** 获取list缓存的长度* @param key 键* @return*/fun lGetListSize(key: String): Long {try {return redisTemplate.opsForList().size(key)!!} catch (e: Exception) {e.printStackTrace()return 0}}/*** 通过索引 获取list中的值* @param key 键* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推* @return*/fun lGetIndex(key: String, index: Long): Any? {try {return redisTemplate.opsForList().index(key, index)} catch (e: Exception) {e.printStackTrace()return null}}/*** 将list放入缓存* @param key 键* @param value 值* @param time 时间(秒)* @return*/fun lSet(key: String, value: Any): Boolean {try {redisTemplate.opsForList().rightPush(key, value)return true} catch (e: Exception) {e.printStackTrace()return false}}/*** 将list放入缓存* @param key 键* @param value 值* @param time 时间(秒)* @return*/fun lSet(key: String, value: Any, time: Long): Boolean {try {redisTemplate.opsForList().rightPush(key, value)if (time > 0)expire(key, time)return true} catch (e: Exception) {e.printStackTrace()return false}}/*** 将list放入缓存* @param key 键* @param value 值* @param time 时间(秒)* @return*/fun lSet(key: String, value: List<Any>): Boolean {try {redisTemplate.opsForList().rightPushAll(key, *value.toTypedArray())return true} catch (e: Exception) {e.printStackTrace()return false}}/*** 将list放入缓存** @param key 键* @param value 值* @param time 时间(秒)* @return*/fun lSet(key: String, value: List<Any>, time: Long): Boolean {try {redisTemplate.opsForList().rightPushAll(key, *value.toTypedArray())if (time > 0)expire(key, time)return true} catch (e: Exception) {e.printStackTrace()return false}}/*** 根据索引修改list中的某条数据* @param key 键* @param index 索引* @param value 值* @return*/fun lUpdateIndex(key: String, index: Long, value: Any): Boolean {try {redisTemplate.opsForList().set(key, index, value)return true} catch (e: Exception) {e.printStackTrace()return false}}/*** 移除N个值为value* @param key 键* @param count 移除多少个* @param value 值* @return 移除的个数*/fun lRemove(key: String, count: Long, value: Any): Long {try {val remove = redisTemplate.opsForList().remove(key, count, value)return remove!!} catch (e: Exception) {e.printStackTrace()return 0}}
}

在application.properties中增加redis配置(实际上默认是这些参数)

#Redis数据库索引(默认为0)
spring.redis.database=0
#Redis服务器地址
spring.redis.host=127.0.0.1
#Redis服务器连接端口
spring.redis.port=6379
#Redis服务器连接密码(默认为空)
spring.redis.password=

3、单元测试

在src/test/kotlin目录下 com.example.demo包下新建类TestRedisUtil.kt

package com.example.demoimport com.example.demo.util.RedisUtil
import com.fasterxml.jackson.databind.ObjectMapper
import org.junit.Assert
import org.junit.FixMethodOrder
import org.junit.runners.MethodSorters
import org.springframework.boot.test.context.SpringBootTest
import javax.annotation.Resource
import kotlin.test.Test@SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TestRedisUtil {@Resourceprivate lateinit var redisUtil: RedisUtil@Testfun test001_javaBean() {val student = Student(0, "Aa")redisUtil.set("student", student)val json = redisUtil.get("student")var result: Student? = nullif (json is HashMap<*, *>) {//map  转 beanval mapper = ObjectMapper()//result = mapper.readValue(mapper.writeValueAsString(json), Student::class.java)result = mapper.convertValue(json, Student::class.java)Assert.assertTrue(result == student)}}@Testfun test002_List() {val list = listOf("Aa", "Bb", "Cc")redisUtil.set("listBean", list)val json = redisUtil.get("listBean")if (json != null) {val mapper = ObjectMapper()val type = mapper.typeFactory.constructParametricType(ArrayList::class.java, String::class.java)val result: List<String> = mapper.readValue(mapper.writeValueAsString(json), type)println(result)}}@Testfun test003_stringList() {val list = listOf("Aa", "Bb", "Cc")redisUtil.del("stringList")redisUtil.lSet("stringList", list)val result = redisUtil.lGet("stringList", 0, 10)Assert.assertEquals(list, result)}@Testfun test_studentList() {val list = listOf(Student(1, "Aa"), Student(2, "Bb"), Student(3, "Cc"), null)redisUtil.del("studentList")redisUtil.lSet("studentList", list)val result= redisUtil.lGet("studentList", 0, 10)if (result is List<*> && result.isNotEmpty() && result.get(0) is List<*>) {val resultList = result[0] as List<*>val objectMapper = ObjectMapper()val studentList = resultList.map { item -> objectMapper.convertValue(item, Student::class.java) }Assert.assertEquals(list, studentList)}}@Testfun test_map() {redisUtil.del("map")val map = mutableMapOf<String, Int>()map.put("A", 0)map.put("B", 1)redisUtil.hmset("map", map)val result = redisUtil.hmget("map");Assert.assertTrue(result == map)}class Student() {var id: Int? = nullvar name: String? = nullconstructor(id: Int?, name: String?) : this() {this.id = idthis.name = name}override fun hashCode(): Int {var result = id ?: 0result = 31 * result + (name?.hashCode() ?: 0)return result}override fun equals(other: Any?): Boolean {if (this === other) return trueif (javaClass != other?.javaClass) return falseother as Studentif (id != other.id) return falseif (name != other.name) return falsereturn true}override fun toString(): String {return "Student(id=$id, name=$name)"}}
}

启动本地redis,即可测试从redis中存取String、list、对象及map等数据。

转载于:https://www.cnblogs.com/wushengwuxi/p/11372713.html

相关文章:

:before和::before的区别

在一次项目中&#xff0c;有一次要用到::selection伪元素&#xff0c;然后开发同学问我&#xff0c;CSS中一个冒号和两个冒号有神马区别&#xff1f; 这好像真的是个问题&#xff0c;或许很多前端同学对此都有疑惑&#xff0c;查了些资料&#xff0c;证实了下两个符号的区别&am…

python下载大文件mp4_python合并大量ts文件成mp4格式(ps:上限是450,亲测)

原博文 2018-08-22 17:34 − 1 import os 2 #exec_str rcopy /b ts/c9645620628078.tsts/c9645620628079.ts ts/1.ts 3 #os.system(exec_str) 4 f open(index.m3u8, r, encod...08595 相关推荐 2019-12-19 14:27 − ts readonly name "xxx"; updateValueAndValidi…

提高网站页面收录的几个方法 返回列表 发新帖回复

首先是清楚网站总体有多少页面。 可以用xenu扫描出所有的页面。 1.html地图 网页数量不是太多&#xff0c;可以用网站地图来增加收录&#xff0c;分成几个地图页面。 2.随机文章模块 在不影响用户体验的情况下&#xff0c;在栏目中增加随机文章模块&#xff0c;增加链接曝光度&…

JSP+Servlet+JavaBean

JSP相当于在HTML页面中加上Java代码&#xff0c;一般在<body>标签中放入主要代码。 在JSP里用<%...%>把Java代码包含起来的。 Servlet的生命周期&#xff1a; ①被服务器实例化后&#xff0c;容器运行init方法。 ②当请求&#xff08;Request&#xff09;到达时&am…

logistic回归 如何_第七章:利用Python实现Logistic回归分类模型

免责声明&#xff1a;本文是通过网络收集并结合自身学习等途径合法获取&#xff0c;仅作为学习交流使用&#xff0c;其版权归出版社或者原创作者所有&#xff0c;并不对涉及的版权问题负责。若原创作者或者出版社认为侵权&#xff0c;请联系及时联系&#xff0c;我将立即删除文…

多年没有管理的技术博客了,即日起开始管理起技术博客

多年没有管理的技术博客了&#xff0c;即日起开始管理起技术博客&#xff0c;希望朋友们一如既往的支持转载于:https://www.cnblogs.com/flashicp/archive/2012/08/14/2639054.html

GNS3的默认Telnet程序改成secureCRT

编辑-首选项-一般里的“终端命令”改为C:\Users\ldy\AppData\Local\VanDyke Software\SecureCRT\SecureCRT.exe /t /telnet %h %p 前面是SecureCRT程序的目录&#xff0c; /t是指建立一个新标签 &#xff0c; /telnet的意思是走Telnet协议&#xff0c; %h是要telnet到的主机&am…

关于Vue实例的生命周期created和mounted的区别

关于作者 程序开发人员&#xff0c;不拘泥于语言与技术&#xff0c;目前主要从事PHP和前端开发&#xff0c;使用Laravel和VueJs&#xff0c;App端使用Apicloud混合式开发。合适和够用是最完美的追求。 个人网站&#xff1a;http://www.linganmin.cn 最近刚写了一个手机在线播放…

UVa 10112 - Myacm Triangles

UVa第一卷最后一题。 求内部不含点并且面积最大的三角形。 暴力。 代码如下&#xff1a; 1 #include<iostream>2 #include<cstdio>3 #include<cmath>4 #include<cstring>5 6 using namespace std;7 8 typedef struct node9 { 10 char ch; 11 i…

[转]ASP.NET1.0升级ASP.NET2.0问题总结

来自&#xff1a;http://www.enet.com.cn/article/2006/0310/A20060310510518.shtml1&#xff0e;Global.asax文件的处理形式不一样&#xff0c;转化后将出现错误 在vs2003中Global.asax具有代码后置文件&#xff0c;2.0下, 将代码分离文件移到 App_Code 目录下&#xff0c;以便…

python文本编码转换_Python: 转换文本编码

最近在做周报的时候&#xff0c;需要把csv文本中的数据提取出来制作表格后生产图表。 在获取csv文本内容的时候&#xff0c;基本上都是用with open(filename, encoding UTF-8) as f:来打开csv文本&#xff0c;但是实际使用过程中发现有些csv文本并不是utf-8格式&#xff0c;从而…

ipone 网页版的iphone

本文摘自&#xff1a;http://www.cocoachina.com/bbs/m/list.php?fid6#list

import static

import static&#xff08;静态导入&#xff09;是JDK1.5中的新特性&#xff0c;一般我们导入一个类都用 import com.....ClassName;而静态导入是这样&#xff1a;import static com.....ClassName.*;这里多了个static&#xff0c;还有就是类名ClassName后面多了个 .* &#xf…

poj1423

http://acm.pku.edu.cn/JudgeOnline/problem?id1423n!(log10(sqrt(4.0*acos(0.0)*n))n*(log10(n)-log10(exp(1.0)))1);n1 除外 转载于:https://www.cnblogs.com/FCWORLD/archive/2011/03/12/1982355.html

python缩进在程序中长度统一且强制使用_Python习题纠错1

February, 1991 0.9.1 2.Python语言的缩进只要统一即可&#xff0c;不一定是4个空格&#xff08;尽管这是惯例&#xff09;。 Python缩进在程序中长度统一且强制使用. 3.IPO&#xff1a;Input Process Output 4.Python合法命名的首字符不能是数字。 5.Python保留字&#xff1a;…

ASP.NET MVC3 在WebGrid中用CheckBox选中行

分三步走 1.保证你的webgrid包含在form中 using (Html.BeginForm("Assign","Home")) { } 2.在webgrid中加一列checkbox grid.Column(header: "Assign?", format: <text><input class"check-box" id"assi…

Delphi中使用IXMLHTTPRequest如何用POST方式提交带参

http://blog.sina.com.cn/s/blog_51a71c010100gbua.html说明&#xff1a;服务器端为JAVA&#xff0c;编码UTF-8&#xff0c;返回数据编码UTF-8&#xff1b;数据交换格式JSON。procedure TloginForm.loginBtnClick(Sender: TObject);var jo: ISuperObject; //JSON接口 req: IX…

Windows图标:有一些你未必知道的东西

有一天&#xff0c;我的程序在任务栏的应用程序中看起来是这样的很奇怪&#xff0c;我的图标明明不是这样的&#xff0c;在资源管理器的文件夹里面&#xff0c;我的图标能够正常显示&#xff0c;在桌面的任务栏里&#xff0c;也能正常的显示&#xff0c;唯独在任务管理器里显示…

几种函数式编程语言

1、函数式编程语言有&#xff1a;lisp,hashshell,erlang等。 2、在函数中的参数&#xff0c;有一一对应的&#xff0c;也有指定模式的&#xff0c;还有使用能数组。如*argp&#xff08;元组&#xff09;&#xff0c;**argp(字典&#xff09;。 3、在pyphon语言中有一些内置的函…

python逐个读取文件并处理_逐个读取多个文件并用python进行处理

我在python中使用Pybrain&#xff08;神经网络库&#xff09;进行图像处理。我在一个目录中有196个文件&#xff0c;它保存在下面代码中的所有_文件中。我试着打开每个文件并分别对每个文件进行处理&#xff0c;但它将所有文件数据放在一个字符串中&#xff0c;我希望每个文件逐…

HDU 2102 A计划

该题是一道典型的搜索题&#xff0c; #include<stdio.h> #include<stdlib.h> #include<string.h> struct Node {int x, y;int time;int flag; }q[100024]; int d[4][2]{ 0,1,1,0,0,-1,-1,0 }; int N,M; char map[2][13][13]; void getxy( int &X,int &a…

node.js是做什么的?

作者&#xff1a;厂长链接&#xff1a;https://www.zhihu.com/question/33578075/answer/56951771来源&#xff1a;知乎著作权归作者所有。商业转载请联系作者获得授权&#xff0c;非商业转载请注明出处。国外有一篇非常好的Node.js 介绍文章&#xff0c;从原理入手讲解&#x…

K8S - Kubernetes简介

Kubernetes Kubernetes&#xff08;简称K8s&#xff0c;用8代替8个字符“ubernete”&#xff09;是Google开源的一个容器编排引擎&#xff0c;支持自动化部署、大规模可伸缩、应用容器化管理。 Kubernetes 是目前最为广泛且流行的容器编排调度系统&#xff0c;也是现在用来构建…

python中filenotfounderror_Python3 报错 FileNotFoundError: [WinError 2]

Python3 报错 FileNotFoundError: [WinError 2]工具/原料 Python3.7 chromedriver 方法/步骤 1 首先&#xff0c;打开py文件&#xff0c;如图&#xff0c;有如下代码。 import time from selenium import webdriver driver webdriver.Chrome()2 然后运行py文件&#xff0c;run…

Push Notifications

push notification 使用&#xff1a; 参考资源: http://tiny4cocoa.com/thread-1406-1-1.html http://bbs.ldci.com.cn/read.php?tid-19971.html http://www.cocoachina.com/bbs/read.php?tid-3770-keyword-apns.html http://code.google.com/p/apns-python-wrapper/ http://…

[原创]Bash中的$*和$@的区别

2019独角兽企业重金招聘Python工程师标准>>> 在Bash脚本中&#xff0c;$*和$都用于表示执行脚本时所传入的参数。先通过一个例子看看他们的区别: #!/bin/bash # testvar.sh echo "-------------ISF is set to \"-seperator\" ------------" IFS…

文本处理工具之grep和egrep

文本处理工具之grep和egrep grep全称global search regular expression (RE) and print out the line正则表达式&#xff08;一类字符所书写的模式pattern&#xff09; 元字符&#xff1a;不表示字符本身的意义&#xff0c;用于额外功能性的描述基本正则表达式的元字符 字符匹配…

【转】堆栈和托管堆 c#

原文地址&#xff1a;http://blog.csdn.net/baoxuetianxia/archive/2008/11/04/3218913.aspx首先堆栈和堆&#xff08;托管堆&#xff09;都在进程的虚拟内存中。&#xff08;在32位处理器上每个进程的虚拟内存为4GB&#xff09; 堆栈stack 堆栈中存储值类型。 堆栈实际上是向…

python特性和属性_Python之属性、特性和修饰符

原博文 2018-03-17 11:08 − 作为面对对象的核心内容&#xff0c;将从以下一个方面进行总结&#xff1a; 1. property和property 2. __getattribute__()、__getattr__()、__setattr__()、__delattr__() 3. 描述符__get__()、__set__()、__delete__()... 相关推荐 2019-09-28 21…

pytest+allure环境别人电脑运行正常,自己运行不正常几种情况

1. AttributeError&#xff1a;module’ object has no attribute severity_level 之前运行都是正常的&#xff0c;想弄allure报告&#xff0c;就使用pip install allure-pytest 命令安装了&#xff0c;其实该命令的作用是会把你当前版本的pytest卸载掉&#xff0c;然后安装 al…