redis的配置及使用

来源:http://www.cnblogs.com/zhongwu/archive/2017/07/20/7212174.html
-Advertisement-
Play Games

一、redis配置 1、啟動redis 這裡使用的是windows版本的redis,直接解壓使用就可以了。 註意1: 當運行redis-server時需要註意的是不同的電腦因為配置問題可能無法雙擊啟動。所以需要通過命令提示符的方式進行啟動 這個界面表示redis已經啟動,預設配置 redis.hos ...


一、redis配置

  1、啟動redis

  這裡使用的是windows版本的redis,直接解壓使用就可以了。

   註意1: 當運行redis-server時需要註意的是不同的電腦因為配置問題可能無法雙擊啟動。所以需要通過命令提示符的方式進行啟動

 

  

  這個界面表示redis已經啟動,預設配置 redis.host=localhost   redis.port=6379

   2、applicationContext-redis.xml配置

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:aop="http://www.springframework.org/schema/aop"  
    xsi:schemaLocation="  
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">  

     <context:component-scan base-package="com.zhongwu.redis.dao"/> 
    
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxActive" value="50" />
        <property name="maxIdle" value="8" />
        <property name="maxWait" value="1000" />
        <property name="testOnBorrow" value="true"/>
        <property name="testOnReturn" value="true"/>
        <!-- <property name="testWhileIdle" value="true"/> -->
    </bean>

    <bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool"  scope="singleton">
        <constructor-arg index="0" ref="jedisPoolConfig" />
        <constructor-arg index="1">
            <list>
                <bean class="redis.clients.jedis.JedisShardInfo">
                    <constructor-arg name="host" value="localhost" />
                    <constructor-arg name="port" value="6379" />
                    <constructor-arg name="timeout" value="0" />
                    <constructor-arg name="weight" value="1" />
                </bean>
            </list>
        </constructor-arg>
    </bean>
    
</beans>

  

  引入jar包,這裡需要註意的是redis版本問題,版本更新中有些參數名稱更改,此處根據applicationContext-redis.xml配置中參數選擇2.1.0版本進行配置。

     <!-- redis -->  
         <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.1.0</version>
        </dependency>        

 

  3、redis使用相關介面方法

  

  RedisDataSource.java

package com.zhongwu.redis.dao;

import redis.clients.jedis.ShardedJedis;

public interface RedisDataSource {
        public abstract ShardedJedis getRedisClient();
        public void returnResource(ShardedJedis shardedJedis);
        public void returnResource(ShardedJedis shardedJedis,boolean broken);
}

  RedisClientTemplate.java

package com.zhongwu.redis.dao.impl;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

import com.zhongwu.redis.dao.RedisDataSource;

import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPipeline;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
@Repository("redisClientTemplate")
public class RedisClientTemplate {

        private static final Logger log = LoggerFactory.getLogger(RedisClientTemplate.class);

        @Autowired
        private RedisDataSource     redisDataSource;

        public void disconnect() {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            shardedJedis.disconnect();
        }
        
        /**
         * 通過配置獲取redis連接
         * 
         * return
         * */
        public static RedisClientTemplate getRedis(){
            ApplicationContext ac =  new ClassPathXmlApplicationContext("classpath:/META-INF/spring/applicationContext2.xml");
            RedisClientTemplate redisClient = (RedisClientTemplate)ac.getBean("redisClientTemplate");
            return redisClient;
        }


        /**
         * 設置單個值
         * 
         * @param key
         * @param value
         * @return
         */
        public String set(String key, String value) {
            String result = null;

            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.set(key, value);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        /**
         * 獲取單個值
         * 
         * @param key
         * @return
         */
        public String get(String key) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }

            boolean broken = false;
            try {
                result = shardedJedis.get(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Boolean exists(String key) {
            Boolean result = false;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.exists(key);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String type(String key) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.type(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        /**
         * 在某段時間後實現
         * 
         * @param key
         * @param unixTime
         * @return
         */
        public Long expire(String key, int seconds) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.expire(key, seconds);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        /**
         * 在某個時間點失效
         * 
         * @param key
         * @param unixTime
         * @return
         */
        public Long expireAt(String key, long unixTime) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.expireAt(key, unixTime);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long ttl(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.ttl(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public boolean setbit(String key, long offset, boolean value) {

            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            boolean result = false;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.setbit(key, offset, value);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public boolean getbit(String key, long offset) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            boolean result = false;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;

            try {
                result = shardedJedis.getbit(key, offset);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public long setrange(String key, long offset, String value) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            long result = 0;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.setrange(key, offset, value);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String getrange(String key, long startOffset, long endOffset) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            String result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.getrange(key, startOffset, endOffset);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String getSet(String key, String value) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.getSet(key, value);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long setnx(String key, String value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.setnx(key, value);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String setex(String key, int seconds, String value) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.setex(key, seconds, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long decrBy(String key, long integer) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.decrBy(key, integer);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long decr(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.decr(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long incrBy(String key, long integer) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.incrBy(key, integer);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long incr(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.incr(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long append(String key, String value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.append(key, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String substr(String key, int start, int end) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.substr(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hset(String key, String field, String value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hset(key, field, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String hget(String key, String field) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hget(key, field);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hsetnx(String key, String field, String value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hsetnx(key, field, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String hmset(String key, Map<String, String> hash) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hmset(key, hash);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<String> hmget(String key, String... fields) {
            List<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hmget(key, fields);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hincrBy(String key, String field, long value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hincrBy(key, field, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Boolean hexists(String key, String field) {
            Boolean result = false;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hexists(key, field);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long del(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.del(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hdel(String key, String field) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hdel(key, field);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hlen(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hlen(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<String> hkeys(String key) {
            Set<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hkeys(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<String> hvals(String key) {
            List<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hvals(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Map<String, String> hgetAll(String key) {
            Map<String, String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return
              
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 一,base.css基礎樣式表的意義 我昨天,整理了一下代碼規範。 發現現在這個程度的頁面還原。有必要創建一個規範的base.css庫和framework.css庫 而且也要為日後的工作整理一些常用的基礎css,你們想象一下日後在公司里上班,如果每次都要逐一新增基礎樣式,那麼花費的時間就會滴水長流。 ...
  • 什麼是DOM? HTMLDOM將HTML文檔視作樹結構,被稱為"節點樹" 作用:可通過 JavaScript (以及其他編程語言)對 HTML DOM 進行訪問 ———————————————————————————————————————————— DOM對象方法 具體方法見手冊 getEleme ...
  • 我網上查了很多方法,說是用戶名或者密碼錯誤,但是我通過命令行和Navicat都能直接連接MySQL,但是通過nodejs就是連接不上,命令行中報了標題的那個錯誤,我也問了很多人,也都不是很清楚。 後來我想其他方法都能連接成功,僅僅是nodejs連接不上,是不是nodejs連接還需額外的配置,看了no ...
  • 本文章由尚學堂旗下雲數學院周老師做內容指導,薛同學編輯,如需轉載,請標明出處。 QQ技術交流群:299142667 前言 使用man grep查看grep的幫助文檔,有如下內容: 可以看出,正則表達式由三類,分別是 基本的正則表達式(Basic Regular Expression 又叫 Basic ...
  • 生成AWR報告需要dbms_workload_repository包的許可權。一、以oracle用戶登錄到資料庫伺服器二、進入SQLPLUS三、執行腳本@?/rdbms/admin/awrrpt.sql四、設定生成報告的格式說明:不用輸入,預設即可,直接按Enter五、設定報告時間段的天數說明:只導當... ...
  • 因本人較懶,有些圖片缺失和東西寫的比較簡單,請多包涵 編碼規範: 命名的規範(入鄉隨俗) 編碼習慣: 團隊合作: 團隊配置管理軟體: (TFS SVN) 第一章 更改身份驗證模式:伺服器 屬性 安全性 Master: 記錄所有系統信息 Model: 模板 Msdb: 自動備份 Tempdb: 臨時資 ...
  • 昨晚添加完索引之後, 查詢整表的時候拋出Lock wait timeout exceeded; try restarting transaction, 嚇死小白的我, 為什麼條件查詢可以, 整表查不了, 老大說是不是我添加錯了..., 後來找到解決辦法, 原來是死鎖了查看資料庫的隔離級別select... ...
  • 關於時間序列的計算是一個很(也)常(很)用(大)的topic,而且應用範圍很廣,譬如計算同比,環比,根據時間序列預測某個值。必不可少的就是在模型裡面有一個日期的維度。 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...