redis 的key 過期通知設定

Redis - Wikipedia

redis有expire機制,且同時有redis keyspace notification。不過預設默認的通知是關閉的~需要透過redis.conf或config set啟用。

config set notify-keyspace-events KEA

接著在c# 使用StackExchange.Redis

然後訂閱__keyevent@0__:expired 這個頻道就可以了

var redisConnection = ConnectionMultiplexer.Connect(“localhost”);
var db = redisConnection.GetDatabase();

var subscriber = redisConnection.GetSubscriber();
// 訂閱過期事件通知頻道
subscriber.Subscribe(“__keyevent@0__:expired”, (channel, key1) =>
{
// 在這裡進行過期事件的處理邏輯
// key 是過期的 Redis 鍵名
Console.WriteLine($”Key {key1} has expired.”);
});

Console.WriteLine(“Press any key to exit.”);
Console.ReadKey();

// 斷開與 Redis 的連線
redisConnection.Close();

chatGPT與line官方帳號結合 = line ai 小助理

OpenAI設計的ChatGPT問世後,很快的ai的使用人數破億。且chatgpt讓ai整個流行了起來~ 想說台灣最流行的通訊工具line,有沒有機會跟chatgpt串到一起,於是很快的用php以及.net core都串了一次。簡單明瞭~很易懂

分享關鍵的php,有問題歡迎line: superlevin 林壽山


$api_key = 'xxxxxxxxxx';
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.openai.com/v1/completions',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key
],
CURLOPT_POSTFIELDS => json_encode([
'prompt' => $ask_question,
'model' => 'text-davinci-003',
'max_tokens' => 1000,
'temperature' => 0.3
])
]);
$response = curl_exec($curl);

$json = json_decode($response, true);

 

 

C#資料結構與演算法

使用對的演算法與資料結構,在程式效能上有很大的幫助。常用的資料結構有array、stack、 queue、 linked list、 tree、 graph、 heap、 hash。在c#上常見的是使用array 、arraylist、 list、 dictonary 以及queue可以滿足絕大部份的場景。

以下介紹github上二個高階資料結構與演算法的項目。

一、C Sharp Algorithms

一開始是學習資料結構,在不斷更新以及維護後,可以用在正式環境。

https://github.com/aalhour/C-Sharp-Algorithms

二、Advanced Algorithms

https://github.com/justcoding121/advanced-algorithms

.Net 7 開發增進效能的小撇步

預計在2022年11月發布的.net7目前進入RC2的版本。來談談.net7 做了那些效能上的改進~

LINQ部份

1針對max/min最佳化

2針對Average/sum

3新增order/orderDescending 取代orderby/orderbydescending

4 System.IO的改善 WriteAllText改ReadAllText

5 針對Jsonserializer NoCachedOptions提昇

6Guid的 GuidEquals提昇

7ParseBigInt提昇

8ParseBool

9 Stopwatch中的getprocessbyname與getcurrentprocessname

10 在stopwatch加上getelapsedtime取得時間戳

.net Multi-platform APP UI(MAUI)教學準備中

2022年11月微軟準備在.net 新版本中發表 Multi-platform APP UI(MAUI)新的跨平台開發架構,透過c#以及XAML就可以開發出同時在windows、android以及ios與mac os上的程式(對了!目前還沒有支援到linux)!

簡單的說它算是Xamarin.Forms後續的版本,近期開始著手撰寫以及錄製MAUI的教學以及學習文件。

.net MAUI 新增程式
預設.net MAUI 範例教學程式

第四方金流高鉅初體驗

最近跟第四方金流高鉅做串接服務,主要是以金流以及訂閱式服務開發為需求。

串接上倒是沒有很多特別要注意的地方,我想大部份的模式都與其他金流服務綠界~

等搞定後再分享程式碼出來

相關資源:

高鉅第四方金流模擬串接服務

https://pay.usecase.cc/simulator/payment/orders

高鉅第四方金流交易設計概要

https://doc.usecase.cc/Payment/Store/?php#paypage