pom

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.elasticsearch.client</groupId>
  4. <artifactId>transport</artifactId>
  5. <version>6.0.0</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.apache.logging.log4j</groupId>
  9. <artifactId>log4j-core</artifactId>
  10. <version>2.9.1</version>
  11. </dependency>
  12. <dependency>
  13. <groupId>junit</groupId>
  14. <artifactId>junit</artifactId>
  15. <version>4.12</version>
  16. </dependency>
  17.  
  18. <dependency>
  19. <groupId>com.google.code.gson</groupId>
  20. <artifactId>gson</artifactId>
  21. <version>2.8.2</version>
  22. </dependency>
  23. </dependencies>

创建索引

  1. package com.zy.esapi;
  2.  
  3. import com.google.gson.Gson;
  4. import org.elasticsearch.action.bulk.BulkRequestBuilder;
  5. import org.elasticsearch.action.bulk.BulkResponse;
  6. import org.elasticsearch.action.index.IndexResponse;
  7. import org.elasticsearch.client.transport.TransportClient;
  8. import org.elasticsearch.common.settings.Settings;
  9. import org.elasticsearch.common.transport.TransportAddress;
  10. import org.elasticsearch.common.xcontent.XContentFactory;
  11. import org.elasticsearch.common.xcontent.XContentType;
  12. import org.elasticsearch.transport.client.PreBuiltTransportClient;
  13. import org.junit.After;
  14. import org.junit.Before;
  15. import org.junit.Test;
  16.  
  17. import java.io.IOException;
  18. import java.net.InetAddress;
  19. import java.net.UnknownHostException;
  20. import java.util.HashMap;
  21.  
  22. /**
  23. * create by zy
  24. * TODO:创建索引
  25. */
  26. public class CreateIndexTest {
  27.  
  28. private TransportClient client;
  29.  
  30. private IndexResponse indexResponse;
  31.  
  32. /**
  33. * 创建client
  34. *
  35. * @throws UnknownHostException
  36. */
  37. @Before
  38. public void initClient() throws UnknownHostException {
  39. client = new PreBuiltTransportClient(Settings.builder().put("cluster.name", "myes").build())
  40. .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.44.41"), 9300))
  41. .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.44.42"), 9300))
  42. .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.44.43"), 9300));
  43. }
  44.  
  45. /**
  46. * 常用的 map格式
  47. *
  48. * @throws Exception
  49. */
  50. @Test
  51. public void index1() throws Exception {
  52. HashMap<String, String> jsonMap = new HashMap<String, String>();
  53. jsonMap.put("id", "1");
  54. jsonMap.put("name", "zhangsan");
  55. jsonMap.put("sex", "1");
  56. jsonMap.put("age", "18");
  57. jsonMap.put("address", "beijing");
  58.  
  59. //index type id
  60. indexResponse = client.prepareIndex("user", "baseinfo", "1")
  61. .setSource(jsonMap)
  62. .get();
  63. }
  64.  
  65. /**
  66. * 自己拼装json
  67. *
  68. * @throws Exception
  69. */
  70. @Test
  71. public void index2() throws Exception {
  72. String json = "{" +
  73. "\"id\":\"2\"," +
  74. "\"name\":\"kimchy\"," +
  75. "\"sex\":\"1\"," +
  76. "\"age\":\"22\"," +
  77. "\"address\":\"shanghai\"" +
  78. "}";
  79. indexResponse = client.prepareIndex("user", "baseinfo", "2")
  80. .setSource(json, XContentType.JSON)
  81. .get();
  82.  
  83. }
  84.  
  85. /**
  86. * XcontentBuilder
  87. *
  88. * @throws IOException
  89. */
  90. @Test
  91. public void index3() throws IOException {
  92. indexResponse = client.prepareIndex("user", "baseinfo", "3")
  93. .setSource(new XContentFactory().jsonBuilder()
  94. .startObject()
  95. .field("id", "3")
  96. .field("name", "lisi")
  97. .field("age", "18")
  98. .field("sex", "0")
  99. .field("address", "beijing")
  100. .endObject())
  101. .get();
  102.  
  103. }
  104.  
  105. /**
  106. * 常用的 对象json格式
  107. */
  108. @Test
  109. public void index4() {
  110. Gson gson = new Gson();
  111. UserBaseInfo user = new UserBaseInfo("6", "xueyou", "13", "1", "xianggang");
  112. String json = gson.toJson(user);
  113.  
  114. indexResponse = client.prepareIndex("user", "baseinfo", user.getId())
  115. .setSource(json, XContentType.JSON)
  116. .get();
  117.  
  118. }
  119.  
  120. /**
  121. * 批量创建
  122. * 批量操作,可以提高创建索引的速度,主要减少网络请求。
  123. * 如果正常情况,创建一个文档就会发送一次网络请求,其实就是发起一次http请求。
  124. * bulkIndex就可以将多个文档合并在一起之后,发送一次请求。
  125. *
  126. * @throws IOException
  127. */
  128. @Test
  129. public void index5() throws IOException {
  130. BulkRequestBuilder bulk = client.prepareBulk();
  131. bulk.add(client.prepareIndex("user", "baseinfo", "4")
  132. .setSource(new XContentFactory().jsonBuilder()
  133. .startObject()
  134. .field("id", "4")
  135. .field("name", "wangwu")
  136. .field("age", "18")
  137. .field("sex", "0")
  138. .field("address", "hangzhou")
  139. .endObject()));
  140. bulk.add(client.prepareIndex("user", "baseinfo", "5")
  141. .setSource(new XContentFactory().jsonBuilder()
  142. .startObject()
  143. .field("id", "5")
  144. .field("name", "zhaoliu")
  145. .field("age", "18")
  146. .field("sex", "0")
  147. .field("address", "shenzhen")
  148. .endObject()));
  149. BulkResponse bulkResponse = bulk.get();
  150. System.out.println(bulkResponse);
  151. }
  152.  
  153. /**
  154. * 打印返回信息
  155. */
  156. @After
  157. public void printResultAndCloseClient() {
  158. System.out.println("index:" + indexResponse.getIndex());
  159. System.out.println("type:" + indexResponse.getType());
  160. System.out.println("id:" + indexResponse.getId());
  161. System.out.println("version:" + indexResponse.getVersion());
  162. System.out.println("status:" + indexResponse.getResult());
  163. client.close();
  164. }
  165. }

删除索引

  1. package com.zy.esapi;
  2.  
  3. import org.elasticsearch.action.ActionListener;
  4. import org.elasticsearch.action.delete.DeleteResponse;
  5. import org.elasticsearch.client.transport.TransportClient;
  6. import org.elasticsearch.common.settings.Settings;
  7. import org.elasticsearch.common.transport.TransportAddress;
  8. import org.elasticsearch.index.query.QueryBuilders;
  9. import org.elasticsearch.index.reindex.BulkByScrollResponse;
  10. import org.elasticsearch.index.reindex.DeleteByQueryAction;
  11. import org.elasticsearch.rest.RestStatus;
  12. import org.elasticsearch.transport.client.PreBuiltTransportClient;
  13. import org.junit.After;
  14. import org.junit.Before;
  15. import org.junit.Test;
  16.  
  17. import java.net.InetAddress;
  18. import java.net.UnknownHostException;
  19.  
  20. /**
  21. * create by zy
  22. * TODO:
  23. */
  24. public class DeleteIndexTest {
  25. private TransportClient client;
  26. private DeleteResponse response;
  27.  
  28. @Before
  29. public void init() throws UnknownHostException {
  30. Settings settings = Settings.builder().put("cluster.name", "myes").build();
  31. client = new PreBuiltTransportClient(settings)
  32. .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.44.41"), 9300))
  33. .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.44.42"), 9300))
  34. .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.44.43"), 9300));
  35. }
  36.  
  37. @After
  38. public void close() throws UnknownHostException {
  39. if (response != null) {
  40. String index = response.getIndex();
  41. String type = response.getType();
  42. String id = response.getId();
  43. long version = response.getVersion();
  44. System.out.println("index " + index + " type" + type + "" + id + "" + version + "" + version);
  45. RestStatus status = response.status();
  46. System.out.println("status:" + status.getStatus());
  47. client.close();
  48. }
  49. }
  50.  
  51. /**
  52. * 根据文档进行删除
  53. *
  54. * @throws UnknownHostException
  55. */
  56. @Test
  57. public void delete1() throws UnknownHostException {
  58. response = client.prepareDelete("user", "baseinfo", "1").get();
  59. }
  60.  
  61. @Test
  62. /**
  63. * 根据根据查询结果删除数据,并触发相关事件
  64. */
  65. public void delete2() throws UnknownHostException {
  66. DeleteByQueryAction.INSTANCE.newRequestBuilder(client)
  67. .filter(QueryBuilders.matchQuery("sex", "1"))
  68. .source("user")
  69. .execute(new ActionListener<BulkByScrollResponse>() {
  70. public void onResponse(BulkByScrollResponse response) {
  71. long deleted = response.getDeleted();
  72. System.out.println("---------------" + deleted);
  73. }
  74.  
  75. public void onFailure(Exception e) {
  76. System.out.println("------------错误了");
  77. }
  78. });
  79. }
  80. }

查询

  1. package com.zy.esapi;
  2.  
  3. import com.google.gson.Gson;
  4. import org.elasticsearch.action.get.GetResponse;
  5. import org.elasticsearch.action.get.MultiGetItemResponse;
  6. import org.elasticsearch.action.get.MultiGetResponse;
  7. import org.elasticsearch.action.search.SearchRequestBuilder;
  8. import org.elasticsearch.action.search.SearchResponse;
  9. import org.elasticsearch.client.transport.TransportClient;
  10. import org.elasticsearch.common.settings.Settings;
  11. import org.elasticsearch.common.text.Text;
  12. import org.elasticsearch.common.transport.TransportAddress;
  13. import org.elasticsearch.common.xcontent.XContentType;
  14. import org.elasticsearch.index.query.MatchAllQueryBuilder;
  15. import org.elasticsearch.index.query.QueryBuilders;
  16. import org.elasticsearch.search.SearchHit;
  17. import org.elasticsearch.search.SearchHits;
  18. import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
  19. import org.elasticsearch.search.sort.SortOrder;
  20. import org.elasticsearch.transport.client.PreBuiltTransportClient;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23.  
  24. import java.net.InetAddress;
  25. import java.net.UnknownHostException;
  26. import java.util.ArrayList;
  27.  
  28. /**
  29. * create by zy
  30. * TODO:查询
  31. */
  32. public class QueryTest {
  33.  
  34. private TransportClient client;
  35.  
  36. /**
  37. * 创建client
  38. *
  39. * @throws UnknownHostException
  40. */
  41. @Before
  42. public void initClient() throws UnknownHostException {
  43. client = new PreBuiltTransportClient(Settings.builder().put("cluster.name", "myes").build())
  44. .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.44.41"), 9300))
  45. .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.44.42"), 9300))
  46. .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.44.43"), 9300));
  47. }
  48.  
  49. /**
  50. * 根据id查询一个
  51. */
  52. @Test
  53. public void query1() {
  54. GetResponse response = client.prepareGet("user", "baseinfo", "1").get();
  55. String index = response.getIndex();
  56. String type = response.getType();
  57. String id = response.getId();
  58.  
  59. System.out.println(response.getSourceAsString());
  60. System.out.println(index);
  61. System.out.println(type);
  62. System.out.println(id);
  63.  
  64. client.close();
  65. }
  66.  
  67. /**
  68. * 查询多个id
  69. */
  70. @Test
  71. public void query2() {
  72. MultiGetResponse responses = client.prepareMultiGet()
  73. .add("user", "baseinfo", "1")
  74. .add("user", "baseinfo", "2")
  75. .add("user", "baseinfo", "3")
  76. .add("user", "baseinfo", "4")
  77. .get();
  78. ArrayList<UserBaseInfo> users = new ArrayList<UserBaseInfo>();
  79. for (MultiGetItemResponse response : responses) {
  80. String json = response.getResponse().getSourceAsString();
  81. Gson gson = new Gson();
  82. UserBaseInfo user = gson.fromJson(json, UserBaseInfo.class);
  83. users.add(user);
  84. }
  85. System.out.println(users);
  86.  
  87. client.close();
  88. }
  89.  
  90. @Test
  91. public void query3() {
  92. SearchResponse response = client.prepareSearch("user").setTypes("baseinfo")
  93. //所有的查询方式都可以直接new出来,
  94. .setQuery(new MatchAllQueryBuilder())
  95. //5.x以后如果用字段排序,需要在setting中预先设置fielddata=true
  96. .addSort("id", SortOrder.DESC)
  97. //浅分页
  98. .setFrom(1).setSize(3)
  99. .get();
  100. SearchHits hits = response.getHits();
  101. for (SearchHit hit : hits) {
  102. System.out.println(hit.getSourceAsString());
  103. //docid没有值,旧版本有值
  104. //int docId = hit.docId();
  105. //System.out.println(docId);
  106. }
  107. }
  108.  
  109. /**
  110. *
  111. DELETE user
  112. PUT /user/?pretty
  113. PUT user/_mapping/baseinfo
  114. {
  115. "properties":{
  116. "id":{
  117. "type":"text",
  118. "fielddata":true
  119. },
  120. "name":{
  121. "type":"text"
  122. },
  123. "age":{
  124. "type":"text"
  125. },
  126. "sex":{
  127. "type":"text"
  128. },
  129. "address":{
  130. "type":"text"
  131. }
  132. }
  133. }
  134. */
  135.  
  136. //--------------------------------search 高亮--------------------------------
  137.  
  138. //建立索引 需要用ik分词器
  139. /**
  140. * DELETE allarticle
  141. * PUT /allarticle?pretty
  142. * {
  143. * "settings" : {
  144. * "analysis" : {
  145. * "analyzer" : {
  146. * "ik" : {
  147. * "tokenizer" : "ik_max_word"
  148. * }
  149. * }
  150. * }
  151. * },
  152. * "mappings" : {
  153. * "article" : {
  154. * "dynamic" : true,
  155. * "properties" : {
  156. * "id" : {
  157. * "type" : "text",
  158. * "fielddata": true
  159. * },
  160. * "title" : {
  161. * "type" : "text",
  162. * "analyzer" : "ik_max_word"
  163. * },
  164. * "content" : {
  165. * "type" : "text",
  166. * "analyzer" : "ik_max_word"
  167. * }
  168. * }
  169. * }
  170. * }
  171. * }
  172. */
  173.  
  174. /**
  175. * 数据准备
  176. *
  177. * @throws UnknownHostException
  178. */
  179. @Test
  180. public void initPageData() throws UnknownHostException {
  181.  
  182. for (int i = 1; i <= 100; i++) {
  183. // 描述json 数据
  184. Article article = new Article();
  185. article.setId(i + "");
  186. article.setTitle(i + "搜索工作其实很快乐");
  187. article.setContent(i
  188. + "我们希望我们的搜索解决方案要快,我们希望有一个零配置和一个完全免费的搜索模式,我们希望能够简单地使用JSON通过HTTP的索引数据,我们希望我们的搜索服务器始终可用,我们希望能够一台开始并扩展到数百,我们要实时搜索,我们要简单的多租户,我们希望建立一个云的解决方案。Elasticsearch旨在解决所有这些问题和更多的问题。");
  189.  
  190. Gson gson = new Gson();
  191. String json = gson.toJson(article);
  192.  
  193. // 建立文档
  194. client.prepareIndex("allarticle", "article", article.getId())
  195. .setSource(json, XContentType.JSON)
  196. .get();
  197. }
  198.  
  199. //释放资源
  200. client.close();
  201. }
  202.  
  203. @Test
  204. //高亮查询
  205. public void test11() throws Exception {
  206. // 搜索数据
  207. SearchRequestBuilder searchRequestBuilder = client
  208. .prepareSearch("allarticle").setTypes("article")
  209. //.setQuery(QueryBuilders.termQuery("title", "搜索"));
  210. .setQuery(QueryBuilders.multiMatchQuery("搜索", "title", "content"));//这种多字段查询效率高些
  211.  
  212. //设置高亮数据
  213. HighlightBuilder hiBuilder = new HighlightBuilder();
  214. //设置格式
  215. hiBuilder.preTags("<font style='color:red'>");
  216. hiBuilder.postTags("</font>");
  217. //设置字段
  218. hiBuilder.field("title");
  219. hiBuilder.field("content");
  220. searchRequestBuilder.highlighter(hiBuilder);
  221.  
  222. //获得查询结果数据
  223. SearchResponse searchResponse = searchRequestBuilder.get();
  224.  
  225. //获取查询结果集
  226. SearchHits searchHits = searchResponse.getHits();
  227. System.out.println("共搜到:" + searchHits.getTotalHits() + "条结果!");
  228. //遍历结果
  229. for (SearchHit hit : searchHits) {
  230. System.out.println("start************************************");
  231. System.out.println("String方式打印文档搜索内容:");
  232. System.out.println(hit.getSourceAsString());
  233. System.out.println("-----------------------------------------");
  234. System.out.println("Map方式打印高亮内容");
  235. System.out.println(hit.getHighlightFields());
  236.  
  237. System.out.println("-----------------------------------------");
  238. System.out.println("遍历高亮集合,打印高亮片段:");
  239. Text[] titles = hit.getHighlightFields().get("title").getFragments();
  240. for (Text str : titles) {
  241. System.out.println(str);
  242. }
  243.  
  244. Text[] contents = hit.getHighlightFields().get("content").getFragments();
  245. for (Text str : contents) {
  246. System.out.println(str);
  247. }
  248. System.out.println("end**************************************");
  249. }
  250.  
  251. //释放资源
  252. client.close();
  253. }
  254.  
  255. }

其他类

  1. package com.zy.esapi;
  2.  
  3. /**
  4. * create by zy
  5. * TODO:
  6. */
  7. public class Article {
  8. private String id;
  9. private String title;
  10. private String content;
  11.  
  12. public Article() {
  13. }
  14.  
  15. public Article(String id, String title, String content) {
  16. this.id = id;
  17. this.title = title;
  18. this.content = content;
  19. }
  20.  
  21. public String getId() {
  22. return id;
  23. }
  24.  
  25. public void setId(String id) {
  26. this.id = id;
  27. }
  28.  
  29. public String getTitle() {
  30. return title;
  31. }
  32.  
  33. public void setTitle(String title) {
  34. this.title = title;
  35. }
  36.  
  37. public String getContent() {
  38. return content;
  39. }
  40.  
  41. public void setContent(String content) {
  42. this.content = content;
  43. }
  44.  
  45. @Override
  46. public String toString() {
  47. return "Article{" +
  48. "id='" + id + '\'' +
  49. ", title='" + title + '\'' +
  50. ", content='" + content + '\'' +
  51. '}';
  52. }
  53. }
  54.  
  55. package com.zy.esapi;
  56.  
  57. import java.io.Serializable;
  58.  
  59. /**
  60. * create by zy
  61. * TODO:
  62. */
  63. public class UserBaseInfo implements Serializable {
  64. private String id;
  65. private String name;
  66. private String age;
  67. private String sex;
  68. private String address;
  69.  
  70. public UserBaseInfo() {
  71. }
  72.  
  73. public UserBaseInfo(String id, String name, String age, String sex, String address) {
  74. this.id = id;
  75. this.name = name;
  76. this.age = age;
  77. this.sex = sex;
  78. this.address = address;
  79. }
  80.  
  81. public String getId() {
  82. return id;
  83. }
  84.  
  85. public void setId(String id) {
  86. this.id = id;
  87. }
  88.  
  89. public String getName() {
  90. return name;
  91. }
  92.  
  93. public void setName(String name) {
  94. this.name = name;
  95. }
  96.  
  97. public String getAge() {
  98. return age;
  99. }
  100.  
  101. public void setAge(String age) {
  102. this.age = age;
  103. }
  104.  
  105. public String getSex() {
  106. return sex;
  107. }
  108.  
  109. public void setSex(String sex) {
  110. this.sex = sex;
  111. }
  112.  
  113. public String getAddress() {
  114. return address;
  115. }
  116.  
  117. public void setAddress(String address) {
  118. this.address = address;
  119. }
  120.  
  121. @Override
  122. public String toString() {
  123. return "UserBaseInfo{" +
  124. "id='" + id + '\'' +
  125. ", name='" + name + '\'' +
  126. ", age='" + age + '\'' +
  127. ", sex='" + sex + '\'' +
  128. ", address='" + address + '\'' +
  129. '}';
  130. }
  131. }

ElasticSearch的java api的更多相关文章

  1. Elasticsearch中JAVA API的使用

    1.Elasticsearch中Java API的简介 Elasticsearch 的Java API 提供了非常便捷的方法来索引和查询数据等. 通过添加jar包,不需要编写HTTP层的代码就可以开始 ...

  2. ElasticSearch实战系列三: ElasticSearch的JAVA API使用教程

    前言 在上一篇中介绍了ElasticSearch实战系列二: ElasticSearch的DSL语句使用教程---图文详解,本篇文章就来讲解下 ElasticSearch 6.x官方Java API的 ...

  3. 使用Java操作Elasticsearch(Elasticsearch的java api使用)

    1.Elasticsearch是基于Lucene开发的一个分布式全文检索框架,向Elasticsearch中存储和从Elasticsearch中查询,格式是json. 索引index,相当于数据库中的 ...

  4. ElasticSearch AggregationBuilders java api常用聚会查询

    以球员信息为例,player索引的player type包含5个字段,姓名,年龄,薪水,球队,场上位置.index的mapping为: "mappings": { "pl ...

  5. elasticsearch常用JAVA API 实例

    1.引入dependency <dependency> <groupId>org.springframework.data</groupId> <artifa ...

  6. ElasticSearch排序Java api简单Demo

    代码: String time1 = ConstValue.GetCurrentDate(); SortBuilder sortBuilder = SortBuilders.fieldSort(&qu ...

  7. Elasticsearch的Java API做类似SQL的group by聚合。

    https://www.cnblogs.com/kangoroo/p/8033955.html

  8. Elasticsearch JAVA api搞定groupBy聚合

    本文给出如何使用Elasticsearch的Java API做类似SQL的group by聚合.为了简单起见,只给出一级groupby即group by field1(而不涉及到多级,例如group ...

  9. Elasticsearch JAVA api轻松搞定groupBy聚合

    本文给出如何使用Elasticsearch的Java API做类似SQL的group by聚合. 为了简单起见,只给出一级groupby即group by field1(而不涉及到多级,例如group ...

随机推荐

  1. vue-router教程一(安装篇)

    Installation安装 #直接下载/cdn https://unpkg.com/vue-router/dist/vue-router.js Unpkg.com提供基于NPM的CDN链接.上述链接 ...

  2. elixir 集成ejabberd

    备注: 我开发测试的环境时centos 1. 预备环境 1. openssl yum install -y  openssl-devel 2. xml yum install -y expat-dev ...

  3. jest js 测试框架-简单方便人性化

    1. 安装 yarn global add jest-cli or npm install -g jest-cli 备注:可以安装为依赖不用全局安装 2. 项目代码 a. 项目初始化 yarn ini ...

  4. Automating CSS Regression Testing

    The following is a guest post by Garris Shipon . We've touched on the four types of CSS testing here ...

  5. Oracle数据库安装图文操作步骤1

    Oracle数据库安装图文操作步骤 一.Oracle 下载 注意Oracle分成两个文件,下载完后,将两个文件解压到同一目录下即可. 路径名称中,最好不要出现中文,也不要出现空格等不规则字符.   官 ...

  6. sql的一些事件处理

    select getdate() select Convert(varchar(10),getdate(),120) yyyy-mm-ddselect Convert(varchar(20),getd ...

  7. Ubuntu sudo: add-apt-repository: command not found

    安装缺少的指令即可 $ sudo apt-get install software-properties-common python-software-properties

  8. Hibernate学习6—Hibernate 映射类型

    第一节:基本类型映射 com.cy.model.Book.java: package com.cy.model; import java.sql.Blob; import java.util.Date ...

  9. centos7系统安装python3,pip3,django

    首先去python官网下载python3的源码包,网址:https://www.python.org/ 或者直接wget下载 wget https://www.python.org/ftp/pytho ...

  10. Django缓存,信号,序列化

    缓存 1.缓存的简介 在动态网站中,用户所有的请求,服务器都会去数据库中进行相应的增,删,查,改,渲染模板,执行业务逻辑,最后生成用户看到的页面. 当一个网站的用户访问量很大的时候,每一次的的后台操作 ...