Files
core/cache/mapsync/map_int.go
yanweidong 25386cf0e1 ```
refactor(print): 将 print 包重命名为 printer 并更新所有引用

将项目中的 print 包统一重命名为 printer,以避免与标准库或第三方库产生命名冲突。同时,
更新了所有相关模块对该包的引用,确保功能一致性和代码可维护性。

涉及文件包括:
- conf/new.go
- infra/service.go
- service/register.go
- service/service.go
- with/databases.go
- with/etcd.go
- with/memory.go
- with/redis.go

此外,删除了以下已废弃或未使用的代码文件:
- cmd/cmd.go
- data/map_float.go
- data/map_string.go
- oplog/new.go
- oplog/types.go
- print/print.go
- utils/ext.go
```
2025-09-27 00:20:36 +08:00

65 lines
768 B
Go

package mapsync
import (
"sync"
)
var (
// sync map
MapInt *mapInt
)
// lock
type mapInt struct {
sync.RWMutex
Data map[string]int
}
func NewMapInt() *mapInt {
return &mapInt{
Data: make(map[string]int),
}
}
func (c *mapInt) Set(key string, val int) {
c.Lock()
defer c.Unlock()
c.Data[key] = val
}
func (c *mapInt) Get(key string) int {
c.RLock()
defer c.RUnlock()
vals, ok := c.Data[key]
if !ok {
return 0
}
return vals
}
func (c *mapInt) Del(key string) {
c.Lock()
defer c.Unlock()
delete(c.Data, key)
}
func (c *mapInt) All() map[string]int {
c.RLock()
defer c.RUnlock()
return c.Data
}
func (c *mapInt) Keys() (keys []string) {
c.RLock()
defer c.RUnlock()
for k, _ := range c.Data {
keys = append(keys, k)
}
return
}