/** * 设置 * k 键key * v 值value * t 秒 */ function putLS(k, v, t) { try { wx.setStorageSync(k, v) var seconds = parseInt(t) if (seconds > 0) { var newtime = Date.parse( new Date()) newtime = newtime / 1000 + seconds; wx.setStorageSync(k + 'xz' , newtime + "" ) } else { wx.removeStorageSync(k + 'xz' ) } } catch (e) { // console.log(e); } } /** * 获取 * k 键key */ function getLS(k) { try { var deadtime = parseInt(wx.getStorageSync(k + 'xz' )) if (deadtime) { if (parseInt(deadtime) < Date.parse( new Date()) / 1000) { //wx.removeStorageSync(k); remLS(k) console.log( "过期了" ) return false } } var res = wx.getStorageSync(k) if (res){ return res } else { return false } } catch (e) { // console.log(e); } } /** * 删除 */ function remLS(k) { try { wx.removeStorageSync(k); wx.removeStorageSync(k + 'xz' ); } catch (e) { // console.log(e); } } /** * 清除所有key */ function remAllLS() { try { wx.clearStorageSync(); } catch (e) { // console.log(e); } } module.exports = { putLS, getLS, remLS, remAllLS }
|
redis是服务端的 storage是客户端的,说成是类cookie还行
多多交流