我正在尝试刷新Redis缓存数据库并在响应中返回状态。但是在清除缓存之前,它会返回响应。
在下面的代码中,由于不等待flushRedisDB,console.log将始终显示未定义的内容。
我的节点版本是v8.1.0
myfile.js
async function flushRedisapi(request, response)
{
try {
var value = await redisModules.flushRedisDB();
console.log("the value is : " + value);
if(value)
response.status(200).send({status : 'Redis Cache Cleared'});
else
response.status(400).send({status : "Redis Cache could not be flushed"});
} catch (error) {
response.status(400).send({status : "Redis Cache could not be flushed"});
}
}
Run Code Online (Sandbox Code Playgroud)
redismodule.js
var redisClient; // Global (Avoids Duplicate Connections)
module.exports =
{
openRedisConnection : function()
{
if (redisClient == null)
{
redisClient = require("redis").createClient(6379, 'localhost');
redisClient.selected_db = 1;
} …Run Code Online (Sandbox Code Playgroud) 我正在使用此控件进行分页链接并能够得到以下结果。

我可以更改非选定/活动项目的背景颜色,但如何更改选定项目的样式,如上图 8 所示,它是紫色的,所以我需要它是不同的颜色。
下面是react中的JS代码
const styles = theme => ({
paginationItemStyle: {
marginLeft: "5px",
color: "white"
},
paginationLinkStyle: {
backgroundColor: "#b90000",
borderRadius: "5px",
"&:hover": {
backgroundColor: "#772e2e",
},
"&:active": {
backgroundColor: "#772e2e",
}
}
});
<Pagination>
<PaginationItem>
<PaginationLink previous />
</PaginationItem>
{someNumbersList.map((i, key) => (
<PaginationItem key={key} className={classes.paginationItemStyle} active={currentPage==(i+1)}>
<PaginationLink className={classes.paginationLinkStyle}>
{i+1}
</PaginationLink>
</PaginationItem>
))}
<PaginationItem>
<PaginationLink next />
</PaginationItem>
</Pagination>
Run Code Online (Sandbox Code Playgroud) Uncaught ReferenceError: regeneratorRuntime is not defined尝试使用超级代理进行 api 调用时出现此错误。
目前我正在使用 react 17、webpack 5 以及 css 模块和所有最新的包。
包.json
{
"dependencies": {
"date-fns": "^2.16.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"superagent": "^6.1.0"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@babel/preset-react": "^7.12.10",
"@dr.pogodin/babel-plugin-react-css-modules": "^6.0.10",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.2",
"css-loader": "^5.0.1",
"eslint": "^7.16.0",
"html-webpack-plugin": "^5.0.0-beta.1",
"mini-css-extract-plugin": "^1.3.3",
"node-sass": "^5.0.0",
"postcss": "^8.2.1",
"postcss-scss": "^3.0.4",
"sass": "^1.30.0",
"sass-loader": "^10.1.0",
"style-loader": "^2.0.0",
"url-loader": "^4.1.1",
"webpack": "^5.11.0",
"webpack-cli": "^4.3.0",
"webpack-dev-server": "^3.11.0"
} …Run Code Online (Sandbox Code Playgroud) 我有大约100个Rss链接需要每3分钟获取一次.
所以我使用异步模块来做到这一点.但在处理完所有Rss链接之前,它就会完成并退出.以下是代码.
feedRecords是一个包含RSS url和id 的数组;
var items = [];
var parseRss = require("parse-rss");
var async = require('async');
async.forEach(feedRecords, function taskIterator(feedItem, callback)
{
parseRss(feedItem.url, function (err, articles)
{
if (err)
{
callback(err);
}
else
{
console.log("Feed Id : " + feedItem.feed_id + ", Length : " + articles.length);
items.push({ data : articles, feed_id : feedItem.feed_id });
callback(null);
}
});
},
function ()
{
if (items.length > 0)
{
console.log("Total : " + items.length);
}
else
console.log("No data found"); …Run Code Online (Sandbox Code Playgroud) 我有下面的CSS代码,该代码给出+符号,但与设计基本不匹配,因此需要变薄。参见摘要和鳕鱼
.plus {
position:relative;
border: 1px dotted white;
width: 3px;
height: 3px;
background-color: black;
box-sizing: border-box;
transform: scale(11);
}Run Code Online (Sandbox Code Playgroud)
<div class="plus"></div>Run Code Online (Sandbox Code Playgroud)
Any other styling is also fine for me but should look like the snapshot.
如何在Laravel DB select函数中从MySql获取结果后获取特定的列值
下面是我的PHP代码.
$list = DB::select('SELECT DISTINCT a.pincode FROM table_name nvs
JOIN areas a on nvs.area_id = a.id
where nvs.city_id = ?;', [$area_id]);
Run Code Online (Sandbox Code Playgroud)
以下是上述查询的结果.
[
{
"pincode": "560005"
},
{
"pincode": "560006"
}
]
Run Code Online (Sandbox Code Playgroud)
我只需要pincode值而不是键值对.所以我尝试使用以下代码.
return array_column($list->toArray(), 'pincode');
Run Code Online (Sandbox Code Playgroud)
它在数组上调用成员函数toArray().
如何在不使用foreach循环的情况下仅获取值.
回答
我使用下面的代码
$pincode_list = DB::table('table_name as nvs')
->join('areas as a', 'nvs.area_id', '=', 'a.id')
->select('a.pincode')
->where('nvs.city_id', '=', $area_id)
->distinct('a.pincode')->pluck('pincode')->toArray();
Run Code Online (Sandbox Code Playgroud)
结果是:
[
"560067",
"560035"
]
Run Code Online (Sandbox Code Playgroud) 如何在React.js的 Material UI中更改DialogTitle和DialogContent中的字体/文本颜色
更改Dialog的背景颜色可以,但是尝试更改Dialog和DialogContent的字体颜色不起作用。
<Dialog
open={this.state.open}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
PaperProps={{
style: {
backgroundColor: "#fff",
},
}}
>
<DialogTitle id="alert-dialog-title">
"Use Google's location service?"
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
Hello
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color="primary">
OK
</Button>
</DialogActions>
</Dialog>
Run Code Online (Sandbox Code Playgroud) reactjs ×3
asynchronous ×2
javascript ×2
laravel ×2
node.js ×2
async-await ×1
babel-loader ×1
babeljs ×1
css ×1
css-shapes ×1
feed ×1
html ×1
laravel-5 ×1
laravel-5.3 ×1
material-ui ×1
php ×1
phpcs ×1
reactstrap ×1
rss ×1
webpack ×1