-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,221 additions
and
663 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,21 @@ | ||
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common'; | ||
import type { Redis } from 'ioredis'; | ||
import { CacheClosure, CacheStore } from '@niceai/cache'; | ||
import { CacheService as CacheStoreService } from '@niceai/cache/node'; | ||
import { type Redis } from 'ioredis'; | ||
|
||
@Injectable() | ||
export class CacheService implements OnModuleDestroy, OnModuleInit { | ||
protected store: CacheStore; | ||
|
||
protected readonly cachePrefix: string; | ||
|
||
export class CacheService | ||
extends CacheStoreService | ||
implements OnModuleInit, OnModuleDestroy | ||
{ | ||
constructor(redis: Redis, opts: { prefix?: string } = {}) { | ||
this.store = new CacheStore(redis, opts); | ||
super(redis, opts); | ||
} | ||
|
||
async onModuleInit() { | ||
await this.store.connect(); | ||
} | ||
|
||
getPrefix() { | ||
return this.store.getPrefix(); | ||
} | ||
|
||
async set(key: string, value: unknown, seconds?: number) { | ||
return this.store.set(key, value, seconds); | ||
} | ||
|
||
putMany(values: Record<string, unknown>, seconds?: number) { | ||
return this.store.putMany(values, seconds); | ||
} | ||
|
||
async rememberForever<T>(key: string, fn: () => Promise<T>): Promise<T> { | ||
return this.store.rememberForever<T>(key, fn); | ||
} | ||
|
||
async remember<T>( | ||
key: string, | ||
fn?: CacheClosure<T>, | ||
seconds?: number, | ||
): Promise<T | null> { | ||
const now = Date.now(); | ||
const res = await this.store.remember(key, fn, seconds); | ||
console.log(Date.now() - now); | ||
return res; | ||
} | ||
|
||
async increment(key: string, value = 1) { | ||
return this.store.increment(key, value); | ||
} | ||
|
||
async decrement(key: string, value = 1) { | ||
return this.store.decrement(key, value); | ||
} | ||
|
||
async forever(key: string, value: unknown) { | ||
return this.store.forever(key, value); | ||
} | ||
|
||
async forget(key: string): Promise<boolean> { | ||
return this.store.forget(key); | ||
} | ||
|
||
async get<T>(key: string, defaultVal?: T): Promise<T | null> { | ||
return this.store.get<T>(key, defaultVal); | ||
} | ||
|
||
async del(key: string): Promise<boolean> { | ||
return this.store.delete(key); | ||
} | ||
|
||
async deleteMultiple(keys: string[]): Promise<boolean> { | ||
return this.store.deleteMultiple(keys); | ||
} | ||
|
||
async has(key: string): Promise<boolean> { | ||
return this.store.has(key); | ||
} | ||
|
||
async pull<T>(key: string) { | ||
return this.store.pull<T>(key); | ||
} | ||
|
||
async put<T>(key: string, value: T, seconds?: number) { | ||
return this.store.put(key, value, seconds); | ||
} | ||
|
||
async ttl(key: string): Promise<number | null> { | ||
return this.store.ttl(key); | ||
} | ||
|
||
async flush(): Promise<boolean> { | ||
return this.store.flush(); | ||
} | ||
|
||
async getMultiple(keys: string[]): Promise<any> { | ||
return this.store.getMultiple(keys); | ||
} | ||
|
||
async add<T>(key: string, value: T, seconds?: number) { | ||
return this.store.add<T>(key, value, seconds); | ||
await this.cache.connect(); | ||
} | ||
|
||
onModuleDestroy(): void { | ||
this.store.disconnect(); | ||
onModuleDestroy() { | ||
this.cache.disconnect(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const LoginForm = () => { | ||
return <div>LoginForm</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import { Outlet } from '@remix-run/react'; | ||
import { Avatar } from 'antd'; | ||
|
||
export const ROUTE_PATH = '/console' as const; | ||
|
||
export default function AuthLayout() { | ||
return <Outlet />; | ||
return ( | ||
<div> | ||
当前用户:<Avatar className="bg-blue-500">N</Avatar> | ||
<Outlet /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { MetaFunction } from '@vercel/remix'; | ||
import { Button } from 'antd'; | ||
|
||
export const meta: MetaFunction = () => { | ||
return [ | ||
{ title: 'New Remix App' }, | ||
{ name: 'description', content: 'Welcome to Remix!' }, | ||
]; | ||
}; | ||
|
||
export default function Login() { | ||
return ( | ||
<div> | ||
<h1>Console</h1> | ||
<Button>Login</Button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.