Redis實(shí)戰(zhàn)之商城購物車功能的實(shí)現(xiàn)代碼
目標(biāo)
利用Redis實(shí)現(xiàn)商城購物車功能。
功能
根據(jù)用戶編號查詢購物車列表,且各個(gè)商品需要跟在對應(yīng)的店鋪下;統(tǒng)計(jì)購物車中的商品總數(shù);新增或刪減購物車商品;增加或減少購物車中的商品數(shù)量。

分析
Hash數(shù)據(jù)類型:值為多組映射,相當(dāng)于JAVA中的Map。適合存儲(chǔ)對象數(shù)據(jù)類型。因?yàn)橛脩鬒D作為唯一的身份標(biāo)識(shí),所以可以把模塊名稱+用戶ID作為Redis的鍵;商品ID作為商品的唯一標(biāo)識(shí),可以把店鋪編號+商品ID作為Hash元素的鍵,商品數(shù)量為元素的值。
代碼實(shí)現(xiàn)
控制層
package com.shoppingcart.controller;
import com.shoppingcart.service.ShoppingCartServer;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* redis實(shí)現(xiàn)購物車功能
*/
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {
@Resource
private ShoppingCartServer shoppingCartServer;
/**
* http://localhost:8099/shoppingCart/addCommodity?userId=001&shopId=1234560&commodityId=001&commodityNum=336
* 添加商品
* @return
* @param: userId 用戶ID
* @param: [{shopId:商鋪id,commodityId:商品id,commodityNum:商品數(shù)量},{shopId:商鋪id,commodityId:商品id,commodityNum:商品數(shù)量}]
* 測試數(shù)據(jù):
[
{
"shopId": 123,
"commodityId": 145350,
"commodityNum": 155.88
},
{
"shopId": 123,
"commodityId": 6754434,
"commodityNum": 945.09
},
{
"shopId": 123,
"commodityId": 7452,
"commodityNum": 2445.09
},
{
"shopId": 3210,
"commodityId": 98766,
"commodityNum": 2345.09
},
{
"shopId": 456,
"commodityId": 2435640,
"commodityNum": 11945.09
}
]
*/
@GetMapping("/addCommodity")
public Map<String, Object> addCommodity(
@RequestParam(value = "userId", required = true) String userId,
@RequestBody List<Map<String, Object>> list
) {
Map<String, Object> map = shoppingCartServer.addCommodity(userId, list);
return map;
}
/**
* 購物車列表
* http://localhost:8099/shoppingCart/shoppingCartList?userId=001
*
* @param userId
* @return 返回{店鋪ID:商品ID=商品數(shù)量}的map。
*/
@GetMapping("/shoppingCartList")
public Map<Object, Object> shoppingCartList(
@RequestParam(value = "userId", required = true) String userId,
@RequestParam(value = "pageNo", defaultValue = "0") Long pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Long pageSize
) {
Map<Object, Object> map = shoppingCartServer.shoppingCartList(userId, pageNo, pageSize);
return map;
}
/**
* http://localhost:8099/shoppingCart/updateNum?userId=001&shopId=01&comId=123456&num=342
* 修改商品數(shù)量。
*
* @param userId 用戶id
* @param commodityId 商品id
* @param commodityNum 商品數(shù)量
* @return
*/
@GetMapping("/updateNum")
public Map<String, Object> updateNum(
@RequestParam(value = "userId", required = true) String userId,
@RequestParam(value = "shopId", required = true) Long shopId,
@RequestParam(value = "commodityId", required = true) Long commodityId,
@RequestParam(value = "commodityNum", required = true) Double commodityNum
) {
return shoppingCartServer.updateNum(userId, shopId, commodityId, commodityNum);
}
/**
* http://localhost:8099/shoppingCart/delCom?userId=001&shopId=01&comId=123457
* 刪除購物車中的商品
* @return
* @param: userId 用戶id
* @param: [{shopId:商鋪id,commodityId:商品id},{shopId:商鋪id,commodityId:商品id}]
*/
@PostMapping("/delCommodity")
public Map<String, Object> delCommodity(
@RequestParam(value = "userId", required = true) String userId,
@RequestBody List<Map<String, Object>> list
) {
return shoppingCartServer.delCommodity(userId, list);
}
}
業(yè)務(wù)層
package com.shoppingcart.service;
import java.util.List;
import java.util.Map;
public interface ShoppingCartServer {
//購物車列表
public Map<Object, Object> shoppingCartList(String userId,Long pageNo,Long pageSize);
Map<String,Object> updateNum(String userId,Long shopId, Long commodityId, Double commodityNum);
Map<String, Object> delCommodity(String userId, List<Map<String , Object>> list);
Map<String, Object> addCommodity(String userId, List<Map<String , Object>> list);
}
package com.shoppingcart.service.impl;
import com.shoppingcart.service.ShoppingCartServer;
import com.shoppingcart.utils.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ShoppingCartServerImpl implements ShoppingCartServer {
@Autowired
private RedisService redisService;
//購物車鍵名前綴
public static final String SHOPPING_CART = "shoppingCart:";
//購物車的元素鍵名前綴
public static final String SHOP_ID = "shopId";
//添加商品
@Override
public Map<String, Object> addCommodity(String userId, List<Map<String, Object>> list) {
//記錄:list中有哪些商品在購物車中已經(jīng)存在。
List<String> existCommoditys = new ArrayList<>();
//todo 購物車key
String key = SHOPPING_CART + userId;
for (int i = 0; i < list.size(); i++) {
String commodityKey = SHOP_ID + list.get(i).get("shopId") + ":" + list.get(i).get("commodityId");
//todo 添加商品
boolean boo = redisService.hsetnx(key, commodityKey, Double.parseDouble(list.get(i).get("commodityNum") + ""));
if (!boo) {
existCommoditys.add(commodityKey);
}
}
Map<String, Object> m = new HashMap<String, Object>() {
{
put("existCommoditys", existCommoditys);
put("existCommoditysMsg", "這些商品在購物車中已經(jīng)存在,重復(fù)數(shù)量:"+existCommoditys.size()+"。");
}
};
Map<String, Object> map = new HashMap<String, Object>();
map.put("data", m);
map.put("code", 0);
return map;
}
//購物車列表
@Override
public Map<Object, Object> shoppingCartList(String userId, Long pageNo, Long pageSize) {
//返回{店鋪ID:商品ID=商品數(shù)量}的map。
Map<Object, Object> map = redisService.hmget(SHOPPING_CART + userId);
return map;
}
//修改商品數(shù)量
@Override
public Map<String, Object> updateNum(String userId, Long shopId, Long commodityId, Double commodityNum) {
Map<String, Object> map = new HashMap<String, Object>();
//todo 購物車key
String key = SHOPPING_CART + userId;
//todo 商品key
String commodityKey = SHOP_ID + shopId + ":" + commodityId;
//修改購物車的數(shù)量
boolean boo = redisService.hset(key, commodityKey, commodityNum);
Map<String, Object> m = new HashMap<String, Object>() {
{
put("key", key);
put("commodityKey", commodityKey);
put("commodityNum", commodityNum);
}
};
map.put("data", m);
map.put("msg", boo == true ? "修改購物車商品數(shù)量成功。" : "修改購物車商品數(shù)量失敗。");
map.put("code", boo == true ? 0 : 1);
return map;
}
//刪除商品
@Override
public Map<String, Object> delCommodity(String userId, List<Map<String, Object>> list) {
Map<String, Object> map = new HashMap<String, Object>();
String[] commodityIds = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
//todo 商品key
commodityIds[i] = SHOP_ID + list.get(i).get("shopId") + ":" + list.get(i).get("commodityId");
}
//todo 購物車key
String key = SHOPPING_CART + userId;
//刪除商品的數(shù)量
Long num = redisService.hdel(key, commodityIds);
map.put("msg", "刪除購物車的商品數(shù)量:" + num);
map.put("code", 0);
return map;
}
}
工具類
package com.shoppingcart.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtils {
// 日期轉(zhuǎn)字符串,返回指定的格式
public static String dateToString(Date date, String dateFormat) {
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
return sdf.format(date);
}
}
package com.shoppingcart.utils;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.data.redis.core.DefaultTypedTuple;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.w3c.dom.ranges.Range;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Service
public class RedisService {
@Autowired
private RedisTemplate<String, Object> redisTemplate;
// =============================common============================
/**
* 指定緩存失效時(shí)間
*
* @param key 鍵
* @param time 時(shí)間(秒)
* @return
*/
public boolean expire(String key, long time) {
try {
if (time > 0) {
redisTemplate.expire(key, time, TimeUnit.SECONDS);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 根據(jù)key 獲取過期時(shí)間
*
* @param key 鍵 不能為null
* @return 時(shí)間(秒) 返回0代表為永久有效
*/
public long getExpire(String key) {
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
}
/**
* 判斷key是否存在
*
* @param key 鍵
* @return true 存在 false不存在
*/
public boolean hasKey(String key) {
try {
return redisTemplate.hasKey(key);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 刪除緩存
*
* @param key 可以傳一個(gè)值 或多個(gè)
*/
@SuppressWarnings("unchecked")
public void del(String... key) {
if (key != null && key.length > 0) {
if (key.length == 1) {
redisTemplate.delete(key[0]);
} else {
List<String> list = new ArrayList<>(Arrays.asList(key));
redisTemplate.delete(list);
}
}
}
/**
* 刪除緩存
*
* @param keys 可以傳一個(gè)值 或多個(gè)
*/
@SuppressWarnings("unchecked")
public void del(Collection keys) {
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(keys)) {
redisTemplate.delete(keys);
}
}
// ============================String=============================
/**
* 普通緩存獲取
*
* @param key 鍵
* @return 值
*/
public Object get(String key) {
return key == null ? null : redisTemplate.opsForValue().get(key);
}
/**
* 普通緩存放入
*
* @param key 鍵
* @param value 值
* @return true成功 false失敗
*/
public boolean set(String key, Object value) {
try {
redisTemplate.opsForValue().set(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 普通緩存放入并設(shè)置時(shí)間
*
* @param key 鍵
* @param value 值
* @param time 時(shí)間(秒) time要大于0 如果time小于等于0 將設(shè)置無限期
* @return true成功 false 失敗
*/
public boolean set(String key, Object value, long time) {
try {
if (time > 0) {
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
} else {
set(key, value);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 遞增
*
* @param key 鍵
* @param delta 要增加幾(大于0)
* @return
*/
public long incr(String key, long delta) {
if (delta < 0) {
throw new RuntimeException("遞增因子必須大于0");
}
return redisTemplate.opsForValue().increment(key, delta);
}
/**
* 遞減
*
* @param key 鍵
* @param delta 要減少幾(小于0)
* @return
*/
public long decr(String key, long delta) {
if (delta < 0) {
throw new RuntimeException("遞減因子必須大于0");
}
return redisTemplate.opsForValue().increment(key, -delta);
}
// ================================Hash=================================
/**
* HashGet
*
* @param key 鍵 不能為null
* @param item 項(xiàng) 不能為null
* @return 值
*/
public Object hget(String key, String item) {
return redisTemplate.opsForHash().get(key, item);
}
/**
* 獲取hashKey對應(yīng)的所有鍵值
*
* @param key 鍵
* @return 對應(yīng)的多個(gè)鍵值
*/
public Map<Object, Object> hmget(String key) {
Map<Object, Object> entries = redisTemplate.opsForHash().entries(key);
return entries;
}
/**
* HashSet
*
* @param key 鍵
* @param map 對應(yīng)多個(gè)鍵值
* @return true 成功 false 失敗
*/
public boolean hmset(String key, Map<String, Object> map) {
try {
redisTemplate.opsForHash().putAll(key, map);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* HashSet 并設(shè)置時(shí)間
*
* @param key 鍵
* @param map 對應(yīng)多個(gè)鍵值
* @param time 時(shí)間(秒)
* @return true成功 false失敗
*/
public boolean hmset(String key, Map<String, Object> map, long time) {
try {
redisTemplate.opsForHash().putAll(key, map);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 向一張hash表中放入數(shù)據(jù),如果存在就覆蓋原來的值。
*
* @param key 鍵
* @param item 項(xiàng)
* @param value 值
* @return true 成功 false失敗
*/
public boolean hset(String key, String item, Object value) {
try {
redisTemplate.opsForHash().put(key, item, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 向一張hash表中放入數(shù)據(jù),如果存在就覆蓋原來的值。
*
* @param key 鍵
* @param item 項(xiàng)
* @param value 值
* @param time 時(shí)間(秒) 注意:如果已存在的hash表有時(shí)間,這里將會(huì)替換原有的時(shí)間
* @return true 成功 false失敗
*/
public boolean hset(String key, String item, Object value, long time) {
try {
redisTemplate.opsForHash().put(key, item, value);
if (time > 0) {
expire(key, time);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 刪除hash表中的值
*
* @param key 鍵 不能為null
* @param item 項(xiàng) 可以使多個(gè) 不能為null
* 返回被刪除的數(shù)量
*/
public Long hdel(String key, Object... item) {
return redisTemplate.opsForHash().delete(key, item);
}
/**
* 刪除hash表中的值
*
* @param key 鍵 不能為null
* @param items 項(xiàng) 可以使多個(gè) 不能為null
*/
public void hdel(String key, Collection items) {
redisTemplate.opsForHash().delete(key, items.toArray());
}
/**
* 判斷hash表中是否有該項(xiàng)的值
*
* @param key 鍵 不能為null
* @param item 項(xiàng) 不能為null
* @return true 存在 false不存在
*/
public boolean hHasKey(String key, String item) {
return redisTemplate.opsForHash().hasKey(key, item);
}
/**
* hash數(shù)據(jù)類型:給元素一個(gè)增量 如果不存在,就會(huì)創(chuàng)建一個(gè) 并把新增后的值返回
*
* @param key 鍵
* @param item 項(xiàng)
* @param delta 要增加幾(大于0)
* @return
*/
public double hincr(String key, String item, double delta) {
return redisTemplate.opsForHash().increment(key, item, delta);
}
// ============================set=============================
/**
* 根據(jù)key獲取Set中的所有值
*
* @param key 鍵
* @return
*/
public Set<Object> sGet(String key) {
try {
return redisTemplate.opsForSet().members(key);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 根據(jù)value從一個(gè)set中查詢,是否存在
*
* @param key 鍵
* @param value 值
* @return true 存在 false不存在
*/
public boolean sHasKey(String key, Object value) {
try {
return redisTemplate.opsForSet().isMember(key, value);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 將數(shù)據(jù)放入set緩存
*
* @param key 鍵
* @param values 值 可以是多個(gè)
* @return 成功個(gè)數(shù)
*/
public long sSet(String key, Object... values) {
try {
return redisTemplate.opsForSet().add(key, values);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/**
* 將數(shù)據(jù)放入set緩存
*
* @param key 鍵
* @param values 值 可以是多個(gè)
* @return 成功個(gè)數(shù)
*/
public long sSet(String key, Collection values) {
try {
return redisTemplate.opsForSet().add(key, values.toArray());
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/**
* 將set數(shù)據(jù)放入緩存
*
* @param key 鍵
* @param time 時(shí)間(秒)
* @param values 值 可以是多個(gè)
* @return 成功個(gè)數(shù)
*/
public long sSetAndTime(String key, long time, Object... values) {
try {
Long count = redisTemplate.opsForSet().add(key, values);
if (time > 0)
expire(key, time);
return count;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/**
* 獲取set緩存的長度
*
* @param key 鍵
* @return
*/
public long sGetSetSize(String key) {
try {
return redisTemplate.opsForSet().size(key);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/**
* 移除值為value的
*
* @param key 鍵
* @param values 值 可以是多個(gè)
* @return 移除的個(gè)數(shù)
*/
public long setRemove(String key, Object... values) {
try {
Long count = redisTemplate.opsForSet().remove(key, values);
return count;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
// ===============================list=================================
/**
* 獲取list緩存的內(nèi)容
*
* @param key 鍵
* @param start 開始
* @param end 結(jié)束 0 到 -1代表所有值
* @return
*/
public List<Object> lGet(String key, long start, long end) {
try {
return redisTemplate.opsForList().range(key, start, end);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 獲取list緩存的長度
*
* @param key 鍵
* @return
*/
public long lGetListSize(String key) {
try {
return redisTemplate.opsForList().size(key);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
/**
* 通過索引 獲取list中的值
*
* @param key 鍵
* @param index 索引 index>=0時(shí), 0 表頭,1 第二個(gè)元素,依次類推;index<0時(shí),-1,表尾,-2倒數(shù)第二個(gè)元素,依次類推
* @return
*/
public Object lGetIndex(String key, long index) {
try {
return redisTemplate.opsForList().index(key, index);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 將list放入緩存
*
* @param key 鍵
* @param value 值
* @return
*/
public boolean lSet(String key, Object value) {
try {
redisTemplate.opsForList().rightPush(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 將list放入緩存
*
* @param key 鍵
* @param value 值
* @param time 時(shí)間(秒)
* @return
*/
public boolean lSet(String key, Object value, long time) {
try {
redisTemplate.opsForList().rightPush(key, value);
if (time > 0)
expire(key, time);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 將list放入緩存
*
* @param key 鍵
* @param value 值
* @return
*/
public boolean lSet(String key, List<Object> value) {
try {
redisTemplate.opsForList().rightPushAll(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 將list放入緩存
*
* @param key 鍵
* @param value 值
* @param time 時(shí)間(秒)
* @return
*/
public boolean lSet(String key, List<Object> value, long time) {
try {
redisTemplate.opsForList().rightPushAll(key, value);
if (time > 0)
expire(key, time);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 根據(jù)索引修改list中的某條數(shù)據(jù)
*
* @param key 鍵
* @param index 索引
* @param value 值
* @return
*/
public boolean lUpdateIndex(String key, long index, Object value) {
try {
redisTemplate.opsForList().set(key, index, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 移除N個(gè)值為value
*
* @param key 鍵
* @param count 移除多少個(gè)
* @param value 值
* @return 移除的個(gè)數(shù)
*/
public long lRemove(String key, long count, Object value) {
try {
Long remove = redisTemplate.opsForList().remove(key, count, value);
return remove;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
// ===============================Zset=================================
/**
* 給key鍵的value增加value分?jǐn)?shù),沒有則會(huì)創(chuàng)建。
*
* @param key 鍵
* @param value 值
* @param score 分?jǐn)?shù)
*/
public Double incrementScore(String key, String value, double score) {
//Boolean add = redisTemplate.boundZSetOps(key).add(value, score);
Double add = redisTemplate.boundZSetOps(key).incrementScore(value, score);
return add;
}
/**
* 獲得指定Zset元素的分?jǐn)?shù)
*
* @param key
* @param value
* @return
*/
public Double score(String key, String value) {
Double score = redisTemplate.boundZSetOps(key).score(value);
return score;
}
/**
* 升序查詢key集合內(nèi)[endTop,startTop]如果是負(fù)數(shù)表示倒數(shù)
* endTop=-1,startTop=0表示獲取所有數(shù)據(jù)。
*
* @param key
* @param startPage
* @param endPage
*/
public Set<ZSetOperations.TypedTuple<Object>> rangeWithScores(String key, int startPage, int endPage) {
Set<ZSetOperations.TypedTuple<Object>> set = redisTemplate.boundZSetOps(key).rangeWithScores(startPage, endPage);
return set;
}
/**
* 降序查詢key集合內(nèi)[endTop,startTop],如果是負(fù)數(shù)表示倒數(shù)
* endTop=-1,startTop=0表示獲取所有數(shù)據(jù)。
*
* @param key
* @param startPage
* @param endPage
*/
public Set<ZSetOperations.TypedTuple<Object>> reverseRangeWithScores(String key, int startPage, int endPage) {
Set<ZSetOperations.TypedTuple<Object>> set = redisTemplate.boundZSetOps(key).reverseRangeWithScores(startPage, endPage);
return set;
}
/**
* 批量新增數(shù)據(jù)
*
* @param key
* @param set
* @return
*/
public Long zsetAdd(String key, Set set) {
Long add = redisTemplate.boundZSetOps(key).add(set);
return add;
}
/**
* 刪除指定鍵的指定下標(biāo)范圍數(shù)據(jù)
*
* @param key
* @param startPage
* @param endPage
*/
public Long zsetRemoveRange(String key, int startPage, int endPage) {
Long l = redisTemplate.boundZSetOps(key).removeRange(startPage, endPage);
return l;
}
/**
* 刪除指定鍵的指定值
*
* @param key
* @param value
*/
public Long zsetRemove(String key, String value) {
Long remove = redisTemplate.boundZSetOps(key).remove(value);
return remove;
}
}
到此這篇關(guān)于Redis實(shí)戰(zhàn)之商城購物車功能的實(shí)現(xiàn)代碼的文章就介紹到這了,更多相關(guān)Redis商城購物車內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
將音頻文件轉(zhuǎn)二進(jìn)制分包存儲(chǔ)到Redis的實(shí)現(xiàn)方法(奇淫技巧操作)
這篇文章主要介紹了將音頻文件轉(zhuǎn)二進(jìn)制分包存儲(chǔ)到Redis的實(shí)現(xiàn)方法(奇淫技巧操作),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07
Redis的數(shù)據(jù)存儲(chǔ)及String類型的實(shí)現(xiàn)
這篇文章主要介紹了Redis的數(shù)據(jù)存儲(chǔ)及String類型的實(shí)現(xiàn),redis作為k-v數(shù)據(jù)存儲(chǔ),因查找和操作的時(shí)間復(fù)雜度都是O(1)和豐富的數(shù)據(jù)類型及數(shù)據(jù)結(jié)構(gòu)的優(yōu)化,了解了這些數(shù)據(jù)類型和結(jié)構(gòu)更有利于我們平時(shí)對于redis的使用,需要的朋友可以參考下2022-10-10
一起raid數(shù)據(jù)恢復(fù)及回遷成功的案例
這篇文章主要介紹了一起raid數(shù)據(jù)恢復(fù)及回遷成功的案例,需要的朋友可以參考下2017-04-04
Redisson延時(shí)隊(duì)列RedissonDelayed的具體使用
定時(shí)調(diào)度基本是每個(gè)項(xiàng)目都會(huì)遇到的業(yè)務(wù)場景,一般地,都會(huì)通過任務(wù)調(diào)度工具執(zhí)行定時(shí)任務(wù)完成,但是會(huì)有一定的缺點(diǎn),本文主要介紹了Redisson延時(shí)隊(duì)列RedissonDelayed的具體使用,感興趣的可以了解一下2024-02-02
Redis做數(shù)據(jù)持久化的解決方案及底層原理
Redis有兩種方式來實(shí)現(xiàn)數(shù)據(jù)的持久化,分別是RDB(Redis Database)和AOF(Append Only File),今天通過本文給大家聊一聊Redis做數(shù)據(jù)持久化的解決方案及底層原理,感興趣的朋友一起看看吧2021-07-07
redis啟動(dòng)報(bào)錯(cuò)Can‘t?open?the?log?file:?No?such?file?or?d
這篇文章主要介紹了redis啟動(dòng)報(bào)錯(cuò)Can‘t?open?the?log?file:?No?such?file?or?directory問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11

